Google Analytics and Google Tag Manager have previously published articles on domain management, including Web Domain Tracking for Universal Analytics and Google Analytics Multi-Domain Setup.
Over the past period, numerous changes have occurred. One of the most significant developments was the official launch of GA4—the analytics platform we’ve known as App + Web. What was previously available only in beta form has now been officially released with the option to upgrade via Google Analytics. Our clients (those managing both applications and websites) have also begun planning their implementation processes. Another key development is that integrations have increasingly been integrated into web and application management platforms. Instead of relying on comprehensive content management systems, many scenarios now involve using a variety of specialized services together.
For example, you can create your website using Webflow and then link your application to your website via a subdomain (subdomain), manage your forms using form and survey tools like Typeform,, and manage your landing pages using Unbounce. Naturally, during this entire process, transitions between different domains (cross-domain) and subdomains can occur. In such cases, various issues related to ad performance and website traffic may also arise.
In my previous articles, I included a description of the ga (analytics.js) library. In this article, I will directly discuss the Global Site Tag (gtag), UA/GA4 versions, and the configuration and reporting settings of Google Tag Manager.
First, let’s take a step back to understand the underlying reasons behind these changes.
Google Analytics Reports and Domain Management
When you install Google Analytics, you’ll be asked to enter a domain name. This represents the foundation of property creation. In short, each domain definition is a Google Analytics property (Property ID) — for example, UA-1234567-89, 123456789, etc.
The Page definitions listed under Behavior > Site Content > All Pages correspond to pages under this domain. Don’t forget to add that the domain is defined by the Hostname, while pages are defined by the Request URI.
Google Analytics collects a client ID value each time a session is initiated by a user (session), (see Audience > User Explorer) and stores this value as a cookie on the device where the session took place. 1 This cookie uses a unique customer identifier to determine whether a user is a new visitor or a returning visitor. If a hit has already been sent to a client ID that matches the same property, the user is considered a returning visitor (see Audience > Behavior > New vs Returning). Because cookies are tied to a domain, they are not accessible from other domains.
For a complete and more effective measurement of customer journeys, sessions must be linked across multiple domains. To achieve this linking, the client ID value must be passed from one domain to another. The Google Analytics site tracking code appends a parameter to the URL that includes the user’s identity, the linking parameter, the current timestamp, and browser metadata.
The linking parameter resembles: _ga=1.199239214.1624002396.1440697407
This parameter enables Google Analytics to associate sessions across different domain names using the client ID. As a result, you can identify target web properties or properties by client ID and merge sessions from different domain names belonging to the same user. If cross-domain tracking is performed across multiple top-level domains, a change must be made in the Google Analytics tracking code for each domain.
When a user’s session transitions from your primary (source) domain to your secondary (target) domain, Google Analytics treats this as a referral — a user referred from your primary domain to your secondary domain — and creates a new session. To treat user interactions across multiple domains as a single session, you must add the domain(s) that are being redirected to the referral exclusion list (Property > Tracking Info > Referral Exclusion List)2.
For example, suppose a user visits your corporate website (primary domain) and then navigates to another site hosting your products (secondary domain), before returning to your corporate website. If the secondary domain’s URL is not excluded from the referral exclusion list, two sessions will be recorded — one for each visit — to the primary domain. However, if you exclude the redirects to the secondary domain, the second visit to the primary domain will not trigger a new session and will be counted as a single session only.
When using cross-domain tracking (site-to-site tracking) along with the referral exclusion feature, a user’s interactions across multiple domains will be counted as a single session, and no additional sessions will be triggered2.
When Analytics is first created, the web property is automatically added to the referral exclusion list. Therefore, if you have a web property with multiple subdomains, it will not detect any redirects it makes itself.
IMPORTANT RULES:
- Maintain the original formatting (markdown, HTML tags, links, etc.)
- Keep technical terms and proper nouns as appropriate
- Preserve code blocks and technical syntax exactly
- Maintain the same tone and style
- Only output the translated text, no explanations or comments
If a user navigates from one subdomain of your site (e.g. app.alanadi.com) to another (e.g. alanadi.com), and this subdomain is neither excluded nor deleted from the exclusion list, Analytics will treat this as a redirect originating from a primary domain and will initiate a new session. As a result, the session reports will show artificially inflated session counts.
The redirect exclusion list uses contains matching. For example, if you enter example.com, traffic from sales.example.com will also be excluded because it contains the domain example.com2.
Primary (Source) Domain
The primary domain refers to the domain associated with the Google Analytics property.
Secondary (Destination) Domain
The secondary domain refers to the domain where traffic originates from the primary domain and is associated with another Google Analytics property.
Both domains are primarily designated as primary or secondary depending on whether traffic originates from or is directed to them. Therefore, the domain-to-domain mapping should be performed accordingly. This mapping process is referred to as site linking3. Let me illustrate this with an example.
GA4 and Site Linking
When the linker parameter includes a domains value in the target domain, gtag.js checks the linking parameters in the URL. If a linking parameter is present and valid, gtag.js extracts and stores the client ID from the parameter. This enables the activation of cross-domain measurement (site linking) by automatically and manually appending the linking parameter to URLs in page links and forms4.
Let’s now walk through the example process. Assume that both our primary and secondary (and possibly other) sites have the Google Analytics snippet included. In this case, we must add domain mappings to both snippets.
Final reminder: the site linking parameter has a 2-minute validity period. After this time expires, no linking will be performed. Similarly, since the linking parameter’s validity period has expired, you cannot manually use this parameter either. Additionally, the relevant parameter is associated with the click event through the connection. That is, when you inspect the source code of the page, you will not see the linking parameter in the URLs.
One-Way Between-Section Measurement
There may be situations where we cannot perform the linking operations we previously discussed, which are meant to automatically establish relationships between sections. To address such cases, the gtag.js for the target section can be configured so that it can select the linking parameter from the URL where the visitor arrived. For this purpose, we enable the accept_incoming key.
gtag('config', 'GA_MEASUREMENT_ID', {
'linker': {
'accept_incoming': true
}
});
// Alternatively, without a config definition
gtag('set', 'linker', {
'accept_incoming': true
});
However, remember: one-way between-section measurement occurs only when a user flow moves from one section to another. Since there may be different transitions between section names, it is essential to approach the situation as much as possible based on a two-way cross-sectional measurement5.
Two-Way Between-Section Measurement
Let’s assume our primary section’s ID value is GA_MEASUREMENT_ID_1, and our section name is example.com.
Let’s also assume our secondary section’s ID value is GA_MEASUREMENT_ID_2, and our section name is example-store.com.
GA snippet for the primary section:
gtag('config', 'GA_MEASUREMENT_ID_1', {
'linker': {
'domains': ['example-store.com']
}
});
Thanks to this addition, the snippet will append the linker parameter to all links on the page that point to the target domain example-store.com.
GA snippet for the secondary section:
gtag('config', 'GA_MEASUREMENT_ID_2', {
'linker': {
'domains': ['example.com']
}
});
As observed, we have ensured that our parameters are included for the linker definition, which points to the name of another field within each snippet.
Using a Single Snippet Across All Fields
To further simplify the bi-directional measurement between fields, you can list all possible fields you intend to analyze under the domains property, and we can then add this code to all relevant websites. This ensures that we do not overlook any field name or make a spelling error. If the field name is not a subdomain, we will need to add new field names to the domains object key for each field name5.
gtag('config', 'GA_MEASUREMENT_ID_2', {
'linker': {
'domains': ['example.com', 'newdomain.com', 'secondwebsite.com', '...'],
}
});
Form Handling
If we are using forms that point to a secondary destination (rather than a URL link) — if such a destination is defined as an action — we can enable form submissions to also receive parameters via decorate_forms5.
For example, if our form is sending data from a primary field to a secondary field:
gtag('config', 'GA_MEASUREMENT_ID_2', {
'linker': {
'domains': ['example.com', 'newdomain.com', 'secondwebsite.com', '...'],
'decorate_forms': true
}
});
// Alternatively, without a config definition
gtag('set', 'linker', {
'decorate_forms': true
});
Special Cases
In certain situations, a query parameter (i.e., the question mark ?) in the URL may need to be replaced with a fragment delimiter (i.e., the hashtag symbol #). For example: https://example.com#_ga=1.199239214.1624002396.1440697407. For such cases, gtm.js provides us with the url_position parameter5.
gtag('config', 'GA_MEASUREMENT_ID_2', {
'linker': {
'domains': ['example.com', 'newdomain.com', 'secondwebsite.com', '...'],
'url_position': 'fragment'
}
});
// Alternatively, without a config definition
gtag('set', 'linker', {
'url_position': 'fragment'
});
Google Tag Manager
Google Tag Manager makes many tasks easier. Cookie sharing is one of those features. All topics related to GA UA and GA4 also apply to GTM. It is not mandatory to specify a domain name as the container name during GTM setup. Therefore, you can use the same GTM container across many different websites and ensure that the relevant codes run under the desired domain name, based on the Page Hostname (or Page URL).
If you’re managing multiple GA codes within the same GTM container, you can create a Hardcoded Variable that includes all the domain names, or a Data Layer Variable if you need to retrieve this information from a web page or app. Of course, you should keep in mind the rules I’ve outlined under the dataLayer section. My recommendation is to manage domain names as hardcoded variables to minimize potential issues.
Regardless of the path you take, our goal remains the same: when adding a new domain or modifying existing ones, instead of updating all the codes, simply update the content of the relevant variable.
GTM - GA Domain Configuration
Now we can adjust the Google Analytics tags that will share cookies within our GTM container. These adjustments are made through the Google Analytics Settings.
We can access the variable configuration screen by clicking on (I). Similarly, we can also reach the relevant Google Analytics Settings section from the Variables section. This way, we can apply the same settings across all our Google Analytics tags for different UA IDs.
Our tracking ID is expressed here. Since we’re using these settings as a template, we can also reference the ID value as a variable. This way, we can assign a value to the variable either from our web page or application as needed. The most important settings are the Cookie Field, allowLinker, cookieDomain, and Cross-Domain Tracking settings.
Cookie Field
: By setting the auto (automatic) value for the Cookie Field, Google Analytics automatically determines the best cookie (_ga) field to use6.
Field: allowLinker
: I previously mentioned the linker parameter in the gtag.js snippet. When we set the value to true, we instruct Google Analytics to check for the linker parameter in the URL (_ga).
Field: cookieDomain
: Provides domain management for cookie settings7. As I mentioned earlier, we can store domain names as variables. In this case, we only need to call the variable. Otherwise, we must enter the domain names separated by commas in this field.
Automatically Link Domains
: Just as we specify in the linker parameter, we enter the relevant domain names in this field to enable automatic cross-domain tracking. If we’re storing the domain names as variables, we simply call the variable; otherwise, we must enter the domain names separated by commas.
Use the Square Indicator as a Boundary
When the _ga parameter in the URL is passed via a fragment instead of a question mark, it returns the true value.
Enable Form Integration – If domain name operations occur not only through URLs but also via forms, the relevant parameter will be sent through the form, and thus it returns the true value.
You may refer to the above-mentioned Exception Cases section for more details on these two topics.
Reporting
Now that we’ve configured all our settings, we can examine how to track these changes through reports.
Under normal circumstances, any Analytics property—regardless of which web property it’s associated with—will display the page address under the Page dimension. That is, for a page with the URL example.com/page-slug, the report will only provide us with the /page-slug portion. As previously mentioned under the Google Analytics Reports and Domain Management section, we can also access this data via the Request URI dimension. Additionally, we can include the Hostname option as a secondary dimension in our reports.
However, in certain situations, we may wish for the domain name to appear within the Page dimension as well. For example, default index pages such as index.php often reflect as / within the Page field, or the same page path may exist under different domain names. In such cases, if we do not include Hostname as a secondary dimension in the report, we may not be able to differentiate between pages. One solution is to use View filters. With these filters, we can ensure that our Page definitions are structured as example.com/page-slug.
Remember, filters become active immediately upon creation and affect the data in the order in which they are created.
Field A -> Extract A
: Extracts the domain name (e.g., exaple.com) and makes it accessible via $A1.
Field B -> Extract B
: Extracts the page URI (e.g. /page-slug) and makes it accessible via $B1.
Output To -> Constructor
: Provides the field name and page path together as the page value via $A1$B1.
The particularly important option among the choices is Override Output Field. This option allows the previous value of the filter output to be changed. You may also refer to my earlier article titled Displaying the Full Page URL in Reports.
That’s all for the operations. The page size field name will now appear in the reports. You can access page information related to UA through the Behavior > Site Content > All Pages report.
Footnotes
- Cookies and user identification with gtag.js. Universal Analytics (gtag.js) ↩
- Excluded redirects. Analytics Help ↩ ↩2 ↩3
- Cross-domain tracking. Analytics Help ↩
- Set up cross-domain tracking (analytics.js) ↩
- Measure activity across domains. Universal Analytics (gtag.js) ↩ ↩2 ↩3 ↩4
- Automatic Cookie Domain Configuration. Google Analytics ↩
- Configuring cookie field settings. Google Analytics ↩