setting-up cross-domain tracking

Setting Up Cross-Domain Tracking: Manual Approach

Google Analytics 4

Tracking user interactions across multiple domains is essential for understanding how users are moving through your online presence and where they are dropping off. Google Analytics 4 (GA4) offers a powerful way to do this, but setting up cross-domain tracking manually can be tricky, especially if you're not a web developer or analytics expert.

We'll walk you through the step-by-step process of setting up GA4 cross-domain tracking manually. We'll break down the technical aspects and provide clear instructions on what to do. Come on let’s dive right into it - here are the steps:

The  manual setup is done by using the get and set commands of the gtag.js API to store IDs across domains. If you want to learn more, you can check out  this documentation.

Step 1: Retrieving the client ID on the source domain, here, you can use the get method:

gtag('get', 'TAG_ID', 'client_id', (client_id) => {
  // Store the client ID in a variable.
});
gtag('get', 'TAG_ID', 'session_id', (session_id) => {
  // Store the session ID in a variable.
});

Step 2: Adding the client and session IDs to the link that points to the destination domain. 

<a href="https://example.com/?clientId=XXXXX&sessionId=YYYYY">example.com</a>

Step 3: Read the IDs from the URL and set them with the config command: 

gtag('config','TAG_ID', {
'client_id': getClientIdFromUrl(),
'session_id': getSessionIdFromUrl()
});

Once you've completed the steps above, be sure to test your setup to ensure that cross-domain tracking is working properly. To do this, check the URL of the destination domain to make sure the _gl parameter is present.

What are the next steps:

We believe you can gain more knowledge, and here are some resources (Blog Posts) to help you continue learning:

We're always looking for ways to improve our Resources page content. Please share your feedback so we can make it even better.