How do i convert my custom google analytics code - google-analytics

Ok i have this additional ga code and need to convert it to the new analytics.js code (universal analytics)::
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setCampSourceKey', 'utm_source']);
_gaq.push(['_setCampMediumKey', 'utm_medium']);
_gaq.push(['_setCampContentKey', 'utm_keyword']);
_gaq.push(['_setCampTermKey', 'utm_keyword']);
_gaq.push(['_setCampNameKey', 'utm_campaign']);
_gaq.push(['_trackPageview']);

Related

Tracking a Page with Multiple Google Analytics Accounts

I used to be able to use two different Google Analytics accounts on a single page with the old ga.js.
This is how I used to do it:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22766576-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setAccount', 'UA-OTHER-ID-1']);
_gaq.push(['_trackPageview']);
...
Google Analytics now defaults to use tag manager's gtag.js and looks like this:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-74053665-19"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-74053665-19');
</script>
The UA id is embeded in the JS call as well as in the config. It doesn't look like it's possible to fire two visits for two separate accounts anymore. Does anyone have any other solutions?

Google Analytics - add third party shopping cart to main domain reports

We would like to track if users sent from our main site to a third party site have bounced or clicked on "Register"
They are willing to put our Analytics code in their pages - both product and registration.
I looked at what is suggested by Google but not clear about a few things.
Our current code on our site:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-nnnnn-1']);
_gaq.push(['_setDomainName', 'none']);
_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>
Code suggested by Google to be on the third party site:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-1']);
_gaq.push(['_setDomainName', 'my-example-blogsite.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
</script>
...
<a href="http://dogs.example-petstore.com/intro.html"
onclick="_gaq.push(['_link', 'http://dogs.example-petstore.com/intro.html']); return false;">
See my pet store</a>
Our code has 'none' in this line: _gaq.push(['_setDomainName', 'none']);
Google's sample code has the URL
_gaq.push(['_setDomainName', 'my-example-blogsite.com']);
Does it matter? Do I need to enter the domain as suggested?
Also Google's code has a link back to our site as follows
onclick="_gaq.push(['_link', 'http://dogs.example-petstore.com/intro.html']); return false;"
Do we need to have a link back? Can we remove the onclick code or will it affect the reporting?
Thanks!
Myalo
You need the onclick event. What is does is to "decorate" the link, i.e. it adds the url parameters that need to be carried over to the other domain (where they are picked up by the Google code and used to continue the session).
Please be aware that the code you are using is horribly outdated. If at all possible switch to the current version (Universal Analytics). While cross domain tracking on Universal Analytics works by the same principle it'S somewhat more elegant (uses a single parameter as opposed to the unwieldy query string for classic GA) and offers a number of helper functions to make cross domain tracking easier.

Google Analytics Cross Domain E-Commerce Campaign Tracking

I want to track e-Commerce related stuff with Google Analytics in relation to campaigns.
The basket/checkout (included via iframe) is on a different domain than the shop.
I've enabled e-commerce tracking in GA, added tracking scripts to both pages and I get a lot of data but it seems that the campaign information gets lost, because all e-commerce data has only "shop.com / referral" as source/medium and not "campaign1/newsletter" as I would expect.
Example:
Script on shop.com:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxx']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setDomainName', 'shop.com']);
_gaq.push(['_setAllowLinker', true]);
...
Enter the site via
http://shop.com/page.html?utm_campaign=campaign1&utm_source=newsletter...
Get iframe src
via _gat._getTrackerByName()._getLinkerUrl('http://basket.com/page.html')
which returns something like
http://basket.com/page.html?__utma=14776951xxx&__utmb=14776xx..
Embed iframe with this url..
On basket.com/page.html I've added the following GA E-Commerce tracking code
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxx']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setDomainName', 'basket.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_addTrans',
'1234', // transaction ID - required
'Name',
'123.4' .....
_gaq.push(['_addItem', ...
_gaq.push(['_trackTrans']);..
The really strange thing is, that even the tracking pixel (which is loaded in the iframe to track e-commerce events) seems to be correct
http://stats.g.doubleclick.net/__utm.gif?utmwv=5.4.4dc&....%3Futm_source%3Dnewsletter2%26utm_campaign%3Dcampaign1...
Did i miss something?
Thanks a lot
Try to use the _getLinkerUrl() method to pass the cookies data to the iframe.
_gaq.push(function() {
var pageTracker = _gat._getTrackerByName();
var iframe = document.getElementById('myIFrame');
iframe.src = pageTracker._getLinkerUrl('http://www.my-example-iframecontent.com/');
});
You can find full details here --> Tracking Across iFrames
... and here --> Tracking Across Multiple Domains and Sub-domains
Hope it helps.

Event tracking not working

I am trying to integrate the Google's event tracking on my application using the below script. I can able to see the Events in "Realtime" tab. But I am not able to see the events in "Content" tab.
var _gaq = _gaq || [];
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAccount', 'XXXXX']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackEvent', 'request.fullpath', 'plan_desc', 'plan_code>']);
Are you grabbing the script that defines the gaq function?
var _gaq = _gaq || [];
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAccount', 'XXXXX']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackEvent', 'request.fullpath', 'plan_desc', 'plan_code>']);
(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);
})();
Also, for your event push, are the values you are pushing in supposed to be JS objects? if so, you may want to get rid of the quotation marks.
GA takes a certain amount of time before it translates data that you see in real-time into it's other sections.
It might be that if you have only added the code within 48 hours that results are not ready to view yet.
I would suggest you trying Google Analytics Debugger extension for Chrome to see if tracking events reach google.
https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en
If you are trying to use Rails variables in the JS, as request.fullpath looks like one you must make sure you are rendering it out in your templating engine. For example, if you are using ERB, you must call it like this...
_gaq.push(['_trackEvent', '<%= request.fullpath %>', 'plan_desc', 'plan_code>']);
Obviously repeat for the other variables, if they aren't Ruby and are plain JS objects, you need to omit the quote marks around them.

setting up google analytics for an all-ajax site

i call trackpageview within the onstatechange callback (which i checked is being called), because in an all-ajax site, the states are the pages.
History.Adapter.bind(window, 'statechange', function() {
_gaq.push([ '_trackPageview', History.getState().url ]);
}
i also have the necessary snippet in the (again, which is only ever called once, because this site is all-ajax).
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-31081343-1']);
_gaq.push(['_trackPageview']);
(function() { ... })();
</script>
however, i do not see these pageviews on my google analytics account, neither in 'standard reporting' nor in the 'realtime'.
why aren't these pageviews being tracked?
(I assume you use History.js)
History.getState().url return the complete URL, begining with the protocol (http://...).
When using pageURL parameter with _trackPageview, you must use a beginning slash (/) to indicate the page URL (cf doc). Otherwise the request will not be taken into account by Google Analytics.

Resources