import { Injectable } from '@angular/core' ; import { Angulartics2 } from '../../angulartics2-core' ; declare const fbq ; const facebookEventList = [ 'ViewContent' , 'Search' , 'AddToCart' , 'AddToWishlist' , 'InitiateCheckout' , 'AddPaymentInfo' , 'Purchase' , 'Lead' , 'CompleteRegistration' , ] ; @ Injectable ( { providedIn : 'root' } ) export class Angulartics2Facebook { constructor ( private angulartics2 ) { } startTracking ( ) { this . angulartics2 . eventTrack . pipe ( this . angulartics2 . filterDeveloperMode ( ) ) . subscribe ( x => this . eventTrack ( x . action , x . properties ) ) ; } param action eventTrack ( action , properties = { } ) { if ( typeof fbq === 'undefined' ) { return ; } if ( facebookEventList . indexOf ( action ) === - 1 ) { return fbq ( 'trackCustom' , action , properties ) ; } return fbq ( 'track' , action , properties ) ; } }