Cross-domain tracking with Google Analytics 4
Cross-domain tracking is an interesting topic to tackle as it might cause confusion amongst marketers and analysts as to when it is needed and how it actually works. It might get confused with sub-domain tracking as well. In this article, we explore and answer questions around this topic and shed light on some important nuances as well.
Table of Contents
How does Google Analytics track visitors?
Before explaining cross-domain tracking, you first need to understand how Google Analytics tracks visitors. When someone visits your website, GA stores a cookie on their browser called _ga (it’s called a first party cookie because GA, configured on your website, sets the cookie on your behalf). When the visitor navigates to another page on your website (landed on page A and moves to page B afterwards) the value of the cookie will be forwarded to the second page and therefore when GA will be searching for that cookie, it still sees it and sees that it has the same value. In plain English, this is how Google Analytics tracks and recognizes you as a user. However there are some nuances that you need to know as well.
This is a screenshot of my browser’s cookie window (To see what cookies are set on your browser, open the website and then right click — Inspect—Applications(for google chrome browser). Before a user gives consent on a website, no cookie should be placed in your browser for that website (Please refer to our data privacy article). After giving consent many cookies will be set on your browser, including the _ga cookie. And this is what it looks like:
So what we can see here is that the _ga cookie has a value of GA1.1.1500170752.1655839757 and we can also see that the domain that set the cookie is wearekemb.com (first-party cookie).
When you are on the same domain, your _ga cookie will be saved and transferred to every page you visit. However when you switch to a different domain, that cookie is not forwarded to the second domain. Say you have two websites configured, www.website1.com and www.website2.com and both of them belong to the same customer journey of your business (a click from the first website redirects the visitor to the second website):
Unfortunately, the _ga cookie is not shared between two separate domains. And well, that will be a big problem when you analyze the number of users. If cross-domain tracking is not installed, the same user that visited website1, will be counted as a different user when they move to website2. Because domains are not “talking to each other”, the _ga cookie set on the visitor’s browser when they visit the first website will not be shared with the second. Therefore, when the same visitor moves to the second website, GA will start a new session for a new user, and thus counts the same user twice. You might see now why this is a problem. You will see way too many users in your reports, you’ll also see more sessions recorded. Not only that, but in the acquisition reports, you will see “referrals” from website 1 given that the user who moved to website 2 “came from” the first website. And obviously this is not what you want to see. Cross-domain tracking solves this problem.
How does cross domain tracking work?
When you configure cross-domain tracking you are basically linking the two websites to talk and share information with each other. And one very important information that will be shared is the _ga cookie value. So how does this work?
Well, when a visitor is navigating website1, and proceeds to click on the link that moves them to the second website, a special parameter is passed to the URL of website2.Since the two different domains are now linked together, whenever a visitor is moved from one domain to the other, the URL of the second website will “carry” information from the first domain. Google Analytics set up on website2 will then search for that URL parameter (that includes the _ga value from website 1) and update the _ga cookie value to exactly match that of the first website. End result? The same visitor is tracked once.
Distinction between subdomains and cross-domain tracking
Before we continue setting up cross-domain it is absolutely necessary to distinguish between a sub-domain and a different domain. Going back to our example, and taking www.website1.com as our first website, the domain here is website1.com. If through your journey, you have domains such as blog.website1.com or app.website1.com or any other combination that includes the domain “website1.com” those are called subdomains. And you don’t need to set any cross-domain tracking for them.. Fortunately for us, Google Analytics 4 (as well as GA3) catches and tracks those subdomains automatically, since they all belong to the same domain.
However, when you have a completely different domain like website2.com that is when you need to set up cross-domain tracking. When both websites don’t share anything and are different from one another.
REMEMBER, in order for cross-domain tracking to work in GA4, both websites need to be configured using the same GA4 property (same measurement ID)
How to configure cross-domain tracking
In the older version of Google Analytics (UA or GA3) cross-domain tracking needed to be manually configured, either through the code itself, or using Google Tag manager. The new version of analytics (GA4) has really simplified this process, especially for people who don’t possess the technical skills for manual implementation. Let’s check out how we can do this in Google Analytics 4.
As previously mentioned, both websites need to have THE SAME PROPERTY in GA4 or else this won’t work. We head to Admin — Property — Data streams — More tagging settings — Configure your domains
This is where you insert the domains that you want to cross configure, press Save and you are done!
We have just explored what is cross-domain tracking, how to configure it, and when to use it. This is an important topic in the Google Analytics 4 sphere as it still causes some confusion or sometimes faulty setups. If you are facing a problem with cross-domain tracking, or any issue related to your web tracking, or data infrastructure setup, don’t worry we got you covered!