> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wisepilot.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Tag Manager Setup

> Legacy GTM event tracking for CTA views and clicks. Replaced by plugin-native tracking in v3.0.

<Warning>
  **GTM is no longer required for CTA tracking.** Starting with plugin v3.0, the WisePilot WordPress plugin tracks CTA views and clicks directly and posts events to the WisePilot API. No GTM setup is needed.

  If you're setting up a new site, skip this page and follow the [WordPress plugin guide](/integrations/wordpress) instead.

  If you have an existing GTM setup, it will continue to work alongside the plugin. Events from both sources are deduplicated. You can safely remove your GTM CTA tags when ready.
</Warning>

## Legacy GTM Setup (Pre-v3.0)

The information below is preserved for sites still using GTM-based CTA tracking. For new installations, use the [WordPress plugin](/integrations/wordpress) instead.

***

Google Tag Manager (GTM) captures CTA view and click events on your website, sending them to WisePilot for attribution tracking. With plugin v3.0+, this is handled natively by the attribution tracker script.

## Prerequisites

* Google Tag Manager account with a container deployed to your website
* [Attribution script](/integrations/wordpress) already deployed on your site
* Access to your GTM workspace to create tags and triggers

## What GTM Did in the Pipeline

```
Visitor lands on page -> Attribution script sets cr_attrib cookie
    |
Visitor sees a CTA -> GTM fires cta_view event with cr_attrib
    |
Visitor clicks a CTA -> GTM fires cta_click event with cr_attrib
    |
Events sent to WisePilot -> Linked to form submissions via cr_attrib
```

**With plugin v3.0+**, the attribution script handles all of this directly. GTM is removed from the equation.

## Step 1: Create CTA View Event Tag

This tag fires when a CTA becomes visible on the page.

1. In GTM, create a new **Custom HTML** tag
2. Set the trigger to a Custom Event named `cta_view`
3. Add this HTML:

```html theme={null}
<script>
  dataLayer.push({
    'event': 'cta_view',
    'event_uuid': '{{Event UUID}}',
    'event_ts_ms': Date.now(),
    'attribution_id': window.getAttributionId ? window.getAttributionId() : null,
    'cta_id': '{{CTA ID}}',
    'cta_position': '{{CTA Position}}',
    'page_path': window.location.pathname,
    'asset_content_id': '{{Asset Content ID}}'
  });
</script>
```

<Note>Replace the `{{...}}` template variables with actual GTM variables that pull from your CTA data attributes (`data-cta-id`, `data-cta-position`, `data-asset-content-id`).</Note>

## Step 2: Create CTA Click Event Tag

This tag fires when a user clicks a CTA element.

1. Create a new **Custom HTML** tag
2. Set the trigger to click events on elements with `[data-cta-id]` or the `.cr-cta` class
3. Add this HTML:

```html theme={null}
<script>
  dataLayer.push({
    'event': 'cta_click',
    'event_uuid': '{{Event UUID}}',
    'event_ts_ms': Date.now(),
    'attribution_id': window.getAttributionId ? window.getAttributionId() : null,
    'cta_id': '{{CTA ID}}',
    'cta_position': '{{CTA Position}}',
    'page_path': window.location.pathname,
    'destination_url': '{{Click URL}}',
    'asset_content_id': '{{Asset Content ID}}'
  });
</script>
```

## Migrating Away from GTM

To migrate to plugin-native tracking:

1. Install the [WisePilot WordPress plugin v3.0+](/integrations/wordpress)
2. Verify events are arriving in WisePilot (check Network tab for `/api/integrations/cr/events`)
3. Once confirmed, remove your GTM CTA view and click tags
4. Keep GTM for other tracking needs (GA4 config, conversion tags, etc.)

Historical events from GTM (with `ingest_source: 'gtm'`) are preserved alongside new plugin events (`ingest_source: 'cr_plugin'`).

## Troubleshooting

### Events not arriving in WisePilot

1. **Check GTM container is deployed** — View your page source and verify the GTM snippet is present
2. **Check browser console** — Look for JavaScript errors that might prevent tags from firing
3. **Check network tab** — If using server-side, verify requests to `/api/integrations/gtm/events` are succeeding (200 status)
4. **Check ad blockers** — Some ad blockers prevent GTM from loading. Test in an incognito window with extensions disabled.

### Events arrive but attribution\_id is null

1. **Verify attribution script loads before GTM** — The script must set the cookie before GTM reads it
2. **Check `window.getAttributionId()`** — Open the console and call this function. If it returns `null`, the attribution script isn't running.
3. **Check cookies** — Look for `cr_attrib` in Application -> Cookies. If missing, the attribution script may be blocked.

### Events arrive but CTA fields are empty

* Verify your CTA elements have the required data attributes: `data-cta-id`, `data-cta-position`, `data-asset-content-id`
* Check that your GTM variables are correctly reading from these attributes
* Test with the GTM Preview panel to see what values the variables resolve to
