# Google Tag Manager (GTM)

Commanders Act provides a GTM template to connect your existing GTM implementation to our serverside endpoint, in a secured environment.

{% hint style="info" %}
If you use GA4, you may be interested by the [GTM ultra quick setup](https://doc.commandersact.com/getting-started/integrating-your-data/gtm-tutorial) allowing to forward events from GA4. It offers less flexibility but can be installed in 2 minutes.
{% endhint %}

## Setup

Summarizing all recommended steps:

1. Create a GTM source in Commanders Act
2. Add our template to your GTM implementation
3. Configure your tag

## Create a source in Commanders Act

In your Commanders Act dashboard:

* In the left pane menu, click on **Sources** > **Overview**.
* Click on the **Add source** button.
* In the catalog, search for the **Google Tag Manager** source and click on it.
* Click on **Configure** and set its name, environment and bound destinations.
* Once you're done, click on the **Create** button at the bottom.
* The source key will then be displayed:

![](https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-f8c724ee9abe14a0f756f298d19815c1390bd949%2Fserverside_events_bridge-key.png?alt=media\&token=5b3bcba0-9ecb-4438-94c7-35218f5f6896)

* Copy its value and keep it for later!

{% hint style="info" %}
**Hint**: If you have already created a GTM source, you can retrieve its key by browsing to its **Settings** tab.
{% endhint %}

## Add our template to GTM

First, access [GTM](https://tagmanager.google.com/) and then add our template "**Commanders Act | Serverside events bridge**" from the Google "[Community Template Gallery](https://tagmanager.google.com/gallery/#/owners/TagCommander/templates/Serverside-events-bridge)" in your workspace, then select `(1)` "**Tags**".

![](https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-5361fa6480a0ba6f678a3f9872ee19ff46e96bec%2Fserverside_events_bridge1.png?alt=media)

Click on `(2)` the "**New**" button.

![](https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-ccd62c2f6273397e6d157ed23800473d7774872b%2Fserverside_events_bridge2.png?alt=media)

Click on `(3)` the "**Tag Configuration**" area.

![](https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-7a665818d2bc5951ec229d26aeb47be293f975e9%2Fserverside_events_bridge3.png?alt=media)

Click `(4)` the **magnifying glass** in the upper right corner.

![](https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-2385b99e5e5ce17fd747fd3ad0fd17068bbefac7%2Fserverside_events_bridge4.png?alt=media)

Search for `(5)` the "**Commanders Act | Serverside events bridge**" custom template and click on it to start the configuration.

![](https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-25ed91ecdca8cf259bdedee084cdec196122a447%2Fserverside_events_bridge5.png?alt=media)

## Configure your tag

Start by filling `(6)` **a name for your tag** in the upper left corner.

![](https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-5fab7d89fb8af5e67cd300d94a9af96533b0e0c0%2Fserverside_events_bridge6.png?alt=media)

{% hint style="success" %}
**Hint**: you may want to name your tag adding the event name you're going to implement in the end. (E.g. "*Commanders Act |* Serverside events bridge *- **Purchase***")
{% endhint %}

Input your `(7)` "**Commanders Act Site ID**" and `(8)` "**Commanders Act Source Key**" (refer to the first section on how to create a source and retrieve its key).

Select `(9)` the "**Commanders Act Event**" from the drop-down menu, which is the event you want to forward.

<figure><img src="https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-fc5eb1ef79a680e7e7db8ff2cb24824957b2f5ea%2Fserverside_events_bridge7.png?alt=media" alt="" width="536"><figcaption></figcaption></figure>

Depending on which event you select more (or less) fields will be presented. In case you don't input a mandatory field the template will highlight the missing entry so you can provide a proper mapping.

The "**Event Fields**" section contains fields that define the event itself and are mostly mandatory or highly recommended.

Events including the "**Product Fields**" section require [an array structure for your product information](https://community.commandersact.com/tagcommander/tips-and-tricks/best-practices/common-datalayer-variables#product-arrays). The first field will always be the `(10)` **base array** where the information is stored and all subsequent fields are the related properties - E.g. you can map the information about `(11)` the "**Product Id**" by filling the property name.

<figure><img src="https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-588a47204fa73ed0c36144a27937371bcb26d861%2Fserverside_events_bridge8.png?alt=media" alt=""><figcaption></figcaption></figure>

In the "**User Fields**" section you can set `(12)` the "**User Id**" and `(13)` "**User Email**" - Either one of them is required if you select the "Purchase" event. The `(14)` "**User Consent Categories**" is a mandatory field holding an array with the user's consent category identifiers.

<figure><img src="https://1259070148-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mk6XpTQ2LaRLcr2tA-d%2Fuploads%2Fgit-blob-fd8e1c4bd7de4544ba8d2534d5effb8b87382e75%2Fserverside_events_bridge9.png?alt=media" alt=""><figcaption></figcaption></figure>

It's important to define and map all category identifiers with their respective names. For example, you may have the following array: *\[1,2,4]* and you defined the following relationship:

* 1 **➜** Advertising category
* 2 **➜** Analytics category
* 4 **➜** Functionality category

You also share with Commanders Act that the "Advertising category" must be enabled to activate the "Facebook CAPI." In this example, since the category identifier \[1] is included in the array we can activate the bridge and forward the event to Facebook.

{% hint style="info" %}
Ensure your category relationships are shared with Commanders Act.
{% endhint %}

{% hint style="warning" %}
Only with the agreed consent settings, we're allowed to bridge both the "Purchase" and "Refund" events to the "Facebook CAPI".
{% endhint %}

Complete your configuration by selecting the proper activation in the "Triggering" area / "Firing Triggers".

If you plan to setup [Facebook Conversion API](https://doc.commandersact.com/features/destinations/destinations-catalog/facebook/facebook-conversions-api) through your GTM source, follow this extra step to update your Facebook Pixel tag:

{% content-ref url="../../../destinations/destinations-catalog/facebook/facebook-conversions-api/facebook-capi-through-gtm" %}
[facebook-capi-through-gtm](https://doc.commandersact.com/features/destinations/destinations-catalog/facebook/facebook-conversions-api/facebook-capi-through-gtm)
{% endcontent-ref %}
