forked from angulartics/angulartics2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkissmetrics.ts
46 lines (37 loc) · 1.13 KB
/
kissmetrics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Injectable } from '@angular/core';
import { Angulartics2 } from 'angulartics2';
declare var _kmq: any;
@Injectable({ providedIn: 'root' })
export class Angulartics2Kissmetrics {
constructor(
private angulartics2: Angulartics2
) {
if (typeof (_kmq) === 'undefined') {
_kmq = [];
}
this.angulartics2.setUsername
.subscribe((x: string) => this.setUsername(x));
this.angulartics2.setUserProperties
.subscribe((x) => this.setUserProperties(x));
}
startTracking(): void {
this.angulartics2.pageTrack
.pipe(this.angulartics2.filterDeveloperMode())
.subscribe((x) => this.pageTrack(x.path));
this.angulartics2.eventTrack
.pipe(this.angulartics2.filterDeveloperMode())
.subscribe((x) => this.eventTrack(x.action, x.properties));
}
pageTrack(path: string) {
_kmq.push(['record', 'Pageview', { Page: path }]);
}
eventTrack(action: string, properties: any) {
_kmq.push(['record', action, properties]);
}
setUsername(userId: string) {
_kmq.push(['identify', userId]);
}
setUserProperties(properties: any) {
_kmq.push(['set', properties]);
}
}