-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: analytics to help get insights into user interactions
- Loading branch information
1 parent
e5e93b7
commit 263f113
Showing
9 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AnalyticsService } from './analytics.service'; | ||
|
||
describe('AnalyticsService', () => { | ||
let service: AnalyticsService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(AnalyticsService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { WindowRef } from "./window-ref.service"; | ||
|
||
@Injectable({ | ||
providedIn: "root", | ||
}) | ||
export class AnalyticsService { | ||
private readonly gtag: Function; | ||
|
||
constructor(private readonly window: WindowRef) { | ||
// @ts-ignore | ||
this.gtag = this.window.nativeWindow?.gtag; | ||
} | ||
|
||
sendEvent(name: string, params: unknown = {}) { | ||
this.gtag("event", name, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from "@angular/core/testing"; | ||
|
||
import { Logger } from "./logger.service"; | ||
|
||
describe("Logger", () => { | ||
let service: Logger; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(Logger); | ||
}); | ||
|
||
it("should be created", () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { AnalyticsService } from "./analytics.service"; | ||
|
||
@Injectable({ | ||
providedIn: "root", | ||
}) | ||
export class Logger { | ||
constructor(private readonly analytics: AnalyticsService) {} | ||
|
||
log(...messages: any[]): any { | ||
console.dir(...messages); | ||
} | ||
|
||
error(...messages: any[]) { | ||
this.analytics.sendEvent("error", { | ||
message: messages.join(" "), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { TestBed } from "@angular/core/testing"; | ||
import { WindowRef } from "./window-ref.service"; | ||
|
||
describe("WindowRef", () => { | ||
let service: WindowRef; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(WindowRef); | ||
}); | ||
|
||
it("should be created", () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Inject, Injectable, PLATFORM_ID } from "@angular/core"; | ||
import { isPlatformBrowser } from "@angular/common"; | ||
|
||
@Injectable({ | ||
providedIn: "root", | ||
}) | ||
export class WindowRef { | ||
constructor(@Inject(PLATFORM_ID) private readonly platformId: Object) {} | ||
|
||
get nativeWindow(): (Window & typeof globalThis) | null { | ||
return isPlatformBrowser(this.platformId) ? window : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters