Google Analytics tracking code not installed - google-analytics

i am using google analytics to track my site. They said to add a tracking.js code to my site in every page to track the site. For which i made a google_analytics.js file, wrote the code there and included this file in everypage i need to track. But Google Analytics page is saying that track is not installed!

Google analytics provide this service through two js - ga.js and another is analytics.js
For ga.js, you need to write following code in each html page of your site -
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(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);
})();
</script>
if you are using analytics.js, you need to write below code in each page of your site -
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX-Y');
ga('send', 'pageview');
</script>
please see this link for more info -

Related

Has the Google Analytics script block changed?

I've been given some code to put into a couple of sites, as below (tracking id amended)
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-99999999-99']);
_gaq.push(['_trackPageview']);
(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);
})();
</script>
But I've just created a new GA account, and the script GA states to add is below: (again tracking id amended)
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-99999999-99', 'auto');
ga('send', 'pageview');
</script>
Has this "standard" code changed recently or is there another reason for the difference? I'm trying to pre-empt a "why isn't this the code we sent you?" question if I use the code GA has asked me to use.
There are two versions of Google Analytics.
Classic analytics which uses ga.js your first snippet.
and
Universal analytics which uses analytics.js your second snippet.
If you have an older Google Analytics account you may be using the old snippet. All new sites are created using Universal analytics and should use the new snippet.
Technically speaking even old sits should start using the new snippet but the old snippet will still work for them. I don't think that new sites can use the old snippet tbh there would really be no point in doing so because so many features are not supported in it.
So who ever sent you that snippet is behind times and didn't realize that there is a new version of Google Analytics.

Why is tracking code generated for my site different than what is in the documentation?

Looking at the GA developers page at https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide it says the tracking code is:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(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);
})();
But when I start an account for my site GA gives me the tracking code:
(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-XXXXX-1', 'auto');
ga('send', 'pageview');
Why are these completely different?
Thanks
The first code snippet is for the old/traditional Google Analytics tracking script.
The second one uses the newer universal Google Analytics tracking script.
The reason why they are different is probably because Google is trying to push the newer tracking script, but haven't updated all of their documentation.
The analytics.js JavaScript library is built on Universal Analytics technology. If you’re using a tracking code snippet on your website that references analytics.js, you’re using Universal Analytics.
If you’re using any other library, like ga.js, you’re using a Classic Analytics tracking technology, and should upgrade your tracking code (if you also have a Universal Analytics property).
Reference

How to install and verify asynchronous Google Analytics tracking code?

In my property's Tracking Code section I see this message:
Status: Tracking Not Installed Last checked: Oct ...
The Google Analytics tracking code has not been detected on your website's home
page. For Analytics to function, you or your web administrator must
add the code to each page of your website.
The tracking code shown to be copy/pasted is this:
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXx', 'example.com');
ga('send', 'pageview');
</script>
There's a learn more button and when I click it it takes me to here which shows the asynchronous code, which is something like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-Y']);
_gaq.push(['_trackPageview']);
(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);
})();
</script>
Is this the current/latest version of the GA code? Why is the dashboard (i.e. the Tracking Code section) is not showing this by default? Is there a way to customize the Google Analytics to show this code in the Tracking Code section, prepared for my property (website)?
What you are seeing first is the latest version of Google Analytics known as Universal Analytics. As per Google recommendation , use that for all your new analytics properties. This is identified by the analytics.js library in the tracking code
The second one is an earlier version of Google Analytics based on ga.js library.
Use the first version of tracking code given by GA and follow this tutorial based on analytics.js to debug your code.

How to use both ga.js and analytics.js?

How do i use both for an existing google acc that has been using ga.js...i cant seem to find the right documentation. anyone with experience in this?
To expound what Pete says.
Create a new web property for analytics.js
- In your google analytics account, go to Admin section and Create a new web property
- Creating a new property will provide you with a new Tracking ID
Dual Tag
- Add both your ga.js and analytics.js tracking code. Note that they must not share the same UA code. Your codes may look something like below:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxx-y']);
_gaq.push(['_trackPageview']);
(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);
})();
</script>
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxx-z', 'yoursite.com');
ga('send', 'pageview');
</script>
Existing ga.js users should create a new web property for analytics.js and dual tag their site. It is perfectly safe to include both ga.js and analytics.js snippets on the same page.
see
https://developers.google.com/analytics/devguides/collection/analyticsjs/
The ga.js code will be obsolete in a couple of years, i suggest you migrate to Universal analytics. The initial phase has probably started by non.

Confused between Google's Universal Analytics and Async Analytics. Are we supposed to use both?

After setting up Google analytics for the first time I went to Admin > Tracking Code:
So apparently this is Universal Analytics given to me.
<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','//www.google-analytics.com/analytics.js','ga');
ga('send', 'pageview');
</script>
I can't find my asynchronous tracking code (which would look like this):
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(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);
})();
</script>
Am I only supposed to use one?
Do they both go right before </head>?
As universal is in beta, I would continue using ga.js tracker on your primary web properties.
If you want to try out the new functions (e.g. custom dimensions/metrics) of Universal, you can create a new property specifically for it.
Also, to simplify deployment, try Google Tag Manager.

Resources