Set Up a Server Container in Google Tag Manager
You can achieve more reliable and consistent conversion metrics using a server Google Tag Manager (GTM) container. A server container reduces inaccuracies by avoiding client-side third-party limitations, like browser-based privacy measures or ad-blocking extensions. On top of that, it lets you establish consent management mechanisms, ensuring your data collection practices align with regulatory requirements and user preferences.
While setting up a server GTM container improves the reliability and consistency of conversion metrics, the initial setup process might be a bit more involved and require some extra resources.. We suggest reaching out to developers if you're unsure and giving the setup a good test run to ensure it's working as best as it can.
Looking for an easier way to track Reddit conversions in GTM? Set up a client-side container instead.
Before you start
Create an access token
An access token is required to share conversion events from your server container to Reddit Ads. We recommend generating a conversion token so you don't have to worry about it expiring.
Set up your website on a server
If you're not comfortable with coding or don't have access to your website's backend, ask a developer for help.
There are many ways to set up your server, such as through a cloud hosting provider, managed hosting provider, or self-hosting. Just remember to choose a method that lets you inject code or has native GTM capabilities, based on your comfort level.
You'll also need to:
- Copy and record your website's URL. Your URL should start with
http://
orhttps://
. - Add a path rule, like
/metrics/*
, to route traffic to your tagging server, which is the default URL of your server container. If you need help routing traffic, check the documentation of your hosting service.
Create a Google account
Your account should have enough permissions to set up a billing account. Learn how to set up billing on your account.
If you don't have these permissions, request them or send this guide to someone who does.
Set up your Google tools
You'll need to set up several Google tools to create a server-side GTM container. Here's what you'll need:
- A GTM account with a web and a server container with an automatically provisioned tagging server. You'll need to copy and record each container's ID, formatted as
GTM-XXXXXX
. Need help with setup? Here's a great place to start. For your server container, you'll also need to:- Copy and record its default URL.
- Copy and record its container ID, formatted as
GTM-XXXXXX
. - Set the server container URL to a unique URL on your site. This URL should be your site's domain and a unique path. For example, if your domain is
https://mysite.com
, you could set your server container URL tohttps://mysite.com/metrics
. Learn how to add a container URL to your server.
- A Google Analytics account with your website URL as the web property. You'll need to copy and record your measurement ID, formatted as
G-XXXXXXXXXX
. Learn how to set up Google Analytics for your site. - A web container with the Reddit Pixel set up.
1. Add tags to your web container to forward Google Analytics events
If you're planning on sharing attribution matching or event metadata, you'll need to set up a Google Tag and Google Analytics: GA4 Event tags for all your conversion events. Creating these tags in your web container will let you load and send events to the tag associated with your Google Analytics stream. This way, your server container will automatically populate values based on the variables in your web container.
Set up the Google Tag
- In Tags, select New.
- Select Tag Configuration, then select Google Analytics > Google Tag.
- Create an appropriate name for your tag. We recommend setting this to
Google Tag
. - Paste your Google Analytics Measurement ID into the tag ID field.
- In configuration settings, select Add parameter. Set the parameter to
server_container_url
and its value to your server GTM's server container URL. - Select triggering and choose Initialization - All Pages. This will prioritize this tag and fire it before other triggers.
- Save to create your tag.
Set up a Google Analytics event tag for every conversion event
- In Tags, select New.
- For tag configuration, select Google Analytics > Google Analytics GA4 Event.
- Create an appropriate name for your tag. We recommend setting this to
<Conversion Event> - GA4
. - Paste your Google Analytics Measurement ID into the tag ID field.
- Provide the name of your conversion event for event name.
- In event parameters, select Add parameter. Add all the attribution matching and event metadata parameters that you'd like to share for the event.
- Select triggering and choose the trigger for your conversion event.
- Save to create your tag.
2. Install your web container onto your website
This step is only required if you don't have a native tool in your server solution. If you have a native tool, follow the steps that it provides.
If you're not experienced with code or don't have access to your website, you may need to ask a developer for help.
If your website solution doesn't have the tooling to set up GTM or Google Analytics, you can manually set this up on your website.
At the beginning of the <head>
tag, add the GTM script:
<!-- Google Tag Manager -->
<script>
(function(w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({
'gtm.start': new Date().getTime(),
event: 'gtm.js'
});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l !== 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = '/gtm.js?id=' + i + dl; // Local GTM server path
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', '[Web container ID]');
</script>
<!-- End Google Tag Manager -->
Example: GTM script
If your path rule isn't /metrics/*
, change the URL to match that rule.
<!-- Google Tag Manager -->
<script>
(function(w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({
'gtm.start': new Date().getTime(),
event: 'gtm.js'
});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l !== 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://mysite.com/metrics/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-PNXS9GCP');
</script>
<!-- End Google Tag Manager -->
After the <head>
tag but before <body>
tag, add the GTM <noscript>
:
<!-- Google Tag Manager (noscript) -->
<noscript>
<iframe src="/[Server container path](/ns.html?id=[Web container ID]" height="0" width="0"
style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
Example: GTM noscript
<!-- Example: server container URL as https://mysite.com/metrics and your web container ID as GTM-XXXXXXXX-->
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="/metrics/ns.html?id=GTM-XXXXXXXX" height="0" width="0"
style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
2. Add the web container client to your server container
Connecting your web container to your server container allows the scripts in the web container to serve from the server container, making it possible to access first-party cookies from the Reddit Pixel to CAPI.
- Select your server container to open its workspace.
- In the left-hand menu, go to Clients.
If you don't see Clients in this menu, you might have selected the wrong container.
- Create a new client by selecting New.
- Name your client. We recommend setting the name to
GTM Web Container
so it's easy to identify. - For client configuration, choose Google Tag Manager: Web Container.
- Set priority to 0.
If you have multiple clients, you can set this to a higher number so it runs first.
- Add the ID for your web container to allowed container IDs.
- Enable automatically serve all dependent Google scripts, compress HTTP response, and enable region-specific settings.
- For region, select choose built-in variable and select visitor region. This will set this field to
{{Visitor Region}}
. - Save to create your client.
3. Add the tag template to your Google Tag Manager
- In Google Tag Manager, select your server container to open its workspace.
- In the left-hand menu, select Templates and choose Search Gallery for tag templates.
- Choose Reddit Conversions API and select Add to workspace.
Make sure you choose the template by Reddit and not one by a third-party tag like Stape.
- When prompted, select Add.
4. Create a conversion access token variable
- In the workspace of your server container, select Variables in the navigation menu and select New.
- Set a name for the variable, like
Conversion Access Token
. - For variable configuration, choose constant.
- Add your conversion access token as the value.
- Save your changes to create the variable.
5. Create variables for optional parameters
We highly recommend creating variables for all optional parameters, like attribution matching and event metadata, to automatically populate those values.
- In the workspace of your server container, select Variables in the navigation menu and select New.
- Set a name for the variable. We recommend setting it to the name of the optional parameter.
- For variable configuration, choose event data.
- Provide the key for the key path. This should match the variable's name in your GA4 event tag's event parameters.
- Save your changes to create your variable.
6. Set up triggers
Before creating your tags, create a Google Tag Manager trigger for every conversion event you'd like to share.
- In the workspace of your container, select Triggers in the navigation menu and select New.
- Set a name for the trigger, like the name of the conversion event.
- For trigger type, choose Custom Event and set the trigger to fire for some events.
- Set the event name to exactly match your web container event's name.
- Set the condition to when the event name contains the event name you set in your GA4 event tag.
- Save your changes to create the trigger.
7. Set up conversion events
You can easily share conversion events with the Reddit Conversions API (CAPI) by tagging them with your GTM account. Here's how to do it.
8. Publish your container
When finished with your changes, select Submit or Publish to make your changes live. You'll need to do this for your web and server container.