Send data to server-side Tag Manager

This article 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.

This article 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:

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

You can route data through a server-side implementation via Tag Manager or the Google tag (gtag.js). Pick your implementation option.

Google tag: GA 4

To set up a Google tag for server-side processing, you need to add your server container URL.

Create a configuration variable for the server container URL

  1. Open Google Tag Manager

  2. Select the web container you want to configure.

  3. Open the Variables menu.

  4. Create a New user-defined variable of the type Google tag: Configuration settings.

  5. Add the following parameters:

    • Name: server_container_url
    • Value: Set to the server container URL of your Tag Manager server container.
  6. Name your variable, for example, "Server URL", and Save it.

Assign the server container URL to a Google tag

  1. Open the Tags menu.
  2. Add a new Google tag, or edit an existing one.
  3. In Configuration settings, select the server container variable you just created.
  4. To ensure that the Google tag fires before other triggers, click Triggering and use the Initialization - All pages trigger. Learn more about Page triggers.
  5. Save the tag and Publish the container.

Universal Analytics

To set up a tag for server-side processing, add your server container URL:

  1. In a web container, add a Universal Analytics tag with a Google Analytics Settings Variable, or use an existing Universal Analytics configuration.
  2. Navigate to More Settings > Advanced Configuration.
  3. Select the Set Transport URL checkbox.
  4. Add your server container URL to the Transport URL field (e.g. https://<DOMAIN_NAME> where DOMAIN_NAME is your server container domain name).
  5. Configure the trigger to fire on Initialization - All pages.
  6. Save the tag and Publish the container.

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 behaves and can only be set on the Google tag level.

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

Configuration parameters

Learn how to reuse configuration settings in Google Tag Manager.

All events

To send additional parameters across all events, reuse event settings in Google Tag Manager.

Select events

To send additional parameters with a Google Analytics 4 Event:

  1. In a web container, add a Google Analytics 4 Event tag or edit an existing one.
  2. Click Event Parameters > Add Row.
  3. Add the parameter to send with the event. For pre-defined event parameters see the Recommended events reference.
    • In Field Name add the name of your parameter, for example, language.
    • In Value add the value of your parameter.
  1. Configure a trigger to fire on Initialization - All Pages.
  2. Save the tag and Publish the container.

page_view events

To send a parameter on a page_view event:

  1. In a web container, edit an existing Google tag.
  2. Disable the default page_view in the configuration settings by adding new parameter:

    • Name: send_page_view
    • Value: false
  3. Create a new Google Analytics: GA4 Event tag.

    • Select the configuration tag you modified in step 1.
    • Set the Event Name to page_view.
  4. Add the parameter to send with the event. For pre-defined event parameters see the Recommended events reference. - In Field Name add the name of your parameter, for example language.

    • In Value add the value of your parameter.
  1. Configure a trigger to fire on Initialization - All Pages.
  2. Save the tag and Publish the container.

2. Receive data in your server-side container

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

To view the list of available clients:

  1. Open Google Tag Manager

  2. Open your server container.

  3. In the navigation bar on the left, click Clients. The GA4 client is pre-installed on your server-side container by default. If you need to work with Universal Analytics, set up a Google Analytics: Universal Analytics client.

  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:

    • For UA clients: Default Universal Analytics paths: The client will activate when the request paths include /collect, /r/collect, and other similar paths used by JavaScript files that send data to Google Analytics. This setting is active by default.

    • 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.

Optional: Receive additional data in server-side Tag Manager

If you are sending additional parameters, you need to set up the Google Analytics 4 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 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 can be used to enable server-side tagging support from sources such as mobile apps and server-to-server applications.

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