Cross-domain tracking has been the bane of any analyst’s experience for, oh, just about ever. It is probably the hardest thing to get right in a Google Analytics implementation, and in our experience, more people ask us for help with this one issue than any other.

Over the years we’ve dealt with this problem in different ways. jQuery made it easy to drop in a couple lines of code to track behavior across domains, but even then it wasn’t exactly automatic.

Then along came Universal Analytics and Google Tag Manager – the perfect 1-2 punch combo to knock out cross domain tracking once and for all. We held a webinar to show people step-by-step how to implement cross-domain tracking in Google Tag Manager. Below is a recording of the webinar, along with the written step-by-step instructions.

*NOTE: Since the webinar, there have been some updates to Google Tag Manager and Universal Analytics that make cross domain tracking even easier and more intuitive. If you follow the directions in the webinar, it will still work. But the written instructions below are up to date with the newest features.

Step-By-Step Instructions – Universal Analytics

The following instructions will guide you to setting up cross-domain tracking through Google Tag Manager with Universal Analytics.

Create the following macros

1. uaid

* For the value, replace the Xs and Yx above with your UA number.

2. cross domains

3. element url (if you don’t already have it)

Tagging cross-domain links

Create a tag for your Universal Analytics tracker (I recommend naming it Google Analytics – Universal). The Track Type for this tag should be Page View. If you already have a tag for Universal Analytics, modify it to match the following settings:

1. For Tracking ID, use your uaid macro

2. Under More Settings > Cookie Configuration, set the value of Cookie Domain to auto.

* This step has changed since the webinar was recorded. In the webinar we say to create and use a {{top level domain}} macro for the Cookie Domain value. Now you can simply use auto, as pictured above.

3. Under More Settings > Cross Domain Tracking, set the value of Auto Link Domains to your cross domains macro, and set the Allow Linker drop down menu to True.

* This step has changed since the webinar was recorded. You used to have to go into Fields to Set, and add a Field Name of allowLinker with a value of true. Now you can just use the drop down menu pictured above.

4. Set the firing rule for this tag to All pages.

Tagging cross-domain forms

1. Create tag – name it Form Submit

2. Create tag – name it Cross-Domain – Forms

A. Create a copy of your Google Analytics – Universal tag. To do this, click on your Google Analytics – Universal tag and scroll to the bottom. In the lower right corner, click on the Copy this tag button.

B. Name your new copy Cross-Domain – Forms.

C. Change the Track Type to Decorate Form.

D. Remove the All pages rule and add the following 2 rules (which you will need to create):

Jim Gianoglio is a Manager for the Analytics & Insight department. He works with implementation, analysis and training of Google Analytics and Google Tag Manager. Before focusing on analytics, he led the SEO campaigns of Fortune 500 companies in the insurance, retail and CPG industries. Things you didn’t know about Jim: he’s biked from Pittsburgh to Washington DC in 41 hours, roasts coffee beans and has done voiceovers for TV commercials.

This implementation does take advantage of the autolink feature (through GTM). That’s why we don’t have to use a “Decorate Link” tag – just a “Decorate Form” tag. The link tagging is all done through the standard “Page View” tag with auto link features enabled through the More Settings > Cross Domain Tracking settings.

The form submit auto event listener will work regardless of whether your form uses POST or GET.

There are some edge cases we’ve seen where the form submit auto event listener doesn’t work (or can prevent your form from successfully submitting), but it’s not due to the method (POST/GET) you use to submit the form.

This is possible. You’d basically need to modify the uaid macro from the webinar/instructions above. Instead of using a Constant String type macro, you’d use a Custom JavaScript macro, with the return value being a web property ID based on either the hostname (if it’s a.com or b.com) or based on the referrer (if you’re on c.com).

*Please test before implementing on a live site – this is merely provided as a possible solution (and was written rather quickly, so there may be typos!).

