import { Injectable } from '@angular/core' ; import { Angulartics2 } from '../../angulartics2-core' ; declare var _hmt ; @ Injectable ( { providedIn : 'root' } ) export class Angulartics2BaiduAnalytics { constructor ( private angulartics2 ) { if ( typeof _hmt === 'undefined' ) { _hmt = [ ] ; } else { _hmt . push ( [ '_setAutoPageview' , false ] ) ; } this . angulartics2 . setUsername . subscribe ( ( x ) => this . setUsername ( x ) ) ; 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 ) ) ; } param path link pageTrack ( path ) { if ( typeof _hmt !== 'undefined' && _hmt ) { _hmt . push ( [ '_trackPageview' , path ] ) ; } } param action param properties link eventTrack ( action , properties ) { if ( ! properties || ! properties . category ) { properties = properties || { } ; properties . category = 'Event' ; properties . opt_label = 'default' ; properties . opt_value = 'default' ; } if ( typeof _hmt !== 'undefined' && _hmt ) { _hmt . push ( [ '_trackEvent' , properties . category , action , properties . opt_label , properties . opt_value , ] ) ; } } setUsername ( userId ) { _hmt . push ( [ '_setCustomVar' , 1 , 'identity' , userId ] ) ; } setUserProperties ( properties ) { _hmt . push ( [ '_setCustomVar' , 2 , 'user' , JSON . stringify ( properties ) ] ) ; } }