devapp
Posts: 0
Joined: Mon Mar 23, 2015 3:12 pm

I'm facing issues with enabling Google analytics on my app. Need help

I've created a .js file with the following code:
var _gaq = _gaq || [];
//Note: you should replace this value with your personal site data.
gaq.push(['setAccount', 'UA-62826163-1']);
gaq.push(['trackPageview']);
//Add event handler on page show.
var onPageShow = function(){
//Track page into GA when it has been shown
gaq.push(['trackPageview', window.location.href]);
};
jQuery(document).bind("pageshow", onPageShow);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();

Do I need to add any event on pages after this?

devapp
Posts: 0
Joined: Mon Mar 23, 2015 3:12 pm

I'm facing issues with enabling Google analytics on my app. Need help

Yes, I've seen the tutorials. I just want to tack the pages on an Android app, that's it. Should I use the following code and add it as .js file?

var initGA = function() {
console.log('Initialize GA');
if (getGAPlugin()) {
getGAPlugin().init(gaSuccessHandler, gaErrorHandler, "ENTER_YOUR_GOOGLE_ANALYTICS_ID_HERE", 10);
}
};

var trackPage = function(pageName) {
console.log("trackPage: " + pageName);
if (getGAPlugin()) {
getGAPlugin().trackPage(gaNativePluginResultHandler, gaNativePluginErrorHandler, pageName);
}
};

var trackEvent = function(category, eventAction, eventLabel, eventValue) {
console.log("trackEvent: " + category);
if (getGAPlugin()) {
getGAPlugin().trackEvent(gaNativePluginResultHandler, gaNativePluginErrorHandler, category, eventAction, eventLabel, eventValue);
}
};

Then add an event handler on every page?

trackPage('pagename');

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

I'm facing issues with enabling Google analytics on my app. Need help

Hello,

Yes, use that JS in your app.

Return to “Issues”