This assumes that a.com and b.com are two completely separate sites that never link to each other (otherwise if a user clicked on a link from a.com to b.com, the wrong UA# would fire). It also assumes that the only way to get to c.com is from either a.com or b.com. If it is different, then the last else statement will at least catch those visits into a different account (useful for troubleshooting).

@Gerard – If you’re using “classic” Google Analytics, the main changes are that you need to decorate your links in addition to decorating your forms. With Universal, the functionality to decorate the links is built into the standard tracking with the autoLink plugin (in GTM, this is set under More Settings > Cross Domain Tracking > Auto Link Domains).

So for classic GA, you’d have an additional tag to listen for clicks on links (using the auto event listener), and another tag that would decorate those links if they went to the other domain. Your rules for this tag would be similar to the rules for the Cross-Domain – Forms tag.

Thanks for the excellent blog post! I have a scenario where my main domain is on https site and the contact forms are on a third party http domain. I am trying to record the {{referrer}} in a form submit event, but seems to be stripping out the referrer info. Would your configuration listed above solve this issue?

If you’re sending someone from your form (on http) to your main site (different domain, on https) then the referrer should still be sent. It’s usually only the other way around (going from https to http) that the referrer request header is not sent.

Is the problem that you have your http form iFramed on the https page? In that case, the referrer for the form would be blank.

If that is the case, then the instructions in this post will not save you 🙁

There are some edge cases that can prevent the linker parameters from being added (especially with forms), and without knowing your specifics it’s hard to say exactly why they’re not being added.

Having two sets of code – one through GTM and one manually added – will only make troubleshooting the issue more difficult, as well as lead to other issues.

I’d recommend consolidating everything in GTM and then troubleshooting from there.

Nick

Thanks Jim for posting this. I have everything working – the info is passing along in the url parameters and the visitor persists across one domain to another (so the cross-domain kicks in when a link goes to another domain) but the source is somehow not making it across. Instead it’s a self-referall (or source=domainA.com instead of say yahoo.com).

Any clues as to what this might indicate?

Thanks in advance for any info.

Nick

difeep

Hi Jim, thanks for the awesome write up. I am assuming the debugger should return Running command: ga(gtmXXXXXXX.linker:autoLink, siteA.com,siteB.com, true, true) however, with my test, ga(gtmXXXXXXX.linker:autoLink, siteA.com,siteB.com, false, false) I only ever get false as the value.

Both domains are using the the gtm code and GA profile id.

Any thoughts as to why linking between the 2 different domains still fails to pass the cookie details?

@Nick – Do you have your own sites listed in the referral exclusion list? Look in the Admin, under the Property > Tracking Info > Referral Exclusion List. You should see your sites listed there. If they’re not, go ahead and add them.

@difeep – The boolean values at the end of that command refer to the settings you have in GTM for your Universal Analytics pageview tracking tag. Under More Settings > Advanced Configuration > Cross Domain Tracking, you can set the Auto Link Domains, Use Hash (true/false), Decorate Forms (true/false) and Allow Linker (true/false).

The “false, false” you’re seeing in the command refer to the Use Hash setting (the first false) and the Decorate Forms setting (the second false). In the webinar (and instructions in the post above) I showed how to set up tags for tracking form submits and and doing the necessary form decorations to pass the cookie. Of course, the awesome team working on GTM has since made it much simpler (by using the “true” setting for the Decorate Forms dropdown).

If you’re not seeing the cookie pass back and forth, there could be a number of reasoons (AJAX forms, links that redirect, etc.). It’s hard to say without digging in deep to your site.

Syed

Hi Jim, Many thanks for posting this useful information for us. I would like to link 5 domains for cross domain reporting. So I was wondering if I need to add 4 other sites using RegeX on the element URL field for 2.D.i And 2.D.ii like below:

Thanks for this comprehensive method. I have a question that the Google forums were not able to respond and I wondered if you may be able to help me.

We have 2 websites that use the same payment area, situated in the subdomain of siteA.com. SiteA.com has it’s own GA Profile and SiteB.com has it’s own too. We want top track them independently and be able to see how much traffic they send one an other. So we can’t add them to the referral exclusion list.

Currently in the payment area we have 1 pageview tag for each profile and 1 ecommerce transaction tag for each profile too. The problem we are experiencing is that a new session is being started each time traffic is sent from siteB.com to the payment area instead of just continuing the initial session. As a result siteA.com is showing as the referral and the real pages from SiteB.com never show up in the reports as the landing page.

Any help or ideas will be greatly appreciated.

Julian

Hi Jim,

I’ll much appreciate if you could post a quick pdf guide or update your post on cross-domain tracking with classic GA. Just for the dinosaures like me :/

Great video and thanks for all the tips with GTM.

Julian

Petros

Thank you for this post and the associated work of pulling it together.

I am wondering how cross domain tracking works when you have multiple websites – some of which do not have GTM running at all. I manage 7 sites – all of which are intertwined. 3 have GTM installed. The others have regular async GA and one is still running Urchin!

I am assuming that each site is treated individually — and that I need to get every site on GTM ASAP.

On form submit to siteA.com
On form submit to siteB.com
On form submit to siteC.com
On form submit to siteD.com
On form submit to siteE.com

Each one would be structured like the instructions above. You can’t just include all your domains as a RegEx for the element URL field. If you did it that way, you could potentially have a form post back to the same domain and it would trigger the cross domain form decoration which could cause some issues.

There may be some configurations that aren’t set up correctly – especially since you’re using two trackers on the payment page/site. Are you using named trackers?

Petros

@Jim: That is what I assumed – and am working towards. At least I can set it up on sites that are running GTM. I am going to “hold out” and not succumb to political pressure for the others – especially the one running Urchin!

PS Please implement a comment subscription plugin on this site. You have enough comments to make a business case for it – IMHO 😉

Petros

Silly question @Jim. Is best practice to have a separate GTM container for each domain? Or can this be done using one container for all domains?

thanks for the video guide.
I have 1 question.
I am setting up GA for company where I work and we are going to have a lot of domains.
Example: domain1.eu, domain1.de, domain1.fr …, domain2.eu, domain2.de, domain.fr… and so on (different country different domain for our set of webpages)

Will your guide work on example like above? Do I need to add just the .eu domains in the cross domain macro or do I have to add all of the possible combinations of domains?

Thanks for the great tutorial – I got stuck in just one place – and this has been reworked in any event for the cookie config – using auto works fine – but just a quick heads up for anyone struggling as I did using the script to which you link on the video – this basically takes the dot and takes the domain around that… so subdomain.example.com becomes example.com
My situation was on example.com.au – so the script was returning com.au – which the system then rejected….
As I mention above, using “auto” as the value seems to fix the issue.

That _ga parameter is how GA passes the cookie information for the visitor from one domain to the next – which is absolutely necessary for cross domain tracking to work.

Keep in mind, it will only be there on the first page after clicking from one domain to the next (it doesn’t get added to the URL for every page).

Evan

I have a situation where GA is not understanding a URL Percent-encoding so I can track multiple domains between my “source” domain and my “destination” domain. I’m using Google Tag Manager + the new Universal Analytics.

Is there a macro or rule in google tag manager that I can create to help Google Analytics detect these two URL Percent-encoding as %2526 for & and %253d for = appropriately? If so, is there any support that could be provided with this issue I’m experiencing?

As you can see close to the tail end of URL contains my _ga cookie that originated from my “source” domain and is getting passed to my “destination” domain. This is a good thing, however GA is not able to read it, because of the URL Percent-encoding shown below:

%2526_ga%253d1.244536837.1471787898.1397850931

%2526 is a URL encode for &

%253d is a URL encode for =

Since google analytics is not able to translate the URL Percent-encoding %2526 and %253d it writes a brand new cookie instead when I look at my cookies when I debug using firebug > cookies tab.

Thank you for the help in advance!

Evan

Evan

I figured out a work around to my challenge (above) by writing some custom JS to look for the percent encoding in the URL and then append the entire cookie again to the URL this time with the proper &_ga= and the cross domain cookie. I was able to do this, because the cross domain cookie was already in the URL fortunately, but GA just couldn’t translate “%2526_ga%253d” as “&_ga=” which it now works perfectly with this script. However, it would be even better if GA could translate percent encoding in the URL without going to such length. Just a thought…

note: with the regex on line 1, you would change it to match your own URL encoding issue.

1. Do you have the sites added to your Referral Exclusion List in Google Analytics? (This is the final step listed in the blog post)

2. For your cross domains macro (where you list your site names) are you using just the domain? Or the full domain (including subdomain)? It should be set to:
myothersite.co.uk, mysite.co.uk

not:
myothersite.co.uk, bookings.mysite.co.uk

Also, there may be users whose source/medium was attributed to the self referral before you implemented cross domain tracking, and they keep coming back directly (direct navigation or bookmark). In this case, they will continue to show up as self referrals, because direct never overwrites existing source information.

Mike

Hi Jim,

1 Yes I have but as subdomains ie bookings.mysite.co.uk so have left as mysite.co.uk for now.

2 Ah! Had all the subdomains set so have now removed these and set to mysite.co.uk

Will give it a go!

samshare

Hi Jim,
Thanks your Post. but i have question need you help. there is ” Cross-Domain – Forms Not fired”
Can you tell me the way i can fix it.

Hello,
I want to track ecommerce data of my site. We are using dpd.com for product information and cart. And we are using paypal for payment. Now GA will track when payment is successfully completed. I have enabled Ecommerce on GoogleAnalytics. And its working fine. The problem is when some one lands on our site through other medium, GA is not tracking that medium. Its giving our site name as medium.

I am having the same tracking issue Sneha is having. What I also noticed on my site is that the cross domain cookie (_ga=) would reset after the initial landing page. Any help you could provide here would be greatly appreciated.

@Jim Wow 10/10 for replying & effort! Best posting on Cross domain & GTM
@Marcus asked a good question, if I’m mostly cross sub.domain tracking do I just keep the {{cross domains}} to the one domain? zdomain.ca ? or 1.zdomain.ca & 2.zdomain.ca and all using the same UA-XXXX and with GTM.
Each subdomain has its own GTM container in order to keep it clean.
If I’m sending traffic from zdomain.ca > 1.zdomain.ca > 2.zdomain.ca Where should I be adding these steps? All three containers? Or just on zdomain.ca?
Sadly do have a couple old classic GA sites with GTM but, can you point to an example / blog post that shows the old way of link decorator?
Ps this has been more helpful than the google forum.

In your case, you’re not doing cross-domain tracking, just subdomain tracking. Since the users stay on the same domain, you don’t have to pass their cookies with them (since the cookies written from 1.zdomain.ca can be read by 2.zdomain.ca).

The only thing you need to do is make sure the cookies are being set to the highest level domain (in your example, this would be zdomain.ca).

To do this with Universal Analytics and GTM, you can go into your Google Analytics tags and set the cookie configuration (under More Settings > Cookie Configuration). In the Cookie Domain field, type in “auto” (without the quotes). This sets the cookie to the highest level domain automatically.

For Classic GA in GTM, this same setting is under More Settings > Domains and Directories > Domain Name. For this, you can’t just type in “auto”. You need to type in the highest level domain (i.e. zdomain.ca).

This takes care of maintaining the cookie whenever a user goes from your main domain to a subdomain to any other subdomain.

Just be sure to do this in all your analytics tags in all your containers.

Unfortunately, It’s hard to diagnose your specific issues without more information. There are a lot of things that can make cross domain tracking go awry, and without looking at your specific sites it’s hard to say what’s causing the problems.

Do you recommend using 1 container for multiple subdomains if each site at times will be analyzed independent from others?

For simplicity we would love to have just one container/snippet. However, we are concerned about what the data will look like if we need to audit website marketing performance one day, and then analyze how clients are using the software on a subdomain the other. Google talks about setting up filters and views, but I am hesitant to make changes and then found out it isn’t what we wanted.

Thanks

Anto777

Dear Sir Madam,

Thank you for the amazing post!

What about the situation with multiple GA properties that each has a GTM container, is it possible to create an additional (Global) GA property and set all GTM containers to send all data additionally to the global property. At the moment we have additional specific tags that within each container that link to the global property id.

@Zach –
You can use a single Google Tag Manager container on all domains, but still track them in separate Google Analtyics Web Properties. Just use a lookup table macro to return the correct Web Property ID (UA-12345-1, etc.) based on the hostname.

@Anto777
Yes – rollup trackers are fairly common. You just need to include the GA tag for the rollup Web Property in all of your containers.

I have a problem with my tag manager tag that fires on the success page of my site. The data layer and everything works perf, but in Norway customers are re-directed to the acquirers payment site to confirm their payment, and when confirmed are re-directed back to our success page. The problem then are that when my universal analytics success page tag are firing, then the source of the customers session are re-set to the acquirers URL as a referral. Any clue how to avoid resetting the source of the customers session?

Universal Analytics works differently than “classic” Google Analytics when it comes to referrals. In the classic version, if the session hasn’t time out (30 minutes since the last interaction) referrals are ignored. So in your example, if users in Norway are taken off the site to confirm payment, then brought back to the site for the success page, that third-party payment site is ignored as a referral and does not overwrite the source/medium of the existing session.

With Universal Analytics, on the other hand, each time the traffic source changes (e.g. coming back to the site from the third-party payment site) it generates a new session with new source information. To fix this, you can add the third-party payment site to the Referral Exclusion List. Here’s the documentation for doing that:https://support.google.com/analytics/answer/2795830?hl=en

We use a form system called Wufoo for some folks, and we embed the forms using javascript. I just received an answer to a ticket I submitted regarding submit handlers from Wufoo, and they’re not too optimistic with regard to google tag manager integration.

I was wondering if there is a workaround for situations like this where the form is embedded via javascript, and the submission passes through a third-party server.

Thanks,

Paul

MacKenzie Rawcliffe

I know you recommend using one container to do cross domain tracking – but if you don’t want to – will the cross domain tracking still work. Do you set it up the same way?

@Paul – if the form is being embedded in an iFrame (with the source of the form coming from wufoo.com) then this will not work. I was playing around with the free version of Wufoo and the options to embed the form would not make it possible to track.

The “JavaScript version” merely included a link to the form (which takes you off the site to the form page on wufoo.com). So that wouldn’t work.

The other option to embed was the iFrame version, which like I mentioned, also won’t work.

Perhaps there are additional options with a paid account that I’m not aware of. But it doesn’t look like this is going to be easy for you – sorry!

Thanks for a great explanation. We’ve included cross domain tracking & whilst this is working in terms of picking up clicks for a campaign, it is not linking in with the goals, instead being picked up as referrals. We have the referral included in the exclusion list so not entirely sure why that’s still occurring as it works well for all other campaigns.

@Ron, we’re experiencing exactly the same problem. At some point we lose all information about the source. I’ve noticed that there are 3 cookies stored: .subdomain.domain.com, subdomain.domain.com (so without dot) and .domain.com. 2 first cookies store no data about the source ( (direct), (referral) or (none)) and this is the third one that stores the right source.

Unfortunately in GA Real Time I see the right source at the beginning, but at some point (randomly or after ~5 minutes of inactivity) the source disappears and shows up as (direct), (referral) or (none).

Hi. Jim, I appreciate your efforts and way you reply all queries by readers, But my situation is bit different, Hi have to websites one is ticketstobangladesh.co.uk and another is ticketstoworld, both are different website, if any user search flights, hotel etc on ttb.co.uk he redirects to flight.ticketstoworld, hotels.ticketstoworld.co.uk and so on, these however pages are different on ttb and ttw.co.uk, So how to manage this situation, right now i want to use GTM only on ttb.com for testing purpose. Thanks in Advance..

Sandeep Kumar

Alexander

Should i delete the old Universal Analytics tag from GTM first and then to insert this cross domain tracking tag? The old UA tag is active at this moment.

Great post! I wanted to ask about the scenario where you want to see original referral source but also if it hit both of your websites.

E.g. if someone came from Display and hit my first website, and then clicked on a link on there to go through to my second site.

Based on your post, if I excluded self-referrals then I could see that the person hitting the second site came originally from display but would I still have sight of the fact they hit my other website first or is that information lost?

Excellent guide, Jim! One question: if I have more than one domain (different languages) and I need cross-domain tracking with my payment system, can I add them all as separate macros to the same tag?

I assume that step 2. Cross-domains should countain, for example: mysite.com, paymentsite.com – Or can I add all the versions of my site right there? I.e.: mysite.com, mysite.fr, mysite.de, paymentsite.com?

Jim Gianoglio

You can add all sites and ccTLD versions of your sites in the same macro/variable.

jevan

Hi, what If I am using different containers for each site and I wanted to do cross domain tracking. Say holttruckcenters.com has its own GTM container and holtcat.com has its own GTM container. How can I do the cross domain setting set up?

Jim Gianoglio

You can still do cross domain tracking, you’ll just need to make sure that your GA tags in both containers are set up the same way. Specifically, they both need to have the allowLinker set to true (you’ll set this in the Fields to Set section in GTM V2), and for the Auto Link Domains field, you’ll just list the opposite domain. For example, in the holttruckcenters.com container, you’ll list holtcat.com in the Auto Link Domains field, and vice versa.

Hi Jim, This is a great post and shows how important after 2 years how many comments you still get. I implemented correctly, but now adding another domain to the Cross Domain macro (variable now) and cannot get it working. Is there any additional steps needed when adding new domains to the cross domains list?

Jim Gianoglio

You should be able to just add the new domain to the Cross Domain variable (and make sure to add it to your Referral Exclusion list in GA).

Real-time reports unfortunately won’t help troubleshoot here, since they use last-click attribution (instead of last non-direct click attribution, as the standard reports use). Check your standard reports to see if your source information stays the same from domain A to domain B.

Other things to check:
Click the link on domain A to go to domain B. When you get to domain B, look at the URL in your web address bar – make sure you see the _ga cookie, and compare this value to your _ga cookie from domain A. They should be the same. If there is no _ga cookie being appended to the end of the URL, then you’ve found the problem!

You have it right – using cross-domain tracking, you’ll see the the person hitting the second site as coming originally from display.

Jim Gianoglio

Real-time reports unfortunately won’t help troubleshoot here, since they use last-click attribution (instead of last non-direct click attribution, as the standard reports use). Check your standard reports to see if your source information stays the same from domain A to domain B.

Other things to check:
Click the link on domain A to go to domain B. When you get to domain B, look at the URL in your web address bar – make sure you see the _ga cookie, and compare this value to your _ga cookie from domain A. They should be the same. If there is no _ga cookie being appended to the end of the URL, then you’ve found the problem!

Also, if you’re seeing multiple cookies being set, then you have some other issues to deal with. You probably have multiple trackers on the page with different cookie domain settings. This introduces additional complexities that you’ll need to consider.

Kelly Swanson

This might have been answered but when doing Cross Domain Tracking to 1 Primary and 1 sub-domain in GA where one authenticates to another, how is the user ID feature implemented in the code on either site in order to maintain 1 user ID for the whole session?

Rutger Meekers

I have the same question. Do you have an answer yet?

andrew.girard

It seems that Tag Manager set up for cross domains has again changed since you last updated this. I actually have a tag set up, and it is tracking page views, but it’s not showing what domain each page view is from. I thought it may be the cookie configuration, but that doesn’t even seem to be an option anymore. Any idea what I may be missing? Any help is much appreciated! Thanks!

Jim Gianoglio

Things have changed a bit with Google Tag Manager V2. We have an updated post that walks you through doing cross-domain tracking in the new version – it should answer your questions:

Thanks, I had actually just found your updated article when your replied! The article from annielytics also helped me to get this figured out. I had to set the filter in GA in order to add the domain in front of the pages. Thanks for your help!