I am implementing google analytics for the first time. Here are the steps I took.
I went to analytics.google.com and created an account. Then I created a "property". After that I created a "Data Stream" for my website and got a "Measurement ID which starts with a G-XXXXXXX. Then I implemented the following code in the header (before any other css or js calls)
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'G-XXXXXXX', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
When I look at the network tab, I can see that the call was made:
Request URL: https://www.google-analytics.com/j/collect?v=1&_v=j96&a=316116739&t=pageview&_s=1&dl=https://mywebsite.com&ul=en-gb&de=UTF-8&dt=My Website Title&sd=24-bit&sr=1920x1080&vp=1920x577&je=0&_u=ABC~&jid=1234&gjid=1234&cid=1234.1234&tid=G-XXXXXXX&_gid=1234.1234&_r=1&_slc=1&z=1234
Method: Post
Status Code: 200
However when I look at google analytics, it says "Data collection isn't active for your website".
I waited 24 hours to ensure it is not some delay problem but there is still no data and there have been visitors on the website, at the very least myself.
Is there a step I missed or maybe it could be a configuration issue? I haven't been able to find any clues as to why it might not be working. Any help is most appreciated.
Note: The values above in Request URL have been modified to remove any sensitive information. All the parameters are there, just values have been changed to ABC and 1234 as its not necessary to see those.
If you want to track with GA4 (G-xxxxxxxx)
You need to use gtag.js for it.
ga.js is not support for GA4
Here is the document
Related
I develop an web application with preact. The total size of the webapp is about 30KB gzipped (Google Analytics is about 14KB). I want to add google analytics but I dont want that google analytics slows down the initial page load. The recommended method to include analytics.js () is
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q|| .
[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'> .
</script>
<!-- End Google Analytics -->
This works fine, but the analytics.js gets downloaded before my other stuff gets downloaded. Im pretty sure that this affects the page load as you can see in this picture)
What is the recommend way to download analytics after the page finished loading. (In my case after 'menu' gets downloaded)
I know this is old, but you could add the defer attribute instead of the async attribute to your tag. Async will download the file asynchronously, but it still blocks the main thread while it's running the javascript. Defer will also download asynchronously, but will wait to run the javascript until the HTML parses. This is one of many articles that explains the difference between async and defer
If you really don't want the GA affecting load speeds, you could add an event listener that waits for the window 'load' event before injecting the GA script tags. That is probably overkill for a 30KB web app, but GA will have almost no affect on your page loads.
GA shouldn't be slowing down your website right now
Your script is async, which means it's not blocking the browser from carrying on with other tasks. Accordingly, from the trace screenshot you gave, we can indeed see that while analytics.js is being requested, the browser is making other concurrent requests (bundle.js, ,menu), so you're good.
Loading GA after page load
If you still want to defer loading of GA after page load for best practices, just call GA later:
Using Javascript: Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for it
Using a Tag Manager: for instance with Google Tag Manager, use the Window Loaded trigger which fires when the browser is done loading the page: https://productforums.google.com/forum/#!topic/tag-manager/xOMFkfH0U4k;context-place=forum/tag-manager
I'm trying to introduce Google Analytics in a sort of desktop app that all loading files are done through file:// not http or localhost (because most of the time it works offline). Any attempt to track app uses with Google Analytics or Google Tag Manager wasn't work.
For example, I've used:
ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'checkProtocolTask', null);
ga('set', 'checkStorageTask', null);
ga('send', 'pageview');
As explained here (adding ga('set', 'checkStorageTask', null);
) with no results.
Has anybody deal with this situation?
I run a very quick test. ga('set', 'checkStorageTask', null); did nothing for me, instead I found it necessary to set storage to none on tracker creation (which makes sense, since you cannot set cookies with the file protocol). This also means that you probably won't have session tracking, since each hit generates a new ID.
ga('set', 'checkProtocolTask', null) seems necessary - else the debugger complains (naturally) that file is not a valid protocol.
After that data was sucessfully sent, but did not show up in the realtime view. I suspected that maybe the reporting engine does not like the file protocol and set the "location" field with a correct protocol. So I ended up with:
ga('create', 'UA-XXXXXX-5' , {'storage':'none'});
ga('set', 'checkProtocolTask', null);
ga('send', 'pageview' , {'location' : document.location.href.replace('file','http') });
and that displayed in the realtime reports. This was a real quick test, so you need to verify this independently. Notice that you do not need to set a cookie domain (the "auto" argument in your code example) since you cannot set a cookie in any case (there is no domain to set the cookie to).
Also if you work offline for most of the time GA will not work (you need to load the analytics.js file and you need sent calls to the tracking server), but then you are probably aware of that.
I released a new version of my website today and with the old version, I was around 90 visitors an hour, and after the update, it dropped to around 20 visitors.
I don't know what went wrong. Here's the stats:
As you can see, a drop occurred between 3pm and 4pm and drop to finally get to 0 since then.
I added an httpS connection, but the non www and http all redirects to https://www automatically. The tracker is the same, I only added
ga('set', 'forceSSL', true);
ga('set', 'appVersion', '2');
ga('send', 'pageview');
There is only one page (it's a basic app), so there is no other page that could have the tracker removed.
Now, I'm wondering something, when I start the tracker, I send this info :
ga('create', 'UA-XXXXX-X', 'voilanorbert.com');
shouldn't it be ga('create', 'UA-XXXXX-X', 'www.voilanorbert.com');? (with "www.") Is this the issue?
Big Update: I decided to create a new tracker in Google to see if this was a reason, and yes it is! A few minutes after I changed it to the new tracker, the data went to 1 visitors per hour, to 18 in real time! There is clearly a problem in Google Analytics!
Your tracking code was flawed. This does not imply Google Analytics does not work.
The appVersion parameter is reserved for mobile apps and not for the web collection API.
forceSSL is kind of obsolete now
When in doubt, stick to the regular tracking code or use Google Tag Manager.
I have added the Google Dynamic Re Marketing Tag to my website by use of my GTM account (test#gmail.com) successfully; it was shown with minor warnings in Google Tag Assistant as well. But, when I later switched to another GTM account (original#gmail.com) with the same settings it shows an error: “No HTTP response detected”. How this can happen when both the GTM accounts have the same data ? Any help appreciated.
Thanks!
This means clearly the code is not getting executed, could be syntax error, or extra parameters...etc. In my scenario I was sending transaction as part of Ecommerce,
(ref : https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce )
ga('require', 'ec', 'commerce.js'); ///HTTP RESPONSE NOT DETECTED..error.
ga('require', 'ec'); ///SOLVED THE ISSUE
so on similar grounds, check the syntax!
I've been noticing this error on Chrome's console for a while now:
I modified Google's script so that it logs the error, because it uses try{} catch{}, and this is what I got:
I haven't noticed considerable changes in the stats, it's always in ups and downs.
Also, this isn't only on my sites, but fricking everywhere. I haven't found bug reports or anything like that.
If I go to http://www.google-analytics.com/ga.js on the browser, it loads normally.
Does anyone have a clue of what causes this?
It was a problem with AdBlock. I disabled it and now it loads it normally.
yagudaev suggests (read answers below) that in order to keep AdBlock from blocking Google Analytics, you need to edit the snippet provided and explicitly use https:// instead of the protocol-relative URL by default. This means changing
'//www.google-analytics.com/analytics.js'
into
'https://www.google-analytics.com/analytics.js'
Example:
<script>
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-XX', 'auto');
ga('send', 'pageview');
</script>
It could also be your hosts file, here's mine:
$ grep -ni "google-analytics.com" /etc/hosts
6203:# 127.0.0.1 ssl.google-analytics.com #[disabled = Firefox issues]
6204:127.0.0.1 www.google-analytics.com #[Google Analytics]
If it's an offline app (ie, you've defined a cache manifest) be sure to allow the network request.
See HTML5 Appcache causing problems with Google Analytics
The reason you are running into problems is because AdBlock will block this script if and only if it does not go through https. Notice the error you get it contains an http: protocol reference.
All you need to do is change the snippet to force it to go through an ssl connection by adding an explicit protocol instead of the protocol relative url that is the default.
<script>
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-XX', 'auto');
ga('send', 'pageview');
</script>
This error is commonly caused due to one of the extensions installed within Chrome.
There are a few ways to debug and solve an ERR_BLOCKED_BY_CLIENT message.
Disable the extension.
Whitelist the domain.
Debug the issue.
I would recommend to find more detail at How to Solve ERR_BLOCKED_BY_CLIENT
2019 update
This has become very widespread now.
Solutions
Ask people to unblock your website, (bad idea from personal experience)
Host google analytics script locally (bad idea) because google says so HERE
Referencing the JavaScript file from Google's servers (i.e.,
https://www.googletagmanager.com/gtag/js) ensures that you get access
to new features and product updates as they become available, giving
you the most accurate data in your reports.
Use Server side analytics. This is what people are doing nowadays. If you are on node.js, use a library such as analytics or universal-analytics
I've noticed same thing on my browser some time ago.
Did you sing in to chrome using your Google account maybe? Or did you choose in any way to opt-out from collecting data on Google Analytics ?
Maybe Google remembers that option and uses it on Chrome when you are singed in..
BTW. I can normally open http://www.google-analytics.com/ga.js in browser, it just doesn't work when automatically loaded.
Ensure Fiddler (or similar proxy) is not active.