GALocalStorage
GALocalStorage copied to clipboard
Uncaught ReferenceError: ga is not defined
I am using the new code snippet based on local storage.
I have added the GALocalStorage.js file in my
.I am calling the script below at the bottom of the html page. But, I am getting the uncaught referenceerror: ga is not defined.
// THIS IS FOR LOCALSTORAGE var GA_LOCAL_STORAGE_KEY = 'ga:clientId'; ga('create', 'UA-XXXXX-Y', { 'storage': 'none', 'clientId': localStorage.getItem(GA_LOCAL_STORAGE_KEY) }); ga(function(tracker) { localStorage.setItem(GA_LOCAL_STORAGE_KEY, tracker.get('clientId')); });
// THIS IS FOR FILE URL SUPPORT ga('set', 'checkProtocolTask', function(){ /* noop */});
// And then as usual... ga('send', 'pageview');
Can someone please help?
Hi
You still have to add google analytics in your page with this :
<script async src='https://www.google-analytics.com/analytics.js'></script>
Or by downloading it and adding it to your page if your app can work partially offline.
You can check that everything works by using the debug script and watch your JS console :
<script async src='https://www.google-analytics.com/analytics_debug.js'></script>
You can read more about google analytics on their page.
Thank you for the quick response. The console says "Failed" when it tries to load the js file. I am testing it in localhost (I am building an app using phonegap build). Would that be the reason? I also have admob disabled.
Thank you again
@bigreni did you have found a solution?
I've tried with the new code (I've insert it before of the </head>
) but not works on PhoneGap Build (cli-7.0.1+).
I've tried also including the old GALocalStorage.js but nothing:
<script async src='https://www.google-analytics.com/analytics.js'></script>
/ THIS IS FOR LOCALSTORAGE
var GA_LOCAL_STORAGE_KEY = 'ga:clientId';
ga('create', 'UA-XXXXX-Y', {
'storage': 'none',
'clientId': localStorage.getItem(GA_LOCAL_STORAGE_KEY)
});
ga(function(tracker) {
localStorage.setItem(GA_LOCAL_STORAGE_KEY, tracker.get('clientId'));
});
// THIS IS FOR FILE URL SUPPORT
ga('set', 'checkProtocolTask', function(){ /* noop */});
// And then as usual...
ga('send', 'pageview');
you can download the file hosted at https://www.google-analytics.com/analytics.js and add it to your project in head
tag.
If it doesnt work you can keep the old file and code. I added the deprecation warning not because it doesn't work anymore but because there is no need of an external (not made by google) script anymore.
I updated the readme in a more step-by-step way
@ggendre Hi, I've updated with your latest instruction but not works. On the browser works only if I remove "async" from the remote analytics script, but if I compile the app with PhoneGap Build, Google Analytics not show me activity (real time).