Analytics
3K members online now
3K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

google analytics for single page app running locally

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

We like to use Google Analytics on our single page app.  I have read through all technical guides and still run into issues.  Here is the setup: 

1. the single page app deployed to local server for testing, so the url to access the app is like: http://localhost/~shanl/myapp/

2. the single page is index.html, into which I put the following codes before </head>:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

//ga('create', 'UA-34423886-3', {'storage': 'none', 'clientId': device.uuid});
ga('create', 'UA-34423886-3', 'auto');
ga('set', 'checkProtocolTask', null);
ga('set', 'checkStorageTask', null);
ga('set', 'appName', 'Marvelous Deltek APP2');
ga('set', 'page', '/index2.html');
ga('send', 'screenview', {'screenName': 'LaunchScreen2'});
ga('send', 'pageview');
ga('send', 'event', 'Apps', 'Enter', 'Maco TE2');

3. the hits did not get tracked.  Using Google Tag Assistance, shows a error message "No HTTP Response Detected".

 

Could someone shed some lights on what goes wrong?  BTW, cookie domain set to 'auto' or 'none' yields the same result.

1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Shan L
December 2015

Re: google analytics for single page app running locally

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
To follow up on this, and thanks again @GA Guru for the recommendation of the wonderful tool, the problem actually lies to the Content Security Policy of the header in index.html. After adding google analytics to the list, I am able to track the hits.
Now if I want to wrap this in a cordova hybrid app, I might need to use a local analytics.js.

View solution in original post

Re: google analytics for single page app running locally

A T
Participant ✭ ✭ ✭
# 2
A T
Participant ✭ ✭ ✭

Re: google analytics for single page app running locally

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Thanks @GA Guru for the great tool. It seems promising, and I will give it a try. For the url path, I follow exactly what google suggests. I guess its purpose is to adapt to 'http' and 'https'. Is this the reason? If that is the reason, following the same logic, I should use a local analytics.js if I want to package it into hybrid app. Is it right?
Marked as Best Answer.
Solution
Accepted by topic author Shan L
December 2015

Re: google analytics for single page app running locally

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
To follow up on this, and thanks again @GA Guru for the recommendation of the wonderful tool, the problem actually lies to the Content Security Policy of the header in index.html. After adding google analytics to the list, I am able to track the hits.
Now if I want to wrap this in a cordova hybrid app, I might need to use a local analytics.js.