import { Injectable , Inject } from '@angular/core' ; import * as app from 'application' ; import { isIOS } from 'platform' ; declare var com ; import * as _ from 'lodash' ; var firebase = require ( "nativescript-plugin-firebase" ) ; export interface IAnalyticsProperties { category ? : string ; label ? : string ; value ? : number ; } export interface IAnalytics { track ( action , properties ) : void ; } @ Injectable ( ) export class AnalyticsService implements IAnalytics { private _devMode : boolean = false ; constructor ( ) { } /**
     * Track actions, events, etc.
     **/ public track ( action , properties ) { if ( isIOS && ! this . devMode ( ) && firebase && firebase . analytics ) { let props = [ ] ; if ( properties ) { if ( properties . category ) { props . push ( { key : 'category' , value : properties . category } ) ; } if ( properties . label ) { props . push ( { key : 'label' , value : properties . label } ) ; } if ( properties . value ) { props . push ( { key : 'value' , value : properties . value } ) ; } } firebase . analytics . logEvent ( { key : action , parameters : props } ) . then ( ( ) => { } ) ; } } /**
     * Identify authenticated users
     **/ public identify ( properties ) { if ( ! this . devMode ( ) && firebase && firebase . analytics ) { firebase . analytics . setUserProperty ( properties ) ; } } /**
     * Control whether analytics are tracked
     * true: dev mode on, therefore do not track anything
     * false: dev mode off, track everything
     **/ public devMode ( enable ? ) { if ( typeof enable !== 'undefined' ) { this . _devMode = enable ; } return this . _devMode ; } } /**
 * Base class
 * Standardizes tracking actions and categorization
 */ export class Analytics implements IAnalytics { public category : string ; constructor ( @ Inject ( AnalyticsService ) public analytics ) { } /**
     * Track actions, events, etc.
     **/ track ( action , properties ) { this . analytics . track ( action , Object . assign ( { } , properties , { category : this . category } ) ) ; } }