Ionic 2 RC.0 - Google Analytics


#1

I finally upgraded my app to Ionic 2 RC0 and when i run the app on my Device i get a error in Google Analtycs (work on latest beta)

The plugin is installed

Any have managed to work with RC,0?

Thanks
Baltazar


#2

Did you manage to get this working?

Struggling with the same problem…

Thanks!

Matthias


#3

I have a issue open to resolve this problem.


#4

and are your waiting in your source code that the platform is ready before you are using the plugin?

// wait for `ondeviceready` or use `platform.ready()` if you're using Ionic Framework 2
this.platform().then(() => { // we're assuming you injected platform in your constructor
  Camera.getPicture().then(
    res => console.log("We have taken a picture!"),
    err => console.error("Error taking picture", err)
  );
});

#5

Yes. Off Course!


#6

Works now!

But not sure, what exactly caused the problem…

First I ran this (suggested by mlynch here https://github.com/driftyco/ionic-native/issues/602):

ionic state reset
rm -rf node_modules
npm install

But I also had an error in my code:
I didn’t wait for the platform/plugins to be ready in my root page.
There I just executed GoogleAnalytics.trackView(‘xxx’) in the constructor.

Matthias


#7

Ok, the solution for me must have been the steps suggested by mlynch.

The code error (calling trackView in the rootpage before device ready) didn’t cause the complete failure of the analytics plugin.
I’ve tested it, all other calls to the analytics plugin, which are executed on other pages and after the device is ready, do run into google analytics correctly.


#8

And where you put this code?

GoogleAnalytics.startTrackerWithId(“UA-XXX-XX”);

i have in App.Component.ts and have the same error!


#9

yes, have this code after platform ready in the constructor of app.component.ts too


#10

So for me, don´t work…! It is strange, i have after platform ready and appears to be called before…