All files / src/providers/tracker-service tracker-service.ts

92.86% Statements 13/14
100% Branches 0/0
83.33% Functions 5/6
91.67% Lines 11/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                    1x   39x 39x 39x                                                           2x 2x             2x             1x 4x 4x     1x  
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
/* tslint:disable:no-import-side-effect */
import 'rxjs/add/operator/map';
/* tslint:enable:no-import-side-effect */
import { GoogleAnalytics } from '@ionic-native/google-analytics';
// import { TranslateService } from 'ng2-translate';
import { TranslateService } from '@ngx-translate/core';
 
@Injectable()
export class TrackerService {
 
    constructor ( public http: HttpClient,
                  private ga: GoogleAnalytics,
                  private translateService: TranslateService ) {
    }
 
    // public trackEventWithI18n ( category: { translate: string, params?: any },
    //                             action: { translate: string, params?: any},
    //                             label: { translate: string, params?: any} ) {
    //     const params = {
    //         ...category.params,
    //         ...action.params,
    //         ...label.params
    //     };
    //     this.translateService
    //         .get( [
    //             category.translate,
    //             action.translate,
    //             label.params
    //         ], {
    //             ...category.params,
    //             ...action.params,
    //             ...label.params
    //         } )
    //         .subscribe( ( result: string ) => {
    //             const trackingCategory = result[ category.translate ];
    //             const trackingAction = result[ action.translate ];
    //             const trackingLabel = result[ label.translate ];
    //             console.log( trackingCategory, trackingAction, trackingLabel );
    //             this.ga.trackEvent( trackingCategory, trackingAction, trackingLabel );
    //         }, error => console.log( error ) );
    // }
 
    public translateAndTrack( categoryKey, actionKey, labelKey ) {
        this.translateService
            .get( [
                categoryKey,
                actionKey,
                labelKey
            ] )
            .subscribe( ( result: string ) => {
                this.trackEventWithData(
                    result[ categoryKey ],
                    result[ actionKey ],
                    result[ labelKey ] );
            }, error => console.log( error ) );
    }
 
    public trackEventWithData ( category, action, label ) {
        console.log( `[Tracker]trackEventWithData :: |${category}|${action}|${label}|` );
        this.ga.trackEvent( category, action, label );
    }
 
}