> 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/getting-started/setup-gtm-server-container.md).

# Setup GTM server container

Go from sign-up to your first deploy in under five minutes.

## GA4 configuration

Let's start with the GA4 configuration. Your AdPage server container is going to receive GA4-formatted requests sent from the client, so we'll set up a Google Analytics 4 client and tag to handle those incoming requests. These Google Tag Manager server container settings will ensure that the incoming GA4 requests get sent on to your Google Analytics 4 property as GA4 events.

{% stepper %}
{% step %}

### GA4 Client

To begin with, let’s focus on the Client part of the Google Tag Manager server container. A Client on a Google Tag Manager server container is responsible for receiving incoming data on the server. The GA4 Client enables the server to receive and understand data in GA4 format.

By default, a GA4 Client should already exist on your server container. If you go to the **Clients** section, you should find this client. There are no changes needed to this Client for a regular server-side tagging setup.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2FiF8bf8cvXqCmCT7TYGyk%2Fimage.png?alt=media&amp;token=c189e564-5c76-4c7e-959e-814e0308a8fb" alt=""><figcaption></figcaption></figure>

<details>

<summary>Edit the GA4 Client</summary>

By default the GA4 client uses the JavaScript managed client ID, which means it reads the `_ga` cookie that the Google tag sets in the browser. That works fine for a standard server-side setup, so you can leave this section alone.

If you'd rather let the server handle identification, set Client ID source to Server Managed. The server container then writes its own first-party cookie called `FPID` in the HTTP response, with the HttpOnly flag, so browser JavaScript can't read it. Since it isn't set by JavaScript, it keeps its full lifespan, because Safari's ITP only shortens cookies that JavaScript sets. That's the main reason to switch. Returning visitors stay recognisable for longer, and your user and attribution data holds up better.

If you make this change on a property that already gets traffic, also check Migrate from JavaScript Managed Client ID. Visitors who already have a `_ga` cookie will keep their current ID, and `FPID` only takes over once that cookie is gone. Without it, all your existing visitors get a new ID at the same time, which shows up in GA4 as a spike in new users. On a brand new property there's nothing to migrate, so you don't need the option.

Two things worth checking before you switch. First, the client ID that GA4 receives comes from the `FPID` value, so it no longer matches the `_ga` value that client-side scripts can read. If other tools or integrations rely on that value, test them first. Second, with Server Managed turned on, the FPID cookie gets generated on every request the client claims, no matter what the consent state is, unless you blank out the cookie name conditionally.

</details>
{% endstep %}

{% step %}

### GA4 Tag configuration

Now that the GA4 client is configured, the server can receive and process GA4 web tracking requests. Now we need to a create a Tag to dispatch these requests to the correct GA4 property.

Go to the **Tags** tab of your server container and create a new tag.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2F28xP5GbQutC86XZZBmG2%2Fimage.png?alt=media&amp;token=bfb7b7e7-8d78-482d-9e48-1058426f3f77" alt=""><figcaption></figcaption></figure>

Select **Google Analytics: GA4** as the tag configuration.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2FxyAAxut7ciLlqmmtjrbW%2Fimage.png?alt=media&amp;token=78f698e3-526c-47e2-909a-afbde1075c0b" alt=""><figcaption></figcaption></figure>

In this GA4 tag, several configurations are possible. Here are the 2 most commonly used fields:

**Measurement ID**\
This measurement ID decides which GA4 property your data goes to. If you fill it in, everything gets sent to that property. If you leave it empty, it uses whichever measurement ID your web container sends along.

**Event name**\
This field lets you force the tag to send one specific event name to GA4. Leave it empty and the event names coming in from your web container get passed along as they are.
{% endstep %}

{% step %}

### GA4 trigger configuration

To forward all GA4 events arriving on your server to your GA4 property, configure the tag to trigger when the `Client Name` equals `GA4`.

If **Client Name** doesn’t appear in the dropdown for the trigger condition, enable it by clicking on **Choose Built-in variable**.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2Ft0VSqIaf3mNegHNklYfr%2Fimage.png?alt=media&amp;token=663bbe17-7c6e-424b-bfa6-1ef7a3320ce5" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

Preview url configuration

To be able to use the preview mode in your Google Tag Manager server container, you have to input the server which tracking subdomain you're using. Without this step you won't be able to launch the preview on the server side.

Go to the **Admin** section of your Google Tag Manager server container and open **Container settings**. On that page, add the tracking subdomain you set up earlier in the **Server container URLs** input field.

<figure><img src="https://1274044937-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA65KwL1NwewlJbtCXsXd%2Fuploads%2Fza21RSIbeMXuH6VZXnaC%2Fimage.png?alt=media&amp;token=c8781749-26ec-49c6-a190-dc10dc1da7b5" alt=""><figcaption></figcaption></figure>

## What's next?

You've just set up your first server-side tagging setup for Google Analytics 4. With your GA4 Client and Tag configured, head on to the next step, where you'll set up the Google Tag Manager web container so it can send GA4 requests to your server container based on website-interactions.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.adpage.io/getting-started/setup-gtm-server-container.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
