Google analytics do not work


#1

Hi all,
I am trying to use GA in my app.

In app inicialization I have this part of code:
GoogleAnalytics.startTrackerWithId(“UA-*****”);

And in every component constructor i have:
this.platform.ready().then(() => {
GoogleAnalytics.trackView(“Title”);
});

After app launch I have console error: main.js:7 EXCEPTION: Uncaught (in promise): Tracker not started

Can you help me with it?

Thanks


#2

Do you have wrapped all your plugins call in platform.ready??

platform.ready().then((readySource) => {
      console.log('Platform ready from', readySource);
      // Platform now ready, execute any required native code
});

#3

I had that problem too. To solve it you have to handle your google analytics queries in a providers/service.

 this.platform.ready().then(() => {
  myService.startTracker();
  myService.trackView("Title");
}

etc.

I posted my service code, where I also stack the analytics request till the cordova plugin is ready, there (see peterpeterparker)


#4

I have it like you :-/


#5

the exact same code as I posted in the GitHub issue? You have written a service etc.? Maybe could you show some more details of your codes?


#6

I used the service but some type is red and I don’t know what to do with it :-/

in “trackView()” it is: analytics and than
in “trackEventsNotSent()” it is: Promise and Comparator
in “initGoogleAnalytics()” it is: Promise and catch


#7

you could replace the comparator with following (I edited my solution too):

this.eventsNotSent == null || Object.keys(this.eventsNotSent).length === 0

these are the imports I do (I edited the solution too):

import {Injectable} from '@angular/core';
import {GoogleAnalytics} from 'ionic-native';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/forkJoin';

#8

Replaced but others are still red :-/


#9

for window.analytics you could define an empty interface or cast it in < any >

for the Promise and catch honestly I don’t know why it doesn’t work, it’s like a basic class I thought. You don’t have any Promise and catch in your all app?


#10

Yes I have Promises but with catch I have problems in all app… :-/


#11

strange. maybe remove the catch just for test purpose?


#12

have you seen the last post?

seems it works better with version 1.6.0 of the plugin…if that could help


#13

Jej, it seems working :slight_smile: