GALocalStorage icon indicating copy to clipboard operation
GALocalStorage copied to clipboard

Uncaught ReferenceError: ga is not defined

Open bigreni opened this issue 7 years ago • 6 comments

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?

bigreni avatar Jan 09 '18 03:01 bigreni

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.

ggendre avatar Jan 09 '18 08:01 ggendre

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 avatar Jan 09 '18 22:01 bigreni

@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');

mxkeke avatar Jan 30 '18 07:01 mxkeke

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.

ggendre avatar Jan 30 '18 08:01 ggendre

I updated the readme in a more step-by-step way

ggendre avatar Jan 30 '18 08:01 ggendre

@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).

mxkeke avatar Jan 30 '18 09:01 mxkeke