import { Injectable } from '@angular/core' ; import { Angulartics2 } from '../../angulartics2-core' ; @ Injectable ( { providedIn : 'root' } ) export class Angulartics2IBMDigitalAnalytics { constructor ( private angulartics2 ) { if ( typeof window [ 'cmCreatePageviewTag' ] !== 'function' ) { console . warn ( 'Angulartics 2 IBM Digital Analytics Plugin: eluminate.js is not loaded' ) ; } } startTracking ( ) { 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 ) ) ; } param path link pageTrack ( path ) { const cmCreatePageviewTag = window [ 'cmCreatePageviewTag' ] ; cmCreatePageviewTag ( path , null , null , null ) ; } param action param properties eventTrack ( action , properties = { } ) { const cmDisplayShops = window [ 'cmDisplayShops' ] ; switch ( action ) { case 'cmCreateProductviewTag' : const cmCreateProductviewTag = window [ 'cmCreateProductviewTag' ] ; cmCreateProductviewTag ( properties . productId , properties . productName , properties . categoryId , properties . attrbute , properties . virtualCategory ) ; break ; case 'cmCreateShopAction5Tag' : const cmCreateShopAction5Tag = window [ 'cmCreateShopAction5Tag' ] ; cmCreateShopAction5Tag ( properties . productId , properties . productName , properties . quantity , properties . unitPrice , properties . categoryId , properties . attrbute , properties . extraFields , properties . virtualCategory ) ; cmDisplayShops ( ) ; break ; case 'cmCreateShopAction9Tag' : const cmCreateShopAction9Tag = window [ 'cmCreateShopAction9Tag' ] ; cmCreateShopAction9Tag ( properties . productId , properties . productName , properties . quantity , properties . unitPrice , properties . registrationId , properties . orderId , properties . orderSubtotal , properties . categoryId , properties . attrbute , properties . extraFields ) ; cmDisplayShops ( ) ; break ; case 'cmCreateOrderTag' : const cmCreateOrderTag = window [ 'cmCreateOrderTag' ] ; cmCreateOrderTag ( properties . orderId , properties . orderSubtotal , properties . orderShipping , properties . registrationId , properties . registrantCity , properties . registrantState , properties . registrantPostalCode , properties . attrbute , properties . extraFields ) ; break ; case 'cmCreateRegistrationTag' : const cmCreateRegistrationTag = window [ 'cmCreateRegistrationTag' ] ; cmCreateRegistrationTag ( properties . registrationId , properties . registrantEmail , properties . registrantCity , properties . registrantState , properties . registrantPostalCode , properties . registrantCountry , properties . attrbute ) ; break ; case 'cmCreateElementTag' : const cmCreateElementTag = window [ 'cmCreateElementTag' ] ; cmCreateElementTag ( properties . elementId , properties . elementCategory , properties . attrbute ) ; break ; case 'cmCreateConversionEventTag' : const cmCreateConversionEventTag = window [ 'cmCreateConversionEventTag' ] ; cmCreateConversionEventTag ( properties . eventId , properties . actionType , properties . eventCategoryId , properties . points , properties . attrbute , properties . extraFields ) ; break ; default : console . warn ( 'Unsupported Event Action' ) ; } } }