forked from angulartics/angulartics2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplunk.ts
42 lines (35 loc) · 945 Bytes
/
splunk.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
import { Injectable } from '@angular/core';
import { Angulartics2 } from 'angulartics2';
declare var sp: any;
@Injectable()
export class Angulartics2Splunk {
constructor(private angulartics2: Angulartics2) {
if (typeof (sp) === 'undefined') {
console.warn('Splunk not found');
}
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) {
try {
sp.pageview(path);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
eventTrack(action: string, properties: any) {
try {
sp.track(action, properties);
} catch (e) {
if (!(e instanceof ReferenceError)) {
throw e;
}
}
}
}