From 23eb5652e8cb7949d745d60c2df5dddee6b6d5c9 Mon Sep 17 00:00:00 2001 From: umasoodch Date: Sat, 31 Jul 2021 14:46:36 +0300 Subject: [PATCH] added analytics code --- Mohem/src/app/app.component.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Mohem/src/app/app.component.ts b/Mohem/src/app/app.component.ts index 3f24ffbf..1d7815fb 100644 --- a/Mohem/src/app/app.component.ts +++ b/Mohem/src/app/app.component.ts @@ -9,9 +9,10 @@ import { PushService } from '../../src/app/hmg-common/services/push/push.service import { LazyLoadingService } from './hmg-common/services/lazy-loading/lazy-loading.service'; import { DomSanitizer } from '@angular/platform-browser'; import { SplashScreen } from '@ionic-native/splash-screen/ngx'; -import { Router } from '@angular/router'; +import { Router, NavigationEnd } from '@angular/router'; import { DigitalIdComponent } from './authentication/digital-id/digital-id.component'; import { checkAndUpdatePureExpressionInline } from '@angular/core/src/view/pure_expression'; +import { FirebaseX } from '@ionic-native/firebase-x/ngx'; @Component({ selector: 'app-root', @@ -56,6 +57,7 @@ export class AppComponent implements OnInit { public router: Router, public modalController: ModalController, public nav: NavController, + public firebasex: FirebaseX ) { this.events.subscribe('img-change', displayImg => { console.log('app compont: ' + displayImg); @@ -83,6 +85,7 @@ export class AppComponent implements OnInit { this.ts.loadResources(() => { this.isIOS = this.platform.is('ios') ? true : false; this.initializeDirection(); + this.monitorAnalytics(); this.start = true; if (this.isIOS) { this.monitUrlChange(); @@ -105,6 +108,25 @@ export class AppComponent implements OnInit { }); } + public monitorAnalytics() { + this.router.events.subscribe((val) => { + if (val instanceof NavigationEnd) { + const lastIndex = val.urlAfterRedirects.lastIndexOf('/'); + const currentPageName = val.urlAfterRedirects.substr(lastIndex + 1); + console.log(currentPageName + ' umarrrrrrrr'); + this.setScreenNameAnalytics(currentPageName); + } + }); + } + + public setScreenNameAnalytics(currentPageName: string) { + try { + this.firebasex.setScreenName(currentPageName).then((result)=>{ + console.log(result); + }); + } catch (Error) { } + } + private startReceivingPushService() { this.pushService.startReceiving(); setTimeout(() => {