> For the complete documentation index, see [llms.txt](https://fredhopper.gitbook.io/product-discovery/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fredhopper.gitbook.io/product-discovery/tracking-and-sending-events/implementation-guide/google-tag-manager.md).

# Google Tag Manager

Track user activities with Google Tag Manager using Rezolve AI's provided GTM templates for streamlined front-end tracking implementation.

Use the provided Google Tag Manager (GTM) templates to track [user activities](/product-discovery/tracking-and-sending-events/activities.md).

## Prerequisites

* Configured GTM container
* Data layer containing the [information to be tracked](/product-discovery/tracking-and-sending-events/setup-guide/prerequisites.md#ensure-data-provision) (if possible)
* Tracker key

{% hint style="info" %}
To obtain your tracker key(s), reach out to your Customer Support Manager.
{% endhint %}

## GTM Templates

We provide the following two templates for use:

* [XO Activities Tracking](https://tagmanager.google.com/gallery/#/owners/Attraqt/templates/xo-activities-gtm): Use for sending one activity event for each user action
* [XO Multi-Activities Tracking](https://tagmanager.google.com/gallery/#/owners/Attraqt/templates/xo-multiactivities-gtm): Use for sending mutiple activity events for a single user action

Access these templates by clicking the links above. Alternativey, in the [***Community Template Gallery***](https://tagmanager.google.com/gallery/#/), search for "**XO Activities Tracking"** or "**XO Multi-Activities Tracking"**.

{% hint style="info" %}
The XO templates are used for both FHR and XO.
{% endhint %}

### XO Activities Tracking

The XO Activities Tracking template is the main template. Use this template to send one activity event for each user action:

1. Add the template to your workspace.
2. Using the **New** button in the **Tag** section, add a new tag.
3. Select the **XO Activities Tracking** template.\
   -> A configuration window opens.

<figure><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2Fgit-blob-54e5dbba37d1af5108612a088a46c21297c9dbeb%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

4. Add your **tracker key** in the assigned field.
5. Choose an **action**.\
   Each field corresponds to a **variable**, which means that you can configure **multiple actions** on the tag if your variable is dynamic. Otherwise, you should have an individual tag for each tracking action.
6. Add one or more **targets**.\
   A **target** is a key-value pair which corresponds to the **target** property of the [**activity** **object**](/product-discovery/tracking-and-sending-events/activities/activity-object.md).
7. Add one or more **identities**.\
   An **identity** is a key-value pair. The key corresponds to the name of the **identity** (such as: "**sessionId"**) and the value to the **ID** of that identity for the visitor (the actual **session ID**).
8. Optional: Add any additional information about the user, such as **traits**, or **segments,** in the **User information** section. These fields correspond to the different parts of the [**user object**](/product-discovery/tracking-and-sending-events/identities/user-object.md).
9. Optional: Add any additional details around the **activity**, such as **metadata**, in the **Activity information** section.

{% hint style="warning" %}
The section **Advanced Settings** is not part of the XO tag configuration.
{% endhint %}

#### Example

A basic tracking configuration for events that relate to a single product should look like this:

<figure><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2FUJLBfze6JTW0VNFoiqGp%2FCapture%20d%E2%80%99%C3%A9cran%202020-05-28%20%C3%A0%2010.41.49.png?alt=media&amp;token=bbc8dab8-149c-4cf3-b3f9-132fbe81c8d0" alt=""><figcaption></figcaption></figure>

### XO Multi-Activity Tracking

Use this template to send multiple activity events for a single user action, such as when a user purchases multiple items in their basket:

1. Add the template to your workspace.
2. Use the **New** button in the **Tag** section, add a new tag.
3. Select the **XO Multi-Activities Tracking** template.

{% hint style="warning" %}
For the most part, you can use this template in the same way as the [**XO Activities Tracking** template](#xo-activities-tracking). The key difference in the requirement of a [**variable**](https://support.google.com/tagmanager/answer/7683056?hl=en) containing all the necessary product information.
{% endhint %}

4. Set up your variable in the "Target list" section.

<figure><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2Fgit-blob-27c3bdd040b55ce94e7c87d2d9e62a47553b0f57%2Fimage%20(5).png?alt=media" alt=""><figcaption></figcaption></figure>

Your **variable** should be an array of objects like in the following example:

```json
"buyedProducts": [
    {id: "product1", "price": 100, quantity: 1},
    {id: "product2", "price": 50, quantity: 2}
]
```

5. To set product-specific values for an event, add rows to the **Attributes** section.\
   Each row corresponds to a different value in your **variable**, and allows you to define what it will be mapped to in the activity object.\
   In the following example, we will map the **ID**, **price** and **quantity** from our **variable** (the input object) to the `target.product` , `metadata.price` and `metadata.quantity` fields in the resulting activity object.

{% hint style="danger" %}
Each tracker key can only be used with a single currency.
{% endhint %}

<figure><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2Fgit-blob-bf70318bf2e27534fb880c077829c219dc5fcc7e%2Fimage%20(6).png?alt=media" alt=""><figcaption></figcaption></figure>

6. To set information that is specific to this group of events, and not each product (eg: orderId or currency) you can add them in the **common** section.

<figure><img src="https://3916646904-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfLO8j00CcKdYax4GPUyE%2Fuploads%2Fgit-blob-8cdc92a0ebd6e36d1c7f823f8caf65d9a8f1e136%2Fimage%20(7).png?alt=media" alt=""><figcaption></figcaption></figure>
