import { Injectable } from '@angular/core' ; import { Angulartics2 } from '../../angulartics2-core' ; declare var amplitude ; @ Injectable ( { providedIn : 'root' } ) export class Angulartics2Amplitude { constructor ( private angulartics2 ) { this . angulartics2 . setUsername . subscribe ( ( x ) => this . setUsername ( x ) ) ; this . angulartics2 . setUserProperties . subscribe ( ( x ) => this . setUserProperties ( x ) ) ; this . angulartics2 . setUserPropertiesOnce . 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 ) { try { this . eventTrack ( 'Pageview' , { url : path , } ) ; } catch ( e ) { if ( ! ( e instanceof ReferenceError ) ) { throw e ; } } } eventTrack ( action , properties ) { try { amplitude . getInstance ( ) . logEvent ( action , properties ) ; } catch ( e ) { if ( ! ( e instanceof ReferenceError ) ) { throw e ; } } } setUsername ( userId ) { try { amplitude . getInstance ( ) . setUserId ( userId ) ; } catch ( e ) { if ( ! ( e instanceof ReferenceError ) ) { throw e ; } } } setUserProperties ( properties ) { try { amplitude . getInstance ( ) . setUserProperties ( properties ) ; } catch ( e ) { if ( ! ( e instanceof ReferenceError ) ) { throw e ; } } } }