revolunet/angular-google-analytics

How to use Analytics with Ionic Serve (Emulator for Chrome) and Android

Opened this issue · 10 comments

Hi,
I dont see any page views in google analytics.

I test it with inoic serve in chrome and with a android tablet (android version 5.1.1. tablet, and android samsung galaxy s4 with android 4.4.2)

my configprovider:

.config(function (AnalyticsProvider) {
  // Add configuration code as desired - see below

  AnalyticsProvider
      .logAllCalls(true);
    AnalyticsProvider.setAccount([
        { tracker: 'UA-70818677-1', name: "tracker1" }
    ]);

  AnalyticsProvider.setDomainName('XXX');
  AnalyticsProvider.setHybridMobileSupport(true);
  AnalyticsProvider.trackPages(true);
})

And in the angular controller:
Analytics.trackPage('/catalog/list/current/IN', 'Catalog');
Analytics.pageView();

I hope anyone can help me out

thanks!

arjan

@arjandew I am not sure what 'inoic serve' for Chrome is and I don't have an Android tablet to assist in debugging what you might be experiencing.

Your configuration appears to be correct. Are you able to get the log from the Analytics service while on the device to see if the setup is happening? I'd imagine the issue is something specific to how analytics.js is handling the environment. Are you able to see any debug information from the analytics.js script?

if you're on localhost, try:
AnalyticsProvider.setDomainName('none');

@justinsa ionic serve is a chrome emulator, how do i get the log from the Analytics service? i can see the logs in the analytics object wich looks perfect. but i dont know how to see the debug information from the analytics.js sript.

@nuriel i tried that but it doesn't work

I'm having similar issues...nothing is being sent to Google Analytics. I've tried both of these configurations with no luck.

        app.config(function (AnalyticsProvider) {
            //AnalyticsProvider
            //    .setAccount('UA-23413027-1')
            //    .useAnalytics(true)
            //    .logAllCalls(true)
            //    .trackPages(true);

AnalyticsProvider
.setAccount([{ tracker: 'UA-23413027-1', name: "callT", trackEvent: true }])
.trackPages(true);

        });

@arjandew Advanced debugging with analytics.js is explained here: https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#debug. I am intending to add configuration support for this advanced debugging to angular-google-analytics when I get the chance, but that hasn't happened yet.

@arjandew I've added the debugging support in the latest release. The README explains how to enable this. I hope that helps resolve the issue with Ionic Serve / Android and Google Analytics. If you can let us know what you uncover it would be appreciated and we can incorporate a change into this library to workaround this in the future.

this is not bug
solution is disable cookie and use localstorage:
clientId = localStorage.getItem(GA_LOCAL_STORAGE_KEY);
if (!clientId) {
clientId = uuid4.generate();
localStorage.setItem(clientId);
}
AnalyticsProvider.setAccount({
tracker: "gaTrackingId",
fields: {
storage: 'none',
clientId: clientId
}
});

denyo commented

@zloyag thank you for that hint which helped me get it working.
It looks like web based Android apps built with Ionic don't support cookies. That's why GA never sends anything out because the clientID is bad or not set at all. To solve this you have to take care of generating and storing the cidyourself.

Here is how I set it up in combination with ngStorage:

var options = {
    tracker: ENV.googleAnalyticsId,
    trackEvent: true
};

if(ionic.Platform.isAndroid()){
    var clientId = $localStorageProvider.get('GA_LOCAL_STORAGE_KEY');
    if(!clientId){
        clientId = Math.floor((Math.random() * 9999999999) + 1000000000);
        clientId = clientId+'.'+Math.floor((Math.random() * 9999999999) + 1000000000);

        $localStorageProvider.set('GA_LOCAL_STORAGE_KEY', clientId);
    }

    options.fields = {
        storage: 'none',
        fields: clientId
    };
}

AnalyticsProvider.setAccount(options);

np, but for unique cid better to use angular-uuid4:
a way for injecting it's in config:
app.config(function(){
var uuid4 = angular.injector(['uuid4']).get('uuid4');
clientId = uuid4.generate();
})

@zloyag hi,Have you solve this problem? i have the same situation。In your solution what is the "uuid4"? i am littel confused. it is so lucky if i get your reply.