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.
Related
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?
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.
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']);
I made a small little Tic Tac Toe game that plays perfectly at http://tic.cwoebker.com.
The actual tic tac toe game is loaded from (/tic) and embedded in an iframe.
Therefore others could easily embed the game on their own site if they wanted.
I am doing some event tracking inside of the iframe.
Right now I have it setup so it fires a page view on both the main page
and the actual game code inside the iframe.
I was wondering whether I could somehow only fire the page view for the iframe if its not
embedded on http://tic.cwoebker.com but on another site.
So that everything thats tracked under root (/) is traffic on my site and everything tracked in the i frame (/tic) traffic generated by embedding on another site.
Right now my analytics code in the iframe looks like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxxx-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>
Thanks a lot in advance.
As you're in an iFrame on a separate domain, you can't access the parent window to get the location. Check out this demo and/or google it a bit: http://jsfiddle.net/TomFuertes/RRB52/2/
_gaq.push(['tictactoe._setAccount', 'UA-xxxxxxxxx-x']);
// Line below causes security issues, thus won't work
_gaq.push(['_setCustomVar', 1, 'Domain', window.parent.location.host, 3]);
_gaq.push(['tictactoe._trackPageview']);
You can pass the domain using a querystring on your iFrame page, you'd need to modify the include code to look like this: https://stackoverflow.com/a/5697801/94668
<script type="text/javascript">
document.write('<iframe src="//tic.cwoebker.com/?url=' + window.location + '"></iframe>');
</script>
Then you'd filter out your Google Analytics appropriately.
You can use Google Analytics campaigns to track the traffic. You will need to distribute the embed code that already has the campaign parameters as part of the embed iframes src.
Hope that helps.
Interested to hear from others.
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.