Prevent /p/__utm.gif caused by Google Analytics - google-analytics

I am receiving a 404 error from my Google Analytics tracking code. The following is the code I am currently using in the footer of my page:
<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 ? 'ssl' : 'www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
The 404 error appears to be caused by: /p/__utm.gif
I was using the same JS code from this question: Google Analytics and the __utm.gif file. However, that didn't work with my last report from Goolge.
Is there other way to do it?

You are using an older tracking snippet from GA. You should update to the latest version as it should solve your problem. You should also ensure that this tracking code is on all of your pages on your site. The latest code snippet looks more like the following:
<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-X', 'auto');
ga('send', 'pageview');
</script>
You can get a formatted snippet for your site by:
logging into GA (Google Analytics)
Going to the admin UI by selecting the "Admin" tab at the top of the interface
If you have multiple accounts, ensure you have the correct account selected on the left (Account) column of this screen
Select the site you need the snippet for in the center (Property) column.
Select "Tracking Info" and then "Tracking Code" from the middle column.
The column should animate to the left and a new bit should appear that contains your tracking code formatted and completed for your site.
Copy and paste this into every page on your site.

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.

Google Analytics Tracking GA.js vs Analytics.js

I'm trying to use this code to track an event in Google Analytics
_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
This seems to be meant to be use with the GA.js Analytics "package", however I'm using the Analytics.js
Like this
(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');
Is there a way I can do even tracking with this code only ?
Or do I have to use
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);
})();
Do I need both of these codes?
Or is there some different way using only Analytics.js
Thanks in advance
**EDIT:
Indeed I probably didn't explain what I want, it might not even possible.
I want to work with Funnels on Events, and I want to use _trackEvent (that's what I thought it would do) to mark a user as having Entered the Funnel, if the event is send then we will have the normal funnel.
So if 10 users enter the page and 1 clicks on the button, I would have 10 events on the Funnel with 1 success
analytics.js will report to GA same as the old code, but it has different syntax, so you can't use _trackEvent.
Here is a link to the basic on-page syntax with analytics.js, and here is a link for event tracking with analytics.js
<!-- Google Analytics -->
<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 account ID goes here
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action', // Required.
'eventLabel': 'opt_label',
'eventValue': opt_value,
'nonInteraction': opt_noninteraction
});
</script>
<!-- End Google Analytics -->

Resources