This guide explains how to install the Click2Buy GTM Server-Side tag template to track sales and conversions referred from our platform.
Using this server-side template ensures more robust, reliable, and high-performance tracking by leveraging first-party cookies.
Before you begin, you must have the following:
- An active and functional GTM Server-Side (GTM-SS) container.
- This server container must be hosted on a subdomain of your main site (e.g.,
sgtm.your-site.com) to enable first-party cookie setting. - A Web (client-side) GTM configuration that sends its data to your server container (via the
server_container_urlparameter in your Google Tag).
If these prerequisites are not met, the installation will fail. Please refer to the official Google documentation to set up your GTM Server-Side infrastructure.
In this section, we will install the core tracking logic into your GTM-SS container.
- Download the latest version of our tag template (the
template.tplfile) from the Releases page of this GitHub repository. - In your GTM Server container, go to Templates.
- Under "Tag Templates," click New.
- In the template editor, click the three-dot menu (⋮) in the top-right corner and select Import.
- Choose the
template.tplfile you just downloaded. - Click Save (you can ignore the "edit code" warning, this is normal).
To optimize performance and cost, your tag should only run on relevant events: the initial visit (page_view) and conversion events (purchase, generate_lead, etc.).
-
In your GTM Server container, go to Triggers.
-
Click New and name it (e.g.,
[C2B] - PageView and Conversions). -
Trigger Type: Custom.
-
This trigger fires on: Some Events.
-
Set the following conditions:
{{Client Name}}-equals-GA4{{Event Name}}-matches RegEx-^(page_view|purchase|generate_lead)$
Note: You can select the "Client Name" or "Event Name" variables by clicking on the variable selection icon (brick).
Important: If your primary conversion event is not
purchaseorgenerate_lead, add it to the RegEx (e.g.,^(page_view|purchase|form_submission|my_event)$). -
Click Save.
- In your GTM Server container, go to Tags.
- Click New.
- Name the tag (e.g.,
Click2Buy S2S Attribution). - Click "Tag Configuration" and choose the "Click2Buy S2S Attribution" template you just imported (it will appear in the "Custom" list).
- Click "Triggering" and select the
[C2B] - PageView and Conversionstrigger created in step 1.2. - Click Save.
This section ensures your Web GTM (in the browser) correctly sends all events to your Server GTM, so our tag can intercept them.
If you already have a Web GTM setup that sends all its events (via a dynamic GA4 Event tag) to your
server_container_url, you can skip this section.
- In your Web GTM container, find your main "Google Tag" (the one with your
G-XXXXXXID). - Verify that it has a
server_container_urlconfiguration parameter pointing to your GTM-SS subdomain (e.g.,https://sgtm.your-site.com).
For your server tag to receive purchase events, you must send them. The best method is a single, dynamic event tag.
- In your Web container, go to Tags and click New.
- Name the tag (e.g.,
[GA4] - All Events (to Server)). - Tag Type: Google Analytics: GA4 Event.
- Configuration Tag: Select your main Google Tag (from step 2.1).
- Event Name:
{{Event}}(This is a built-in GTM variable that dynamically uses the event name from thedataLayer).
This tag must fire on all events your site sends.
-
In the tag you are creating (step 2.2), click on Triggering.
-
Create a New trigger (top-right corner).
-
Name it (e.g.,
Custom - All Events (with exceptions)). -
Trigger Type: Custom Event.
-
Event name:
.*and check the Use RegEx matching box. -
This trigger fires on: Some Custom Events.
-
Set the following condition to exclude default GTM events:
{{Event}}-does not match RegEx-^(gtm\.(js|dom|load)|page_view)$
-
Save the trigger, then save the tag.
You have completed the setup. All that's left is to publish and test.
- Publish the changes in your Web container.
- Publish the changes in your Server container.
- Open the Preview mode for your Server container.
- Open the Preview mode for your Web container.
Test 1: The Attribution (Cookie Set)
- In your browser, open a page on your site, adding our test parameter to the URL:
https://www.your-site.com/?c2bm=12345test - In your Server Preview, you should see a
page_viewevent arrive. - Click on this event. The
Click2Buy S2S Attributiontag should appear in the "Tags Fired" section. - In your browser's Developer Tools (F12) > Application > Cookies, you should see a new first-party cookie (e.g.,
_c2b_attribution_id) with the value12345test.
Test 2: The Conversion (Data Send)
- On your site (still in Preview mode), trigger a conversion event (e.g., complete a test purchase to trigger the
purchaseevent). - In your Server Preview, you should see the
purchaseevent arrive. - Click on this event. The
Click2Buy S2S Attributiontag should again be in the "Tags Fired" section. - Click this tag to inspect it. Go to the "Outgoing HTTP Requests" tab.
- You should see a request successfully sent to our tracking endpoint.
If both tests are successful, the installation is complete!
If you encounter any issues, please contact retailers@click2buy.com.