import { Location } from '@angular/common' ; import { Injectable } from '@angular/core' ; import { Angulartics2 } from '../../angulartics2-core' ; declare const s ; @ Injectable ( { providedIn : 'root' } ) export class Angulartics2AdobeAnalytics { constructor ( private angulartics2 , private location ) { this . angulartics2 . setUserProperties . subscribe ( x => this . setUserProperties ( x ) ) ; } 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 ) ) ; } pageTrack ( path ) { if ( typeof s !== 'undefined' && s ) { s . clearVars ( ) ; s . t ( { pageName : path } ) ; } } param action param properties link eventTrack ( action , properties ) { if ( ! properties ) { properties = properties || { } ; } if ( typeof s !== 'undefined' && s ) { if ( typeof properties === 'object' ) { this . setUserProperties ( properties ) ; } if ( action ) { const linkName = properties [ 'linkName' ] ? properties [ 'linkName' ] : action ; const disableDelay = ! ! properties [ 'disableDelay' ] ? true : this ; if ( properties [ 'action' ] ) { action = properties [ 'action' ] ; } this . setPageName ( ) ; if ( action . toUpperCase ( ) === 'DOWNLOAD' ) { s . tl ( disableDelay , 'd' , linkName ) ; } else if ( action . toUpperCase ( ) === 'EXIT' ) { s . tl ( disableDelay , 'e' , linkName ) ; } else { s . tl ( disableDelay , 'o' , linkName ) ; } } } } private setPageName ( ) { const path = this . location . path ( true ) ; const hashNdx = path . indexOf ( '#' ) ; if ( hashNdx > 0 && hashNdx < path . length ) { s . pageName = path . substring ( hashNdx + 1 ) ; } else { s . pageName = path ; } } setUserProperties ( properties ) { if ( typeof s !== 'undefined' && s ) { if ( typeof properties === 'object' ) { for ( const key in properties ) { if ( properties . hasOwnProperty ( key ) ) { s [ key ] = properties [ key ] ; } } } } } }