how to track traffic across n domains with Google Analytics - google-analytics

Example: I have 3 sites, a.com, b.com, and c.com. How can I keep track of the traffic that starts out at a.com and ends up at c.com, using Tag Manager and Universal Analytics?
I know that using referral source is an easy enough thing to view in UA, but I really need referral referral source because UA only uses the most recent referrer, not a referrer n sites back.
Please note that this question is not just about cross-domain tracking, rather keeping track of a site visited before the current referral.

Using GTM
If you use GTM (Google Tag Manager), you must create a permanent variable that contains the domains where your site might go to or be visited from.
Lets call it "myDomains". It would be like this:
myDomains : permanent : "a.com,b.com,c.com" (without quotes)
After this, in your pageViews tags, you'll need to set some fields:
In "more configurations", go to "fields to set" add some fields and set the following properties:
Field Name : Value
allowLinker : true
And, if you use multiple sub-domains, add the following:
cookieDomain : auto
Now, still in the "more configurations", under "Cross Domain Tracking", you will use the variable myDomains (that we created before) on the "Auto Link Domains" as this:
{{myDomains}}
Now you just have to save it and now you can track your multiple domains.
Hard-Coded
If You don't use GTM and insert the tags directly to your source code, then what you need is similar to what we did in GTM:
ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['a.com', 'b.com', 'c.com'] );
Note that just like we did in GTM, we:
set the cookieDomain (implicitaly with "auto")
set the field "allowLinker" true
set the "autoLink" to an array of strings, each one containing one of the domains that will send/receive visitors to/from your site.
Note: if you use the same domain but just diferent levels of sub-domains, you will just need to set the cookieDomain to auto, no need for Cross-Domain.
Further reading
Google guide for this implementation

