This document describes the different ways to send events to a server-side
container. If you need more background information, take a look at
[how server-side tagging works](https://developers.google.com/tag-platform/learn/sst-fundamentals/2-what-is-sst#how-server-side-tagging-works).

This document discusses how to:

- Send data from a website to your server-side container
- Send additional data to a server container
- Receive data in your server-side container
- Send data from sources other than websites

## Before you begin

This guide assumes that you already have:

- [Set up a server container in Tag Manager](https://developers.google.com/tag-platform/tag-manager/server-side/overview#create_a_tag_manager_server_container)
- [Set up a tagging server](https://developers.google.com/tag-platform/tag-manager/server-side/overview#set_up_a_tagging_server)

## 1. Send data from a website to your server-side container

You can route data through a server-side implementation via Tag Manager or
gtag.js. Pick your implementation option.
<button value="GTM" default="">Tag Manager</button> <button value="gtag">gtag.js</button> Choose your implementation option.

### Optional: Send additional parameters with each event

You can send additional two types of additional parameters: Configuration-level
parameters and event-level parameters. Configuration parameters influence how
your Google tag or Google Analytics destination tag behaves and can only be set
on the Google tag or Google Analytics destination tag level.

Event parameters specify additional information about an event and can be set
for all events, select events, or `page_view` events.
Choose your implementation option.

### Setup recommendations

We recommend using Google Analytics tag on a web page to send data to the
server container. This tag can use different transport methods to ensure the
best delivery rate of the events. Such methods include but not limited to

- Image pixel
- Fetch API
- XHR
- Service worker that runs in an iframe loaded from your server container domain.

To ensure that all methods are supported check the following:

***Content-security policy (CSP)***

|---|---|---|
| **Directive** | **Content** | **Purpose** |
| img-src | \[SERVER_CONTAINER_URL\] | Measurement requests |
| connect-src | \[SERVER_CONTAINER_URL\] | Measurement requests |
| frame-src | \[SERVER_CONTAINER_URL\] | Service worker implementation |

In addition, **X-Frame-Options** must not restrict iframes from being loaded
from the server container URL.

Consult with
<https://developers.google.com/tag-platform/security/guides/csp>
for specific policies per product.

## 2. Receive data in your server-side container

When you send HTTP request to a server container, a client has to claim that
request.

> [!IMPORTANT]
> **Key Term:** "Clients" are adapters between the software running on a user's device and your server-side Tag Manager container. They receive measurement data from a device, transform that data into one or more events, process the data in the container, and package the results to be sent back to the device.

To view the list of available clients:

1. [Open
   Google Tag Manager](https://tagmanager.google.com/#/home)

2. Open your server container.

3. In the navigation bar on the left, click **Clients**. The Google Analytics
   client is pre-installed on your server-side container by default.

4. Click the name of the client to view or edit details.

### Optional client settings

In most cases, the client will require no modifications. However, your use case
might be different and you might want to edit one of the following settings:

- **Priority:** Determines the order in which clients will run. Higher numbers
  run first, and the first client that matches the incoming request will
  become the active client for that request.

- **Activation Criteria:** Activation criteria define when the client will
  respond to requests:

  - **Default gtag.js paths for specific IDs:** Use this setting to enable gtag.js JavaScript serving through your server container URL. When enabled, this client will activate in response to requests to the default gtag.js request paths, e.g. `/gtag/js?id=TAG_ID`. Click **Add
    Measurement ID** to add one or more [destination IDs](https://support.google.com/tagmanager/answer/12324787).

### Optional: Receive additional data in server-side Tag Manager

If you are sending [additional parameters](https://developers.google.com/tag-platform/tag-manager/server-side/send-data#additional-parameters), you need to
set up the **Google Analytics** client in your server container to parse the
additional parameters and create event data out of them.

Some server tags will include the additional parameters in their outbound
requests with no setup. To exclude those parameters, create a [Transformation](https://developers.google.com/tag-platform/tag-manager/server-side/transformations)
to remove the value.

To use additional parameters in other tags:

1. In your server container, click on **Variables** in the left navigation.
2. Create a **New User-defined Variable**.
3. In **Variable Configuration** , select the variable type **Event Data**.
4. In **Key Path**, enter the name of the parameter.
5. Give your variable a name and **Save**.

Now you can use the event parameter in any other tag within your server
container.

## 3. Optional: Send data from sources other than websites

The Google Analytics [Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/ga4) can be used to enable server-side
tagging support from sources such as mobile apps and server-to-server
applications. This option lets you send events to your container in the
Measurement Protocol format. The container sends those events to Google
Analytics using the same mechanism as all other SGTM events.

> [!NOTE]
> **Note:** This option doesn't send events to the Measurement Protocol endpoint.

This option doesn't support all the features of the Measurement Protocol
endpoint, like deriving [geographic and device information](https://developers.google.com/analytics/devguides/collection/protocol/ga4#geo_device) from
tagging events.

### Mobile apps

To get your Android or iOS app to send data to your server container, you will
create a custom image tag and configure it to use the Measurement Protocol:

1. In your mobile container (Android or iOS), click **Tags \> New**.
2. In **Tag Configuration** select the **Custom Image** tag type.
3. Set the value of **Image URL** to a pixel image on the server container at the path in the Measurement Protocol client that you specified earlier. Append any desired Measurement Protocol parameters to the end of your pixel URL:   
   `https://custom.example.com/app?v=1\&tid=TAG_ID\&cid=555\&t=screenview\&an=myApp\&version=1.6.2\&aid=com.foo.myapp\&cd=home`
4. Deselect **Enable Cache Busting**.
5. Save the tag and publish the container.
6. In your server-side container, click **Clients \> New**.
7. In **Client Configuration** , select the **Measurement Protocol** client type.
8. Set **Activation Path** to the path of your app's collection endpoint.
9. Save the client configuration and publish the server-side container.

### Server-to-server apps

To send measurement protocol data to your server container, replace the
`www.google-analytics.com` hostname with the domain name of your server
container. For example:

    POST /batch HTTP/1.1
    Host: collection.example.com

    v=1&tid=TAG_ID&cid=555&t=screenview&an=myApp&version=1.6.2&aid=com.foo.myapp&cd=home

To receive Measurement Protocol hits, configure your server-side Tag Manager
installation with a Measurement Protocol client:

1. In your server-side container, click **Clients \> New**.
2. In **Client Configuration** , select the **Measurement Protocol** client type.
3. Set **Activation Path** to the path of your server's endpoint.
4. Save the client configuration and publish the container.

## Next steps

To send data in a true first-party context, you need to serve Google scripts,
such as the Google Analytics library, from your own servers.

[Load
Google scripts through my
server](https://developers.google.com/tag-platform/tag-manager/server-side/dependency-serving)