0

I'm trying to log an event whenever a user visits a screen on my Angular/Ionic application.

Here is my config info :

Ionic:

   ionic (Ionic CLI)  : 4.1.2 (/Users/rguerin/.nvm/versions/node/v8.11.2/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.0
   Cordova Platforms     : ios 4.5.5
   Cordova Plugins       : no whitelisted plugins (16 plugins total)

System:

   NodeJS : v8.11.2 (/Users/rguerin/.nvm/versions/node/v8.11.2/bin/node)
   npm    : 6.4.1
   OS     : macOS High Sierra
   Xcode  : Xcode 10.0 Build version 10A255

Im also using the following plugin :

<plugin name="cordova-plugin-firebase" spec="^2.0.0" />

The event I was looking for is "screen_view", but it is logged automatically by Firebase. The thing is this event is only logged once because, as I am using Cordova, the plugin might think of my app as a single page.

When I try to pass it manually (see code below) I do not see it in my Firebase dashboard.

export class CustomerPage {

     ionViewDidEnter(): void {

         (<any>window).FirebasePlugin.logEvent('screen_view', { page_id: 'customer_page' },
                () => this.logger.trace('log event success'),
                error => this.logger.error('Error login event: ', error));
     }
}

I would like to avoid using custom event, as I saw here and there , it is a non free and limited solution.

Anyone got a workaround to create a reliable and exploitable tracking plan?

rguerin
  • 2,068
  • 14
  • 29

1 Answers1

0

Ok, so as a workaround I'm using the setScreenName method. I set my current screen name inside ngOnInit hook for each component and it seems to work :

export class TestPage implements OnInit {

    ngOnInit(): void {
        (<any>window).FirebasePlugin.setScreenName('TestPage');
    }
}

But I don't think it is still 100% reliable, and a bit harsh to test as the dashboard is not live-reloaded.

If anyone have a better way to do this, you would be welcome :)

rguerin
  • 2,068
  • 14
  • 29