So I have a scenario where I am constantly getting a good number of self-referral traffic to my website. I investigated it further and believe it to be a case of an issue with my cross domain tracking (as I use a 3rd party shopping cart).
What I can't seem to figure out is what I have wrong and why it isn't working. My specific scenario looks like the following
MainSite.com Analytics Code
<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-XXXXX210-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['mainsite.com','checkoutsite.com'], true, true);
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
CheckoutSite.com Analytics Code
<script type="text/javascript">
(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-XXXXX210-1', 'auto', {
'allowLinker': true
});
ga('require', 'ec');
</script>
As for the setup options:
The following domains are added to the exclusion referral list in GA
mainsite.com
checkoutsite.com (the actual checkout is on a subdomain of kiosk.checkoutsite.com but this shouldn't make a difference AFAIK)
mainsite.com 301 redirects to www.mainsite.com
As far as I can tell the 3rd party checkout JS script is adding link decorators as seems to be required Edit: Have confirmed as per the comments below
The links to the checkout cart are Javascript based which result in a iframe popover. They look like the follwing:
<a class="eztixKioskLink tourTemplateId_XXXX" href="javascript:void(0);">
<img alt="" src="http://www.mainsite.com/buy.png" />
</a>
However, I still appear to be getting self-referrals and am completely unable to figure out why. Is there something wrong with my code or my setup? Is there something else I should be looking for?
Any help would be hugely appreciated!
You should be good code wise. You can also exclude those domains as referrers:
https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain#selfreferrals
As you go through the flow yourself do you see #_ga hash's being appended? If not you'll need to reverse engineer the javascript link clicks as the outgoing clicks aren't getting decorated:
https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain#linkerparam
Related
Trying to use the latest google analytics tracking code in a site that uses Barba JS but it will not track past the first page, ie the path of the user, any ideas anybody?
The reason it is only working on the initial page is that the default GA snippet implemented using gtag.js only runs once after load. Since you're using it in a SPA setting, you need to manually re-send the page data when you route. Looking at the barbajs documentation, I think it'll be something like this:
// define a global hook, using afterEnter, but you can adjust to enter, beforeEnter, etc as you see fit.
barba.hooks.afterEnter((data) => {
// this hook will be called for each transitions
//data.current.url is the page path.
gtag('config', 'UA-#######-1', {'page_path': data.current.url});
});
use full code provide with google annalitics
https://developers.google.com/analytics/devguides/collection/analyticsjs/?hl=en
in you JS add
(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-Y', 'auto');
ga('send', 'pageview');
What is the current best-practice to track conversions which happen on another domain?
I have 3 affiliate links, which take users to a multi-page form on another site. The conversion happens when they reach the thank-you page.
Is a destination goal, using the URL of these sites /thank-you page appropriate. I can place a tracking pixel on these sites.
I could create a click event in Analytics and use that as the goal by which to measure conversions, but the user hasn't necessarily converted at that point.
Or is cross-domain tracking needed, such as:
<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-XXXXXX-XX', 'auto',{'allowLinker': true });
ga('linker:autoLink', ['theirdomain1.com', 'theirdomain2.com'], false, true);
ga('require', 'linker');
ga('send', 'pageview');
</script>
Add the following to analytics script on partner site:
ga('create', 'UA-XXXXXXX-X', 'auto',{'allowLinker': true });
ga('require', 'linker');
ga('linker:autoLink', ['mydomain.com'], false, true);
Finally, if I place a tracking pixel on the sites for the /thank-you pages, how will I know the page views originate from referrals from my domain?
Cross-domain tracking would be a better option that you will be able to see where a user gets dropped and also create a goal for this conversion.
The client-id would remain same with cross-domain tracking so you can analyze a user's full journey.
I want to implement Google analytics for an Angular SPA which is currently running in my localhost. I tried to copy the google tracking Js code to each of my view in the Angular SPA. But i don't think it actually worked.
Is this the correct way to implement Google Analytics or whats the correct way?
<div class="background">
<div class="container">
<h2 class="page-title">{{'contact-name' | translate}}</h2>
</div>
</div>
<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-XXXXXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
Don't insert the script in each of your views, instead paste it within your main HTML page.
In addition to Google Analytics you might want to consider using Autotrack and the urlChangeTracker in your SPA
i'm have a simple page http://mellowkids.ru/serv-ga/test.php with only a Google Analytics Universe code:
<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-44059933-1', 'mellowkids.ru');
ga('send', 'pageview');
</script>
In Chrome Developer Tools i can see what analytics.js generate a js query to http://www.google-analytics.com/collect (gif pixel) with some parameters.
Something like this:
curl 'http://www.google-analytics.com/collect?v=1&_v=j16&a=1674396045&t=pageview
&_s=1&dl=http%3A%2F%2Fmellowkids.ru%2Fserv-ga%2Ftest.php&ul=ru&de=UTF-8...
How i can grab this link (curl) and print it in page by echo or something else?
I believe you're going to need a browser (it can be headless one like PhantomJS).
In the case of PhantomJS, through netlog, netsniff or something similar you will be able to capture the GET request you need (i.e. http://www.google-analytics.com/collect?v=1&_v=j16&a=...) and print it wherever you need.
It is the first time i am using the new version of Google Analytics (Universal Analytics), so when i put the below code imediatally before </head> i get blank pages for all my URLs.
Here is the code given by Google:
<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-1234567-89', 'mysite.com');
ga('send', 'pageview');
</script>
Someone knows why it is happening? Seems to be a bug, but i don't know how to solve this.
Based on #Brad comment i detected that PHP Smarty was crashing with Universal Analytics code tracking, so i found this post:
Use {Literal} Smarty Tag to Add Google Analytics Tracking Code to BlogSome Hosted Blogs
And then i did like below and the tracking code works perfectly!
<script>
{literal}
(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-1234567-89', 'mysite.com');
ga('send', 'pageview');
{/literal}
</script>