import { Injectable } from '@angular/core' ; import { Title } from '@angular/platform-browser' ; import { Angulartics2 } from '../../angulartics2-core' ; import { ClickyProperties } from './clicky.interfaces' ; declare var clicky ; @ Injectable ( { providedIn : 'root' } ) export class Angulartics2Clicky { constructor ( private angulartics2 , private titleService ) { if ( typeof clicky === 'undefined' ) { console . warn ( 'Angulartics 2 Clicky Plugin: clicky global not found' ) ; } } startTracking ( ) { this . angulartics2 . pageTrack . pipe ( this . angulartics2 . filterDeveloperMode ( ) ) . subscribe ( x => this . pageTrack ( x . path ) ) ; this . angulartics2 . eventTrack . pipe ( this . angulartics2 . filterDeveloperMode ( ) ) . subscribe ( x => this . eventOrGoalTrack ( x . action , x . properties ) ) ; } param path link pageTrack ( path ) { const title = this . titleService . getTitle ( ) ; clicky . log ( path , title , 'pageview' ) ; } param action param properties link link eventOrGoalTrack ( action , properties ) { if ( typeof properties . goal === 'undefined' ) { const title = properties . title || null ; const type = properties . type != null ? this . validateType ( properties . type ) : null ; clicky . log ( action , title , type ) ; } else { const goalId = properties . goal ; const revenue = properties . revenue ; clicky . goal ( goalId , revenue , ! ! properties . noQueue ) ; } } private validateType ( type ) { const EventType = [ 'pageview' , 'click' , 'download' , 'outbound' ] ; return EventType . indexOf ( type ) > - 1 ? type : 'pageview' ; } }