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

# SKILL

> Install the Thrad browser tag on an advertiser's website, wire its events and purchase conversion so Thrad and OpenAI ad traffic is attributed, then offer server events. Triggers on "Thrad tag", "thradTag", "tag.min.js", "adv_ tag ID", "Thrad attribution", "Thrad pixel", "track conversions for Thrad ads", "install the Thrad tag".

# Thrad Tag

This skill installs the **Thrad browser tag** on an advertiser's website: one loader in the page `<head>`, the events the site should report, and the purchase conversion on the order confirmation. It is the advertiser side of Thrad. It has nothing to do with serving ads.

The server-side companion is the `thrad-conversions-api` skill ([https://docs.thrads.ai/skills/thrad-conversions-api/SKILL.md](https://docs.thrads.ai/skills/thrad-conversions-api/SKILL.md)). Install the tag first. Once it works, this skill's last step recommends server events to the user and, if they agree, hands off to that skill in the same session.

Before using any documentation URL, fetch and read the LLM-friendly docs sitemap:

[https://docs.thrads.ai/llms.txt](https://docs.thrads.ai/llms.txt)

Use the sitemap to locate the latest canonical page for each topic. Prefer sitemap-discovered URLs over the hardcoded ones below if they differ.

## When to use this skill

* "Install the Thrad tag on my site"
* "Set up Thrad attribution"
* "Track purchases from Thrad ads"
* "Add a Thrad conversion to my checkout"
* "My Thrad dashboard says no events received"

## Procedure

### Step 1 — Get the tag ID

Ask the user for their **tag ID** unless they already gave it. It looks like `adv_<name>_<id>`, and it is shown in the Thrad platform on the ad account's **Attribution** page: [https://platform.thrad.ai](https://platform.thrad.ai)

The tag ID is public: it ships in the page and is not a secret. Never leave `<YOUR_TAG_ID>` in code the user will deploy.

The prompt copied from the **Attribution** page may also include a **setup code** that starts with `tsc_`. Keep it for Step 8. It only lets you run Thrad's site check for this ad account and expires after 24 hours. Don't write it into the codebase, a config file or a commit. If there's no setup code, skip Step 8's API calls and send the user to the platform instead.

### Step 2 — Find out how the site is built

Look at the project before writing anything. Decide which one of these paths applies, and tell the user which you chose:

| What you find | Path |
| - | - |
| A Shopify theme (`layout/theme.liquid`, `sections/`, `shopify.theme.toml`) or a headless Shopify storefront | Follow the Shopify guide: [https://docs.thrads.ai/advertisers/attribution/tag/guides/shopify.md](https://docs.thrads.ai/advertisers/attribution/tag/guides/shopify.md) |
| Google Tag Manager already loads the site's other tags (`googletagmanager.com/gtm.js`) and the user wants Thrad there | Follow the GTM guide: [https://docs.thrads.ai/advertisers/attribution/tag/guides/google-tag-manager.md](https://docs.thrads.ai/advertisers/attribution/tag/guides/google-tag-manager.md) |
| A site builder with no code in the repo (Framer, Webflow, Wix, Squarespace) | Give the user the exact snippet and where to paste it. Framer: [https://docs.thrads.ai/advertisers/attribution/tag/guides/framer.md](https://docs.thrads.ai/advertisers/attribution/tag/guides/framer.md) |
| Anything else with a shared layout (Next.js, React, Vue, Svelte, Astro, Rails, Django, Laravel, WordPress, plain HTML) | Install the loader directly, as below. |

GTM containers and site builders live outside the repo, so you can't edit them. On those paths, write the snippets and the dataLayer pushes the site needs, then give the user numbered steps to finish in GTM or the builder.

### Step 3 — Read the reference

Fetch these, in this order:

* Install: [https://docs.thrads.ai/advertisers/attribution/tag/install.md](https://docs.thrads.ai/advertisers/attribution/tag/install.md)
* Track events: [https://docs.thrads.ai/advertisers/attribution/tag/events.md](https://docs.thrads.ai/advertisers/attribution/tag/events.md)
* Track purchases: [https://docs.thrads.ai/advertisers/attribution/tag/conversions.md](https://docs.thrads.ai/advertisers/attribution/tag/conversions.md)

### Step 4 — Install the loader once, on every page

Paste the loader just before `</head>` in the site's **shared layout**, so it runs on every page. It is the same snippet the Thrad platform shows on the **Attribution** page, with the real tag ID in place of `adv_example_123`:

```html theme={null}
<!-- Thrad Tag -->
<script>
  window.thradTag = window.thradTag || function () {
    (window.thradTag.q = window.thradTag.q || []).push(arguments);
  };
  window.thradTag("set", {
    tag_id: "adv_example_123",
    channel: "web"
  });
  if (!window.__thradPageViewQueued) {
    window.__thradPageViewQueued = true;
    window.thradTag("event", "page_viewed");
  }
</script>
<script async src="https://cdn.thrad.ai/tag.min.js"></script>
```

Where it goes in common stacks:

* **Next.js App Router:** `app/layout.tsx`, as two `next/script` tags: an inline one with `id="thrad-tag"` and `strategy="afterInteractive"` holding the stub, `set` call and page view, and one with `async src="https://cdn.thrad.ai/tag.min.js"`. Pages Router: `pages/_document.tsx` or `pages/_app.tsx`.
* **React / Vite / CRA:** `index.html` `<head>`. Not inside a component that re-renders.
* **WordPress:** a `wp_head` action in the child theme's `functions.php`, so a theme update can't remove it.
* **Server templates (Rails, Django, Laravel, Express views):** the base layout's `<head>`.

Rules:

* **Exactly one loader per page.** Search for `tag.min.js` and `thradTag("set"` first. If a Thrad loader already exists, update it instead of adding a second.
* Keep `tag.min.js` loaded from `https://cdn.thrad.ai`. Don't self-host or bundle it.
* **Keep the `__thradPageViewQueued` guard.** It stops a re-run of the loader from counting the same page view twice.
* **Single-page apps:** the loader sends the first page view. For client-side route changes, call `window.thradTag("event", "page_viewed")` from the router's navigation hook, once per navigation.
* If the site has a consent manager, load or enable the tag the same way its other measurement tags are gated. Don't bypass consent.

### Step 5 — Report the actions that matter

Ask the user which actions count as success for their campaigns, then find where each one *completes* in the code. Prefer the success callback or the confirmation page over the button click.

Use the standard names from the events reference:

| Action | Call |
| - | - |
| Product or content viewed | `window.thradTag("event", "contents_viewed", { content_id, content_type })` |
| Added to cart | `window.thradTag("event", "items_added", { content_id, quantity, value, currency })` |
| Checkout started | `window.thradTag("event", "checkout_started", { value, currency })` |
| Lead form submitted | `window.thradTag("event", "lead_created", { event_id })` |
| Account registered | `window.thradTag("event", "registration_completed", { event_id })` |
| Meeting booked | `window.thradTag("event", "appointment_scheduled", { event_id })` |
| Trial or subscription started | `trial_started` / `subscription_created` |

* A lead, signup or booking needs a **stable opaque `event_id`** from that submission, such as `lead:<submission id>`. Reuse it if the same submission is reported again. Never put an email, name or phone number in it.
* Never send a lead or signup as a purchase.
* `value` is in **major currency units** (`58.00`, not `5800`) and `currency` is a three-letter ISO code.
* Read values from the app's real data. Never hard-code example values.

### Step 6 — Fire the purchase conversion

On the **order confirmation page only**, with values the backend rendered or returned for the finalized order:

```js theme={null}
window.thradTag("conversion", {
  order_id: order.id,
  value: order.total,
  currency: order.currency
});
```

* `order_id` is the **final order ID**. Never a cart, checkout or session token, and never a freshly generated ID.
* Fire it **once per order**. Guard against re-renders and reloads; the tag also dedupes on tag ID + order ID.
* Don't pass `event_id` here. The tag derives the purchase identity from the tag ID and order ID.
* Shopify checkout doesn't run your theme code. Its purchase comes from the checkout pixel in the Shopify guide, not from this call.
* If the site already reports purchases to Thrad from a server, stop and tell the user: the server and browser must share one purchase identity, which the `thrad-conversions-api` skill covers.

### Step 7 — Verify before declaring done

Do not tell the user the setup is complete until:

1. The site builds, and every page has exactly one `tag.min.js` request and one `thradTag("set", …)` with the real tag ID.
2. In the browser's Network tab, `https://cdn.thrad.ai/tag.min.js` loads with `200` and the tag fetches its config from `events.thrad.ai/v1/config/<tag ID>`.
3. Each event you wired fires once at the moment the action completes, with real values.
4. The conversion fires once on the confirmation page, with the final order ID, total and currency, and does not fire again on reload.

### Step 8 — Have Thrad confirm it after deploy

You can't deploy for the user. Tell them to deploy the change to the live site and to tell you when it's done. Then confirm with Thrad.

**With a setup code**, ask Thrad to check the live page. Use a page that carries the loader, usually the home page, at its public `https://` URL:

```bash theme={null}
curl -sS -X POST https://api.thrad.ai/v1/tag-setup/agent-checks/ \
  -H "Authorization: Bearer <setup code>" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://www.example.com/", "request_key": "check-7f3a9c2e"}'
```

Make up a new `request_key` (8 to 48 letters, digits, `-` or `_`) for each new check. If a request fails or times out before you get a response, send it again with the **same** key: Thrad returns the check that is already running instead of starting over.

The response is wrapped as `{"success": true, "data": {…}}`. Every five seconds, poll `data.status_url` with the same `Authorization` header until `data.done` is `true`. That usually takes under a minute. Stop after three minutes and tell the user the check is still running on the **Attribution** page.

When it's done:

* `data.passed` is `true`: tell the user Thrad found the tag on the page and received its test event.
* `data.passed` is `false`: tell the user `data.message` in plain words. If it points at something in this codebase, such as a loader that isn't on that page, fix it, then ask the user to deploy again and run a new check. Don't retry more than twice without the user.

A `400` with `SITE_NOT_CONFIGURED` means the URL isn't on one of the ad account's websites: use a page on the site the tag was set up for. A `401` means the code is wrong, expired, or the user no longer has edit access. Ask the user to copy a fresh prompt from the **Attribution** page, and don't ask for any other credential. A `429` means too many checks: wait and ask the user before trying again.

**Without a setup code**, tell the user to open the ad account's **Attribution** page in the Thrad platform and run the site check there (on the tabbed page, **Setup → Confirm your tracking**).

Either way, the site check proves the tag runs and reaches Thrad. A test purchase from a real ad click is the end-to-end check for the conversion.

### Step 9 — Recommend server events

Once the tag is done, recommend server events. Do it after Step 8's check, or after Step 7 if the user won't deploy yet. Ask once, plainly, and let the user decide.

**Look before you ask.** Find where the backend finalizes an order: the payment-succeeded webhook, the order-created handler, or the CRM stage change for a lead. Note the file and roughly how many lines the change needs, so the offer is concrete. Skip the offer, and say why in one sentence, when:

* The repo has no server code that finalizes orders, such as a site builder, a Shopify theme or a static site. Tell the user server events need a backend and link [https://docs.thrads.ai/advertisers/attribution/server-events/overview.md](https://docs.thrads.ai/advertisers/attribution/server-events/overview.md).
* The backend already sends events to `events.thrad.ai`. Tell the user server events are already set up.

**Make the case in plain words.** Recommend it clearly: it's the most useful thing left to do. Cover these points in your own words, without jargon:

* Today purchases are reported only from the shopper's browser. Ad blockers, browser tracking limits such as Safari's, and shoppers who close the tab before the confirmation page loads stop some of them from reaching Thrad. Those sales are never credited to the ads, and campaigns optimize on less data.
* With server events, the user's server also tells Thrad about each order. Thrad matches the browser and server copies by order ID, so nothing is counted twice.
* The change is small. Name the file you found and how many lines it needs.
* It needs one thing only the user can do: create a server token in Thrad. You will never ask for the token.

Don't put a number on the benefit, such as a percentage of sales recovered or a lift in results. Thrad doesn't publish one, so any figure you give would be made up.

Then ask: add server events now, not now, or tell me more.

* **Yes:** fetch [https://docs.thrads.ai/skills/thrad-conversions-api/SKILL.md](https://docs.thrads.ai/skills/thrad-conversions-api/SKILL.md) and follow it in full, in this same session. You already have the tag ID, so don't ask for it again. The code reads the token from `THRAD_SERVER_TOKEN` in the environment. When the change is in, tell the user to open the ad account's **Attribution** page in Thrad, choose **Create server token** (on some accounts the page still has tabs: there it is **Create token** under **Setup → Send conversions from your server**), and save the token as `THRAD_SERVER_TOKEN` wherever their server keeps secrets. Then deploy and place a test order, and the Attribution page shows when the first server event arrives (on the tabbed page, under **Status**).
* **Not now:** end cleanly. Say they can add server events any time from the Attribution page in Thrad, or by asking you again. Don't bring it up again in this session.
* **Tell me more:** explain what the server sends (the order ID, value and currency, plus the browser's attribution context, and a hashed email only if the user consented to measurement) and that it runs in the background so it can't slow down checkout. Then ask once more.

Never ask the user to paste the server token into the chat, and never write it into code, a committed file or a test fixture.

## Common gotchas

* **Two loaders** — a theme and a GTM container both installing the tag doubles every event. Keep one.
* **Conversion on the checkout button** — fire it on the confirmation, after the order exists.
* **Cart or checkout ID as `order_id`** — breaks deduplication with server events and Shopify.
* **Cents as `value`** — the browser tag takes major units. (The server API takes minor units; don't mix them up.)
* **Stripping URL parameters on landing** — redirects must keep `thrad_click_id`, `exp`, `sig` and `oppref` on the landing URL, or the visit can't be attributed.
* **Loader inside a component** — it re-runs on every render. Put it in the document head.
* **Inventing fields** — if a field isn't in the events or conversions reference, it doesn't exist.

## References

* Docs sitemap: [https://docs.thrads.ai/llms.txt](https://docs.thrads.ai/llms.txt)
* Install: [https://docs.thrads.ai/advertisers/attribution/tag/install.md](https://docs.thrads.ai/advertisers/attribution/tag/install.md)
* Track events: [https://docs.thrads.ai/advertisers/attribution/tag/events.md](https://docs.thrads.ai/advertisers/attribution/tag/events.md)
* Track purchases: [https://docs.thrads.ai/advertisers/attribution/tag/conversions.md](https://docs.thrads.ai/advertisers/attribution/tag/conversions.md)
* Server events skill: [https://docs.thrads.ai/skills/thrad-conversions-api/SKILL.md](https://docs.thrads.ai/skills/thrad-conversions-api/SKILL.md)
* Google Tag Manager: [https://docs.thrads.ai/advertisers/attribution/tag/guides/google-tag-manager.md](https://docs.thrads.ai/advertisers/attribution/tag/guides/google-tag-manager.md)
* Shopify: [https://docs.thrads.ai/advertisers/attribution/tag/guides/shopify.md](https://docs.thrads.ai/advertisers/attribution/tag/guides/shopify.md)
* Framer: [https://docs.thrads.ai/advertisers/attribution/tag/guides/framer.md](https://docs.thrads.ai/advertisers/attribution/tag/guides/framer.md)
* First-party proxy (optional): [https://docs.thrads.ai/advertisers/attribution/tag/first-party-proxy.md](https://docs.thrads.ai/advertisers/attribution/tag/first-party-proxy.md)
* Image pixel fallback (optional): [https://docs.thrads.ai/advertisers/attribution/tag/image-pixel.md](https://docs.thrads.ai/advertisers/attribution/tag/image-pixel.md)
* Thrad platform: [https://platform.thrad.ai](https://platform.thrad.ai)
* Site check API: `POST https://api.thrad.ai/v1/tag-setup/agent-checks/` and `GET …/agent-checks/<check_id>/`, authenticated with the setup code
* Support: [contact@thrad.ai](mailto:contact@thrad.ai)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.