> For the complete documentation index, see [llms.txt](https://docs.adpage.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.adpage.io/faq/google-tag-manager-setup/how-do-you-set-up-tracking-for-multiple-domains-on-the-same-container.md).

# How do you set up tracking for multiple domains on the same container?

If you manage multiple websites, you can choose to use a single Google Tag Manager setup for all of them.

If you manage multiple websites, you can choose to use a single Google Tag Manager setup for all of them. This article explains how to configure server-side tagging for multiple domains within the same GTM container.

### Possible scenarios

<figure><img src="https://2963651437-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5eC7lwaeygB0xx6AOZcE%2Fuploads%2FWVddcLZspztd6W2wFZu4%2Fimage.png?alt=media&amp;token=3ca41703-30c3-40d0-894b-09328725a220" alt=""><figcaption></figcaption></figure>

There are four scenarios in which you work with multiple domains:

1. Multiple websites, each with their own GTM web and GTM server container\
   Each website has its own GTM web container, which sends data to its own server container. This is the most common server-side tagging setup.\
   Example: You manage shop-a.com, shop-b.com and shop-c.com. Each website has its own GTM web container and its own server-side tagging subscription.
2. Multiple websites on the same GTM web container\
   You use one GTM web container for multiple websites. The tracking code is the same on every site, but you want to distinguish between the domains in your tags and configuration.\
   Example: You manage shop-a.com, shop-b.com and shop-c.com and want to use the same GTM web container for all three.
3. Multiple domains on the same GTM server container\
   You have multiple websites, each with its own GTM web container, but all of them send data to the same server container.\
   Example: Several clients each have their own GTM web container, but they all use the same server-side tagging subscription.
4. Multiple domains on the same GTM web and GTM server container\
   You use one GTM web container for multiple websites, and all of them send data to the same server container.\
   Example: You manage shop-a.com, shop-b.com and shop-c.com, use the same GTM web container for all three, and all three share the same server-side tagging subscription.

In scenarios 2, 3 and 4, your configuration needs to be domain-specific, so the right data is sent to the right destinations.

***

### Configuration in the GTM web container

If multiple domains use the same GTM web container, you need a variable that detects the current domain and returns the right value based on it.

#### **Replace constant values with a Lookup Table or RegEx Table variable**

Depending on your situation, you use either a Lookup Table or a RegEx Table variable to split your constant values. Values you’ll typically want to split include your GA4 Measurement ID, your server container URL and your Meta Pixel ID.

To create this variable:

1. Open your GTM web container and go to Variables.
2. Under User-Defined Variables, click New.
3. As Variable Configuration, choose Lookup Table or RegEx Table:

* Choose Lookup Table when the input is always exactly the same. For example, use the Page Hostname variable when the domains differ by domain name: yourdomain.nl and yourdomain.com.
* Choose RegEx Table when the input isn’t always exactly the same. For example, use the Page URL variable when the domains are distinguished by the path after the slash: yourdomain.com/nl and yourdomain.com/de.

4. As Input Variable, select the variable you want to base the distinction on.
5. Click Add Row to set a specific Output for each Input (Lookup Table) or Pattern (RegEx Table).

Examples of splitting your GA4 Measurement ID:

<figure><img src="https://2963651437-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5eC7lwaeygB0xx6AOZcE%2Fuploads%2F6zOHeJ1AdNs0GXqCUrRE%2Fimage.png?alt=media&amp;token=5f5fc023-708b-4865-b7a5-658545f1ad39" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2963651437-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5eC7lwaeygB0xx6AOZcE%2Fuploads%2F95AlIEUMrK3drN4Rje3V%2Fimage.png?alt=media&amp;token=33b8af45-6825-4d07-8494-cbbc4244b531" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
For a RegEx Table variable, make sure to turn off all three options under Advanced Settings \
(Ignore Case, Full Matches Only and Enable Capture Groups and Replace Functionality).
{% endhint %}

***

### Configuration in the GTM server container

If multiple domains send data to the same GTM server container, the server container needs to be able to tell these domains apart.

Replace constant values with a RegEx Table variable

To distinguish between the domains of incoming requests, use a RegEx Table variable. Values you’ll typically want to split include your GA4 Measurement ID, your Google Ads Conversion ID, and your Meta Pixel ID and Conversions API access token.

To create this variable:

1. Open your GTM server container and go to Variables.
2. Under User-Defined Variables, click New.
3. As Variable Configuration, choose Event Data.
4. Enter page\_location as the Key Path and save the variable.

<figure><img src="https://2963651437-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5eC7lwaeygB0xx6AOZcE%2Fuploads%2FHVinyy1DJ4XkWrOFYyN7%2Fimage.png?alt=media&amp;token=688d4ac4-cf86-4a83-8878-f5033958c098" alt=""><figcaption></figcaption></figure>

5. Create another new variable and choose RegEx Table as Variable Configuration.
6. As Input Variable, select the page\_location variable you just created. The page\_location in the event data contains the URL of the page on which the event was created and sent, so you can use it to tell the domains apart.
7. Click Add Row to set a specific Output for each Pattern.

{% hint style="info" %}
Make sure to turn off all three options under Advanced Settings.
{% endhint %}

<figure><img src="https://2963651437-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5eC7lwaeygB0xx6AOZcE%2Fuploads%2F4Yvkw6RJUtAXTt9B5E9I%2Fimage.png?alt=media&amp;token=eb0e0b80-8f25-4751-9bbc-2f9f585509fc" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.adpage.io/faq/google-tag-manager-setup/how-do-you-set-up-tracking-for-multiple-domains-on-the-same-container.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
