> ## 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.

# Attribution

> How WisePilot tracks visitors from content view through CTA click to form submission.

Attribution is the backbone of WisePilot's optimization system. It links every form submission back to the content and CTA that drove it, giving you clear visibility into what's converting.

## How Attribution Works

### The Attribution ID (`cr_attrib`)

Every visitor gets a unique `cr_attrib` UUID when they arrive on your site. This ID follows them through the entire funnel:

1. **Page visit** — The attribution script generates and stores `cr_attrib` in a cookie and localStorage
2. **CTA view** — The script detects when a CTA enters the viewport (50% visible) and records a `cta_view` event
3. **CTA click** — The script captures clicks on CTA elements and records a `cta_click` event
4. **Link rewrite** — The script appends `cr_attrib` as a URL parameter on the CTA's destination link
5. **Form submission** — HighLevel captures `cr_attrib` from the URL or injected hidden field
6. **Webhook** — HighLevel sends the form submission (including `cr_attrib`) back to WisePilot
7. **Join** — WisePilot links the form submission to the original CTA click, content asset, and visitor session

### The Attribution Script

The script (`attribution-tracker.js` v3.0) is bundled in the [WisePilot WordPress plugin](/integrations/wordpress) and handles:

* Generating and persisting the `cr_attrib` cookie (90-day expiry)
* Rewriting CTA links to append `cr_attrib` and UTM parameters (idempotent)
* Tracking CTA views via IntersectionObserver (50% visibility threshold, fires once per element)
* Tracking CTA clicks via event delegation (capture phase)
* Posting events directly to the WisePilot API via `navigator.sendBeacon()` with `fetch()` fallback
* Batching view events (1-second debounce, up to 50 per batch)
* Flushing events on page unload (`visibilitychange` / `pagehide`)
* Injecting `cr_attrib` into GHL inline forms and iframe forms
* Firing GA4 custom events (`cta_view`, `cta_click`) if `window.gtag` is available

### Event Delivery

Events are posted directly to `POST /api/integrations/cr/events` — no GTM middleman. The request is authenticated by a per-site `tracking_token` (auto-generated when you download the plugin).

```
Plugin JS -> sendBeacon/fetch -> /api/integrations/cr/events -> tracking_events table
```

Events are rate-limited (100 requests/min per website) and deduplicated by `source_event_id`.

### GA4 Dual-Write

If GA4 is installed on your site (i.e., `window.gtag` exists), the attribution script automatically fires `cta_view` and `cta_click` as GA4 custom events. No configuration needed — if gtag is on the page, events fire. You'll see them in GA4 DebugView and reports.

## What Gets Linked

Once attribution is working, WisePilot can tell you:

| Question                                 | Data Source                                |
| ---------------------------------------- | ------------------------------------------ |
| Which content asset did this lead see?   | `page_path` + asset resolution             |
| Which CTA did they click?                | `cta_id` + `cta_position`                  |
| Where did the form submission originate? | `cr_attrib` link to CTA click              |
| What was the conversion path?            | Full session: view -> click -> submit      |
| Did they book?                           | GHL contact -> conversation -> appointment |

## The Full Funnel

The attribution funnel joins data from multiple sources:

```
GSC Impressions -> GSC Clicks -> GA4 Page Views -> CTA Views -> CTA Clicks -> Form Fills -> Contacts -> Conversations -> Bookings
     (GSC)          (GSC)         (GA4)           (plugin)     (plugin)      (GHL wh)      (GHL sync)  (GHL sync)      (GHL sync)
```

View this funnel on the [CTA Performance report](/reports/cta-performance).

## Privacy

Attribution operates with configurable privacy modes:

* **Strict (default)** — Nulls referrer and click IDs immediately after join
* **Standard** — Retains data with retention caps
* **Debug** — Full data retention, auto-expires after 7 days

Configure privacy mode in your website settings.
