Google Analytics: Tracker not started

Hey @reedrichards, I found the problem, but its really really weird.

There is an uncaught exception in the Java code for the plugin in the UniversalAnalyticsPlugin.java file, in the execute function:

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (START_TRACKER.equals(action)) {
        String id = args.getString(0);
        this.startTracker(id, callbackContext);
        return true;
    } else if (TRACK_VIEW.equals(action)) {
        int length = args.length();
        String screen = args.getString(0);
        System.out.println("GoogleAnalytics JEUDY dentro de execute para llamar a trackView con screen: " + screen);
        try{
          this.trackView(screen, length > 1 ? args.getString(1) : "", length > 2 ? args.getBoolean(2) : false, callbackContext);
        }catch(Exception ex){
          System.out.println("GoogleAnalytics OOPS something wrong on execute: " + ex.getMessage());
          this.trackView(screen, "", false, callbackContext);
        }

This showed up in my logs:

11-30 17:08:14.917 7119 7164 I System.out: GoogleAnalytics OOPS something wrong on execute: Value null at 2 of type org.json.JSONObject$1 cannot be converted to boolean

So just to test I went ahead and called trackView with the default params and voilĆ” ! got activity in GoogleAnalytics.

So the problem is that trackView was never being called in the java code of the plugin. No idea how it works for others or why it fails on my installation.

Congrats!!! Was a pretty good idea to add traces to the plugin itself, well done.

May I ask, where do you mean with ā€œI went ahead and called trackView with the default paramsā€?

Did you already report this issue?
I tried to change this on my side aswell but tracker still not starting

In the catch, I call it

this.trackView(screen, ā€œā€, false, callbackContext);

but that was just for testing.

1 Like

Hi @Saalbach

This issue in the java part is for the trackView, when the tracker is already started.

What fixed the ā€œtracker not startedā€ for me was to implement everything in a service, and make sure you include the cordova.js file in your index.html before including the other js files.

Thx for the documentation. Maybe would it be good to open a ticket in the projectā€™s GitHub.

And again, congrats for finding the solution, have fun now :slight_smile:

Hi @jeudyx

Iā€™ve changed it within the Java-Part but had no effect for me, but Iā€™ve already seen that you commited an Bug on Github! Maybe the fixed PR will help me.

Thanks so far

I had the same problem too :frowning: . Any one please help

If you are using plugin version 1.7 that it has a bug, it wonā€™t work on Androidā€¦ I had same issue so I downgrade to 1.6.0 and itā€™s start working againā€¦

you can also track bug on https://github.com/danwilson/google-analytics-plugin/issues/291

platform.ready().then(() => {
GoogleAnalytics.startTrackerWithId(YOUR-ANALYTICS-ID);      GoogleAnalytics.setAllowIDFACollection(true);
});

GoogleAnalytics.trackView('Track what you want to.');

1 Like

Glad I found this thread. Itā€™s a bit of a consolation to see that Iā€™m not the only one having bad luck with this!

For those who got it to work on Android, how did you make sure itā€™s 1.6.0? Is it that it shows the version on ā€œionic pluginsā€? Did you also have to update config.xml and package.json with the 1.6.0 version?

I started looking at alternatives to Google Analytics for this, but couldnā€™t really come up with anything. Ionicā€™s version of Analytics (https://docs.ionic.io/services/analytics/) is not yet available.

Maybe try removing the plugin:

cordova plugin remove cordova-plugin-google-analytics --save

And then adding the specific version:

cordova plugin add cordova-plugin-google-analytics@1.6.0 --save
2 Likes

Yes you can do as reedrichards told, you can check your plugin version under plugin/google-analytics-plugin/plugin.xml file

2 Likes

@reedrichards and @jigsaxis, thank you for the tips!

looks like my Google Analytics tracking is now working, using the 1.6.0 version. Woohoo!

3 Likes

@reedrichards and @jigsaxis.

I downgraded to 1.6.0 and still not able to build Google Analytics.

I get the following error:

* What went wrong:
Execution failed for task ':processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.2.0.

Nothing that Iā€™ve found in Google works.

Any ideas?

No idea. Maybe a targetSdkVersion problem or maybe your local android sdk should be updated?

Thankā€™s, for me resolved.

Hi
In my application i am using GA but needs to get clear information about google-service.json
Its whether needed to implement GA or not.
I am implemented the GA without google-service.json but in few sites they told abt it will not work in productionā€¦
Can anybody please clarify me.
Whats the advantages if we use google play services.

Thanks & Regards
Yoga

Try to use Google Analytics Native Plugin for Ionic 3 Applications check tutorial here http://www.freakyjolly.com/add-google-analytics-in-ionic-3-application-using-cordova-and-ionic-native-plugin/

Is a problem related with google-play-services incompatibilities. For fix it you have to make sure that all the PLAY_SERVICES_VERSION are the same, in my case for google-maps, googleplus and the rest I used 15.0.2, but for analytics I have to use 15.0.2 (because there are not a 15.0.1 in maven repo).

SO go to your config.xml and add/change your analytics plugin tag to

    <plugin name="cordova-plugin-google-analytics">
        <variable name="PLAY_SERVICES_VERSION" value="15.0.2" />
    </plugin>

and make sure that all the other plugins have some 15.* version. (if you are using another one just make sure that all play service use the same version)

Then if you already added a platform, go to platforms/android/project.properties and the same, just make sure that all play-services libraries are the same version. for example I have:

cordova.system.library.10=com.google.android.gms:play-services-analytics:15.0.2
cordova.system.library.13=com.google.android.gms:play-services-maps:15.0.1

ā€¦

Hope that this work for you, work for me after a lot of research.

2 Likes

UPDATE: With new changes of the library now works properly with 15.0.1 version of play services. They fixed the google play version on last versions of the package