There is no real way to do this within the GA interface.
What you could do is create a new GA property that all these websites send data to (if you haven't already done so).
Then create a filter for this property that appends the hostname to the request URI. You can learn to so this here in the Google documentation. This will allow you to see the full URL thus allowing you see all websites.
I would then create two custom dimensions: sessionId and hitTimeStamp. These can deployed through Google Tag Manager. An article by Simo Ahava found here explains well how to do this.
Using SQL, you will be able to partition page by sessionID and order by hitTimeStamp to give you a view on page flow across each website to c.com.

I do not fully understand your use case, but you can catch the original referrer, store it somewhere (e.g. in a cookie) and then send it e.g. via the url to the following page. Then you catch the query parameter and use it in a set call:
ga('set', 'referrer', '<original referrer>');
ga('send','pageview');
For all hits following the set call GA will record the referrer as the value of ">" which you replace with your captured value.

Related

Cross Domain Tracking with Google Tag Manager across three sites

I have three sites across which I need to track traffic in the same Google Analytics account, with the traffic originating from the first one, passing from the second one, and being converted on the third one.
Site#1 is on domainA.com
Site#2 is on sub1.domainB.com
Site#3 is on sub2.domainB.com
I visit Site#1 (example URL: domainA.com/?utm_source=MySource&utm_medium=MyMedium&utm_campaign=MyCampaign) and I click on the element (button) which takes me to Site#2. The URL then becomes sub1.domainB.com/?_gl=[something]&_ga=[someghing else] which basically indicates that cross domain tracking has been set up correctly, and appears to be working. In Analytics I can see that Source, Medium, and Campaign are the same ones as set in the Site#1 url parameters.
On Site#2 I click on yet another element (a different button) and that takes me to Site#3. That page's url now becomes sub2.domainB.com and there are no CDT url parameters present there, which at first glance seems to be correct, as CDT shouldn't care about subdomains, right?
But then I examine the Google Analytics data, and this is when I get confused; Site#1, and Site#2 both seem to share the same Source, Medium, and Campaign data, as set in the original URL. When I navigate to Site#3 however, and place my order there, I am seeing that the Source, Medium, and Campaign are now (direct), (none), and (none), which indicates that the UTM data is lost somewhere along the way.
My current configuration in GTM is the following:
GTM and Google Analytics fires on all three sites.
Track Type: Page View (Fires on all pages)
Enable overriding settings in this tag (Enabled)
More Settings > Fields to Set > Field Name "allowLinker" : true
More Settings > Fields to Set > Field Name "cookieDomain" : auto
(I've experimented both with and without this field, without much different outcome)
More Settings > Cross Domain Tracking > Auto Link Domains : domainA.com, domainB.com
More Settings > Cross Domain Tracking > Decorate Forms: True
Also, in Google Analytics' Property > JS Tracking Info > Referral Exclusion List, I have both domainA.com, and domainB.com listed there.
What is it that I am missing, that would allow me to make Site#3 be aware of the utm_source, utm_medium, and utm_campaign values when the user eventually converts?

How can I keep my referrer consistent when tracking a subdomain page in a Iframe.

I'm not sure how I should describe my situation and if I'm fully understand it.
Suppose we have a visitor flow that looks like the following:
User arrives, after a google search, at : example.com / referrer is google.com
Clicks to log in: sub.example.com/login.aspx (iframe page) / referrer is example.com
I’ve set the CookieDomain to auto and added example.com to the referral exclusion list. So from what I understand I have the following situation :
the Client ID stay consistant when I'm moving from step 1 to step 2. good !
However I'm concerned with the referrer. I would like to keep my google.com referrer when I'm moving from step one to step two.
How can I do this ?
I think you have two options here. Easy solution is to just look at your traffic sources in Acquisition reports in GA :
https://support.google.com/analytics/answer/1033173?hl=en
If you setup CookieDomain and refferal exlusion list correctly "traffic sources" will give you information you need.
Second option(if you really need to override the reffer) is to:
pass the "refferer" value from your parent page into your iframe. There are several ways how to do it but that's up to you.(e.g. query string or postMessage to iframe)
in your iframe pick this value up and send it to your dataLayer (in example below I name it {{yourValue}} )
then in your GTM you can set "reffer" field in your GA Tag for example:
Let me know if you need more detialed description on how to do it.

Remove all traffic for a specific user agent

Is there a way to exclude, from all properties and all views of Google Analytics, the visitors with a specific user agent?
Note: it's not for spam/bot prevention (I already checked the feature Admin > View settings > Bot filtering > Exclude all hits from known bots and spiders), it's to remove a part of own traffic. I can't use IP filtering because my IP changes all the time, and I use many devices (mobile/desktop/laptop). I also can't use cookies, because often I want to test my website as a random non-logged user. I didn't find anything even after exploring deeply the Analytics UI. Maybe this requires API ?
In the first step you have to get the User Agent into Google Analytics. You can do this with the Tag Manager, by creating a custom Javascipt. This can return the User Agent and you can send it to GA with a custom Dimension or a Event. (It´s also possible to do this without the GTM).
Log in to the Tag Manager and navigate to Variables
Now we have to add a Javascript Variable. The User Agent is stored in the navigator.userAgent property
Now we have to push this data into the Google Analytics Account. We could do this with a custom Dimension or a Event. In this example we take a Event. As Action we send the Page Path - you don´t have to do this, but maybe it´s helpfull later for some reports. As a Trigger we define "All Pages" so the event is fired with every pageview. The User Agent we send as a Event Label.
If you have this information in GA you can add a filter on Account Level (for alle Views and Propertys).
Filter Type = Custom > Select the Event or Dimension > Type the User Agent to exclude.
We can see the User Agent of the Users visited our site now in GA Behavior > Events > Top Events > Search for the Event Category (namend in Tag Manager (in our case "User Agent"))
In the last step we exclude the User Agent from all our Propertys and Views.
Admin > All Filters (In the Account column) > "+ Add Filter" > Filter Type = Custom > Exclude > Select "Event Label" in the Dropdown > specify the User Agent to ignore
Select the Views, there this User Agent should be ignored > DONE
Although this doesn't directly answer the question of how to block a user by user-agent string, it does I think solve the problem of how to remove your own personal traffic from being counted by Google Analytics
Google created a chrome plugin:
Google Analytics Opt-out Add-on (by Google)
https://chrome.google.com/webstore/detail/google-analytics-opt-out/fllaojicojecljbmefodhfapmkghcbnh
(Does require a chromium-based browser and appears you're using firefox but may help other users. Interestingly, there does appear to be a link which will download an xpi extension file if accessed from Firefox, but I'm not too sure about it https://tools.google.com/dlpage/gaoptout )
For Firefox, I believe this one can block Google Analytics traffic:
uBlock Origin
https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/
(Google Tag Manager seemed a bit labyrinthic for me.)
I finally did this:
Use Custom UserAgent String extension (available for FF and Chrome) and set UserAgent to NoTracking (you can do it specifically for certain websites, i.e. your websites only, see options).
Add this in the PHP page, in the Analytics Javascript part:
<?php if ($_SERVER ['HTTP_USER_AGENT'] === 'NoTracking') echo 'if (false)'; ?>
It looks like this:
<script>
<?php if ($_SERVER ['HTTP_USER_AGENT'] === 'MyselfXYZ12') echo 'if (false)'; ?>
(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-xxxxxxx-x', 'auto');
ga('send', 'pageview');
<script>
This will have the effect of disabling the creation of ga object for your traffic only.
NB: I first thought about disabling GA code for my own traffic via Javascript with if (navigator.userAgent == 'NoTracking') but it seems that the UserAgent change thanks to the extension "Custom UserAgent String" has effect only after the page is rendered, which is too late.

When using cookieDomain = auto on the Pageview Tag in Google Tag Manager, does it need to be applied to all Event Tags for cross-domain to work?

I was testing a cross-domain set up (across sub-domains) and noticed that my test campaign was attributed to the order complete page, but not the transaction.
On closer inspection I noticed that all the events and transaction had a different CID to the page view. Checking the browser cookies, two _ga were present (for each sub-domain) but had different values.
Try changing cookie domain to relevant sub-domain instead of "auto". But for this you may want to add separate tags for each sub domain. Should work. But for the visitors who already have two CIDs for parent domain cookie and sub domain cookie, this can still occur until you make a cookie reset.
Thank you.
Just by making cookieDomain auto a user is not tracked b/w sub-domains.
you would have set the allowLinker to true and enter all your domains in the autoLink domain section in cross-domain in the pageview tag
PS: enabling it in the pageview is enough no need to apply it to all events
Hope this helps,
Cheers Analytics ML.

How to track traffic by domain in Google Analytics?

I am using Google Analytics in an embedded form. This form will be placed on various websites, and I want to track the traffic with GA. Creating a new property in GA for each website that embeds the form is not an option. As such, I'm looking to track traffic from all the websites using one GA Tracking ID and segment the data by domain. However, I'm having trouble figuring out how to customize the GA code snippet to do that -- everything I find refers to the old classics GA code and not the new universal code. Can someone please help?
Thanks!
You do not need to customize the code, the domain is tracked automatically in GA in the "hostname" field. Go to your GA admin panel, set up a new view, create an "include" filter and set field to "hostname" and the value to the hostname that you want to track. Repeat for all your domains.
You can create up to 25 views per property.
If you do not need a permanent solution you can track everything to one view and create segments based on the value of the hostname field. Or even more ephemeral, set the secondary dimension to "hostname" in your data tables and use the filter in the upper right of the table to filter by value of the secondary dimension.
Google's official answer is here: https://support.google.com/analytics/answer/1012243?hl=en
by default GA is only showing URI, without hostname. You could follow above link, to add a filter to "include hostname in URI".
this video could be more instructive: https://www.youtube.com/watch?v=tcBg6QfgWR8

Resources