forked from angulartics/angulartics2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacebook.ts
43 lines (37 loc) · 1.02 KB
/
facebook.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
import { Injectable } from '@angular/core';
import { Angulartics2 } from 'angulartics2';
declare const fbq: facebook.Pixel.Event;
const facebookEventList = [
'ViewContent',
'Search',
'AddToCart',
'AddToWishlist',
'InitiateCheckout',
'AddPaymentInfo',
'Purchase',
'Lead',
'CompleteRegistration',
];
@Injectable({ providedIn: 'root' })
export class Angulartics2Facebook {
constructor(private angulartics2: Angulartics2) { }
startTracking(): void {
this.angulartics2.eventTrack
.pipe(this.angulartics2.filterDeveloperMode())
.subscribe(x => this.eventTrack(x.action, x.properties));
}
/**
* Send interactions to the Pixel, i.e. for event tracking in Pixel
*
* @param action action associated with the event
*/
eventTrack(action: string, properties: any = {}) {
if (typeof fbq === 'undefined') {
return;
}
if (facebookEventList.indexOf(action) === -1) {
return fbq('trackCustom', action, properties);
}
return fbq('track', action, properties);
}
}