# Google Tag Manager

> Learn how to install AnyTrack via the official Google Tag Manager Template, and how to trigger AnyTrack events through your existing GTM triggers for eCommerce platforms not natively integrated with AnyTrack.

Google Tag Manager (GTM) is a tag management system that lets you deploy and manage tracking tags on your website from an easy-to-use web-based interface.

You can install AnyTrack via the official [Google Tag Manager Template](https://tagmanager.google.com/gallery/#/owners/anytrack/templates/google-tag-manager-template) available in the Google Tag Manager Template Gallery.

<Image align="center" border={true} src={readmeAsset1} className="border" />

<Prerequisites
  title="Before you begin"
  items={[
    { label: "You have a Google Tag Manager account", done: true },
    { label: "You have an AnyTrack account", done: true },
    { label: "You have your AnyTrack Property ID ready", done: true },
  ]}
/>

### How AnyTrack Compares to Google Tag Manager

If you're currently using Google Tag Manager, you know that you need to configure various triggers that will fire your tags according to the events you want to track.

Depending on the complexity of your setup, these triggers can be hard to configure.

With AnyTrack, event tracking functions such as outbound clicks and form submissions are automatically triggered and the variables associated with these events are automatically captured and sent to the AnyTrack servers.

## Install AnyTrack GTM Template

Watch the video tutorial or follow the step-by-step guide to install the AnyTrack GTM Template.

<Embed url="https://www.youtube.com/watch?v=tHjvobfi_-M" href="https://www.youtube.com/watch?v=tHjvobfi_-M" typeOfEmbed="youtube" html="%3Ciframe%20class%3D%22embedly-embed%22%20src%3D%22%2F%2Fcdn.embedly.com%2Fwidgets%2Fmedia.html%3Fsrc%3Dhttps%253A%252F%252Fwww.youtube.com%252Fembed%252FtHjvobfi_-M%253Ffeature%253Doembed%26display_name%3DYouTube%26url%3Dhttps%253A%252F%252Fwww.youtube.com%252Fwatch%253Fv%253DtHjvobfi_-M%26image%3Dhttps%253A%252F%252Fi.ytimg.com%252Fvi%252FtHjvobfi_-M%252Fhqdefault.jpg%26key%3D7788cb384c9f4d5dbbdbeffd9fe4b92f%26type%3Dtext%252Fhtml%26schema%3Dyoutube%22%20width%3D%22854%22%20height%3D%22480%22%20scrolling%3D%22no%22%20title%3D%22YouTube%20embed%22%20frameborder%3D%220%22%20allow%3D%22autoplay%3B%20fullscreen%3B%20encrypted-media%3B%20picture-in-picture%3B%22%20allowfullscreen%3D%22true%22%3E%3C%2Fiframe%3E" />

1. ### Navigate to [Google Tag Manager](https://tagmanager.google.com)
2. ### Click on the "New" button to add tag

<Image align="center" border={true} src={readmeAsset2} className="border" />

3. ### Click on the TAG icon to select a Tag

<Image align="center" border={true} src={readmeAsset3} className="border" />

4. ### Click on the Community Template Gallery option

<Image align="center" border={true} src={readmeAsset4} className="border" />

5. ### Search for the AnyTrack Template

<Image align="center" border={true} src={readmeAsset5} className="border" />

6. ### Select the "AnyTrack Tracking Tag"

![Click on ](./qlcuxecgsnri7ji6jsuvmc-doc-76e666899b.png)

7. ### Click on the "Add to workspace" button.

<Image align="center" border={true} src={readmeAsset6} className="border" />

8. ### Click on the "Add" Button

By clicking on the Add button you confirm your selection.

<Image align="center" border={true} src="/assets/docs/google-tag-manager/guidde-add-button.png" className="border" />

9. ### Switch to AnyTrack Property Settings
   Locate the property ID and copy it to your clipboard (ctrl+c)

<Image align="center" border={true} src="/assets/docs/google-tag-manager/guidde-property-settings.png" className="border" />

10. ### Switch to Google Tag Manager
    Switch to the AnyTrack Tag Configuration

<Image align="center" border={true} src="/assets/docs/google-tag-manager/guidde-tag-configuration.png" className="border" />

11. ### Now Paste the Property ID
    Now paste the Property ID in the selected field.

<Image align="center" border={true} src={readmeAsset10} className="border" />

12. ### Click on Add Trigger
    Now Click on Add Trigger configure the rule that will load the AnyTrack tag.

![Click on Add Trigger](./fe9odig8n5jugmzzhxbeln-doc-b593ea303d.png)

13. ### Select All Page Views
    Select the "All Pages" option so that the AnyTrack tag will load on every page where your container loads.

![Select All Page Views](/assets/docs/google-tag-manager/guidde-all-page-views.png)

14. ### Save the Tag

Now Save the AnyTrack Tag.

<Image align="center" border={true} src={readmeAsset11} className="border" />

15. ### Submit your container

<Image align="center" border={true} src={readmeAsset12} className="border" />

16. ### Click on the "Publish" button

<Image align="center" border={true} src={readmeAsset13} className="border" />

17. ### Save the new Container Version
    Update the Container version name and description if you wish to and Click on Continue.

<Image align="center" border={true} src="/assets/docs/google-tag-manager/guidde-container-version.png" className="border" />

## Video Tutorial: Install AnyTrack Tag via GTM

Watch this video for another detailed overview of how to install the AnyTrack Tag on your website using a Google Tag Manager container and trigger.

<Embed url="https://www.youtube.com/watch?v=1NhLjzRMFLk" href="https://www.youtube.com/watch?v=1NhLjzRMFLk" typeOfEmbed="youtube" html="%3Ciframe%20class%3D%22embedly-embed%22%20src%3D%22%2F%2Fcdn.embedly.com%2Fwidgets%2Fmedia.html%3Fsrc%3Dhttps%253A%252F%252Fwww.youtube.com%252Fembed%252F1NhLjzRMFLk%26display_name%3DYouTube%26url%3Dhttps%253A%252F%252Fwww.youtube.com%252Fwatch%253Fv%253D1NhLjzRMFLk%26image%3Dhttp%253A%252F%252Fi.ytimg.com%252Fvi%252F1NhLjzRMFLk%252Fhqdefault.jpg%26type%3Dtext%252Fhtml%26schema%3Dyoutube%22%20width%3D%22854%22%20height%3D%22480%22%20scrolling%3D%22no%22%20title%3D%22YouTube%20embed%22%20frameborder%3D%220%22%20allow%3D%22autoplay%3B%20fullscreen%3B%20encrypted-media%3B%20picture-in-picture%3B%22%20allowfullscreen%3D%22true%22%3E%3C%2Fiframe%3E" />

***

## Trigger AnyTrack Events via GTM

If you use an eCommerce platform that is not natively integrated with AnyTrack but already pushes eCommerce events to the GTM `dataLayer`, you can use your existing GTM triggers to fire AnyTrack event snippets. This lets you send [standard events](/docs/standard-events) like `Purchase`, `AddToCart`, or `ViewContent` to AnyTrack without writing any additional tracking code on your site.

### When to Use This Approach

Use GTM to trigger AnyTrack events when your eCommerce platform already emits `dataLayer` events through GTM, but does not have a built-in AnyTrack integration. Common examples include:

* Shopware
* BigCommerce
* Adobe Commerce (Magento)
* PrestaShop
* Any platform with a GTM eCommerce `dataLayer` implementation

If AnyTrack already has a native integration for your platform (such as Shopify or WooCommerce), use that instead. Native integrations handle event tracking and attribution automatically.

### How It Works

Your GTM container already has triggers that fire when eCommerce events occur (for example, when a purchase completes). You create a new Custom HTML tag that calls the AnyTrack event snippet, and attach it to those same triggers. AnyTrack receives the event with all the [event attributes](/docs/event-attributes) you pass, then forwards the conversion data to your connected ad platforms.

> ❗ **Important**
>
> The AnyTrack Tracking Tag must load before any event snippet fires. If the Tracking Tag has not loaded yet, the `AnyTrack()` function will not be available and the event will not be tracked. Use GTM tag sequencing to guarantee the correct load order.

### Step 1: Set Up Tag Sequencing

Tag sequencing tells GTM to fire the AnyTrack Tracking Tag before your event snippet tag. This is required because the event snippet depends on the `AnyTrack()` function that the Tracking Tag loads.

1. Open the Custom HTML tag that will contain your AnyTrack event snippet (created in Step 2 below)
2. Scroll down to **Advanced Settings** and expand **Tag Sequencing**
3. Check **"A tag that fires before [this tag]"**
4. Select your **AnyTrack Tracking Tag** from the dropdown
5. Check **"Don't fire [this tag] if the setup tag fails or is paused"**

This ensures the Tracking Tag is fully loaded before the event snippet runs.

### Step 2: Create the Event Snippet Tag

Create a new **Custom HTML** tag in GTM that calls the AnyTrack event snippet. Use the [standard event names](/docs/standard-events) that AnyTrack supports, such as `Purchase`, `AddToCart`, `InitiateCheckout`, or `ViewContent`.

Map your existing GTM `dataLayer` variables to [AnyTrack event attributes](/docs/event-attributes) using GTM variable references (`{{variable_name}}`).

**Example: Purchase Event**

```html
<script>
  AnyTrack('trigger', 'Purchase', {
    value: {{dlv - transaction total}},
    currency: {{dlv - currency}},
    transactionId: {{dlv - transaction id}},
    email: {{dlv - customer email}},
    items: {{dlv - items array}}
  });
</script>
```

Replace the `{{dlv - ...}}` placeholders with the actual GTM variable names from your `dataLayer` configuration. For example, if your platform pushes the total purchase value to a variable called `ecommerce.purchase.value`, create a Data Layer Variable in GTM for that path and reference it here.

**Example: AddToCart Event**

```html
<script>
  AnyTrack('trigger', 'AddToCart', {
    items: {{dlv - items array}},
    value: {{dlv - item value}},
    currency: {{dlv - currency}}
  });
</script>
```

**Example: ViewContent Event**

```html
<script>
  AnyTrack('trigger', 'ViewContent', {
    items: {{dlv - items array}}
  });
</script>
```

### Step 3: Attach Your Existing Triggers

Attach the same triggers you already use for your eCommerce tracking. For example, if you have a trigger that fires on the `purchase` dataLayer event, use that same trigger for your AnyTrack Purchase event snippet tag.

There is no need to create new triggers. The triggers you already have in your GTM container for events like `purchase`, `add_to_cart`, or `view_item` work with the AnyTrack event snippet tags.

### Step 4: Test and Publish

1. Open GTM **Preview** mode and complete a test transaction on your site
2. Verify in the GTM debugger that the AnyTrack Tracking Tag fires before the event snippet tag
3. Check the [AnyTrack Event Log](/docs/integration-event-log) in your dashboard for the incoming event
4. Install the [AnyTrack Pixel Helper](https://chromewebstore.google.com/detail/anytrack-pixel-helper/ojmhkmdpagjeopleoeihbhgejcfoijjn) Chrome extension to confirm events fire in the browser
5. Once verified, **Submit** and **Publish** your GTM container

### Supported Standard Events

You can trigger any [standard event](/docs/standard-events) through GTM. The most common eCommerce events are:

| Event Name         | When to Trigger    | Required Attributes                           |
| :----------------- | :----------------- | :-------------------------------------------- |
| `ViewContent`      | Product page view  | `items` (with product `id` and `price`)       |
| `AddToCart`        | Item added to cart | `items`, `value`, `currency`                  |
| `InitiateCheckout` | Checkout started   | `items`, `value`, `currency`                  |
| `Purchase`         | Order completed    | `value`, `currency`, `transactionId`, `items` |

For the full list of supported event attributes, including customer data (email, name, phone) and product data (id, name, price, quantity), see the [Event Attributes](/docs/event-attributes) documentation.

***

## GTM Tips and Tricks

### Retrieve the `atclid` and Push It to the dataLayer

Use this snippet to capture the AnyTrack click ID and make it available as a GTM variable. You can then use it to decorate forms, links, or pass it to other tags.

```javascript
<script>
(function checkAtclid(attempts) {
  if (typeof AnyTrack === 'function' && typeof AnyTrack.q === 'undefined') {
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
      event: 'atclid_ready',
      atclid: AnyTrack('atclid')
    });
  } else if (attempts < 50) {
    setTimeout(function() {
      checkAtclid(attempts + 1);
    }, 100);
  }
})(0);
</script>
```

***

## Validation

<Callout icon="🔎" theme="default">
  ### Install the AnyTrack Pixel Helper Extension

  Install the [AnyTrack Pixel Helper](https://chromewebstore.google.com/detail/anytrack-pixel-helper/ojmhkmdpagjeopleoeihbhgejcfoijjn) Chrome extension to verify the AnyTrack Tag is installed on your website. It also shows connected ad platforms and browser-side events. [View the Pixel Helper guide](/docs/anytrack-chrome-extension).
</Callout>

***

<FaqAccordion
  title="FAQ and Troubleshooting"
  icon="fa-duotone fa-circle-question"
  items={[
    {
      question: "Do I need to disable my current Facebook, Google Ads, and other tracking tags?",
      answer: "Yes. Disable the tags for any ad platform you have connected in your AnyTrack account. AnyTrack loads those tags on your behalf, so keeping them active would create duplicate events."
    },
    {
      question: "Do I need to create triggers for standard events like AddToCart or FormSubmit?",
      answer: "It depends on the platform. If your platform has a native AnyTrack integration (like Shopify), AnyTrack tracks standard events automatically. If you are using a platform without a native integration, use your existing GTM triggers to fire the AnyTrack event snippet as described in the Trigger AnyTrack Events via GTM section above."
    },
    {
      question: "How do I test my GTM implementation?",
      answer: "Use the GTM Preview mode to step through your tags and verify firing order. Then check the AnyTrack Event Log in your dashboard to confirm events are arriving. The <a href='/docs/anytrack-chrome-extension'>AnyTrack Pixel Helper</a> Chrome extension also shows browser-side events in real time."
    },
    {
      question: "When should I use GTM to trigger AnyTrack events instead of a native integration?",
      answer: "Use GTM when your eCommerce platform does not have a built-in AnyTrack integration but already emits eCommerce events to the GTM dataLayer. Platforms like Shopware, BigCommerce, Adobe Commerce (Magento), and PrestaShop are common examples. If a native AnyTrack integration exists for your platform, use that instead."
    },
    {
      question: "Can I pass dataLayer variables to the AnyTrack event snippet?",
      answer: "Yes, and it is recommended. Map your GTM dataLayer variables to <a href='/docs/event-attributes'>AnyTrack event attributes</a> like value, currency, transactionId, email, and items. Use the standard GTM variable syntax (double curly braces) in your Custom HTML tag."
    },
    {
      question: "Why is my AnyTrack event snippet not firing?",
      answer: "The most common cause is that the AnyTrack Tracking Tag has not loaded before the event snippet fires. Set up tag sequencing in GTM so the Tracking Tag fires first. Open GTM Preview mode and verify the Tracking Tag appears before your event snippet in the firing order."
    },
    {
      question: "What standard events can I trigger through GTM?",
      answer: "You can trigger any AnyTrack <a href='/docs/standard-events'>standard event</a> through GTM, including Purchase, AddToCart, InitiateCheckout, ViewContent, Lead, and more. Use the exact event names from the standard events documentation."
    },
    {
      question: "Can I trigger custom events through GTM?",
      answer: "Yes. If you have custom events that are not part of the standard event list, you can trigger them the same way. Use a Custom HTML tag with the AnyTrack event snippet and pass your custom event name. For example: AnyTrack('trigger', 'MyCustomEvent'). Attach it to whatever GTM trigger fits your use case."
    }
  ]}
/>
