> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Add Tracking Codes and Third-Party Scripts

## Article: Add Tracking Codes and Third-Party Scripts

## Article Link: https://dev.wix.com/docs/api-reference/business-management/marketing/skills/add-tracking-codes-and-third-party-scripts.md

## Article Content:

# Add Tracking Codes and Third-Party Scripts

Code from an outside service goes into the site through one of two public APIs:

- [Custom Embeds](https://dev.wix.com/docs/api-reference/business-management/custom-embeds/introduction.md): any HTML snippet, shown in the dashboard under Custom Code.
- [Marketing Tags](https://dev.wix.com/docs/api-reference/business-management/marketing/marketing-tags.md): a tracking ID for a supported service, shown under Marketing Integrations.

Either way, the code runs on every page, including pages added later, loads according to the visitor's cookie consent, and the owner can turn it off without editing the site. A snippet pasted into page files does none of this: it runs for every visitor whatever their consent, and the owner cannot see it in the dashboard.

Every call below is complete and was run as written: send it without looking up its schema first.

## Pick the API

| The user gives | Use |
|---|---|
| A tracking ID for Google Analytics (`G-…`), Google Tag Manager (`GTM-…`), Google Ads (`AW-…`), Meta Pixel, TikTok Pixel or Yandex Metrica, on a premium site | Marketing Tags (Step 3a) |
| The same, on a free site | A custom embed with the service's snippet (Step 3b). Marketing Tags answers `428 NOT_A_PREMIUM_SITE` on a free site. |
| Any other snippet: a chat widget, a heatmap, a verification meta tag, an ad network | A custom embed (Step 3b) |

Not covered here, because it is not site-wide code from an outside service:

- A widget for one page (a booking calendar on Contact, a map, an embedded form). The API cannot target pages (`pageFilter` is read-only), so it goes in that page.
- The site's own behavior: menus, animations, form handling.
- An event the site's own code reports, such as a conversion when a form is sent. See [Conversion events](#conversion-events).

## Step 1: Read what the site already has

Read both lists before adding anything. When the service is already there, change that entry (Step 4) instead of adding a second copy, which would count every visit twice.

```bash
curl -X GET 'https://www.wixapis.com/embeds/v1/custom-embeds' \
  -H 'Authorization: <AUTH>'
```

Returns `customEmbeds[]`, each with `id`, `revision`, `name`, `enabled`, `position`, `embedData.category` and `embedData.html`, and `pagingMetadata.hasNext`.

```bash
curl -X GET 'https://www.wixapis.com/marketing/v1/tags' \
  -H 'Authorization: <AUTH>'
```

Returns `tags[]`, each with `id`, `type` (`GOOGLE_ANALYTICS`, `GOOGLE_TAG_MANAGER`, `GOOGLE_ADS`, `FACEBOOK_PIXEL`, `TIKTOK_PIXEL`, `YANDEX_METRICA`, …), `enabled`, and an object for its type holding `trackingId`. `tags: []` means no marketing integration is connected.

To find a service in custom embeds, search `embedData.html` for its ID (`fbq('init', '<pixel id>')`, `gtag/js?id=G-…`, `gtm.js?id=GTM-…`).

## Step 2: Confirm what will be added

Adding code changes the live site. A request that hands over the snippet or ID and asks to add or change it is the go-ahead. In any other case, such as tracking the user did not paste, or an entry the user did not mention that the change would replace, tell the user the service, the name the dashboard will show and the consent category from Step 3b, and wait for a yes before Step 3.

## Step 3a: Connect a marketing tag

[Upsert Marketing Tag](https://dev.wix.com/docs/api-reference/business-management/marketing/marketing-tags/upsert-marketing-tag.md). The tag holds one object, named for its type: `googleAnalytics`, `googleTagManager`, `googleAds`, `facebookPixel`, `tikTokPixel` or `yandexMetrica`.

```bash
curl -X POST 'https://www.wixapis.com/marketing/v1/tags' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  -d '{
    "tag": {
      "enabled": true,
      "facebookPixel": {
        "trackingId": "<pixel id>",
        "domain": "<site hostname>"
      }
    }
  }'
```

- `domain` is required in practice: without it the call answers `400` "domain is not a valid hostname". Use the hostname of the site's primary URL, without `https://`, from [List Published Site URLs](https://dev.wix.com/docs/api-reference/business-management/site-urls/published-site-urls/list-published-site-urls.md) (`GET https://www.wixapis.com/urls-server/v2/published-site-urls`, the entry with `primary: true`).
- A free site answers `428` with `NOT_A_PREMIUM_SITE`. Go to Step 3b with the service's own snippet.
- A site holds one tag per type (list and delete both work by type), so upserting a new Meta Pixel ID replaces the old one.

## Step 3b: Add a custom embed

[Create Custom Embed](https://dev.wix.com/docs/api-reference/business-management/custom-embeds/create-custom-embed.md). Pass the snippet exactly as the service gives it, `<script>` and `<noscript>` tags included. A snippet holds both `'` and `"`: put it into the request body as a JSON-encoded string value, not between quotes in code, where its own quotes end the string.

```bash
curl -X POST 'https://www.wixapis.com/embeds/v1/custom-embeds' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  -d '{
    "customEmbed": {
      "name": "Meta Pixel",
      "enabled": true,
      "position": "HEAD",
      "embedData": {
        "category": "ADVERTISING",
        "html": "<script>!function(f,b,e,v,n,t,s){…}(window, document,\"script\",\"https://connect.facebook.net/en_US/fbevents.js\");fbq(\"init\", \"<pixel id>\");fbq(\"track\", \"PageView\");</script>"
      }
    }
  }'
```

Returns `customEmbed.id` and `customEmbed.revision`, which Step 4 needs.

`embedData.category` decides when the code loads:

| Category | For | Loads |
|---|---|---|
| `ESSENTIAL` | Code the site cannot work without: a verification meta tag, a font, a library the pages call | Always. In the page's HTML as served, except on a static upload, where the browser adds it ([Wix Headless sites](#wix-headless-sites)) |
| `FUNCTIONAL` | Chat widgets, social feeds, review badges | After the page, if the visitor's consent allows it |
| `ANALYTICS` | Google Analytics, Tag Manager, heatmaps, session recording | After the page, if consent allows it |
| `ADVERTISING` | Meta Pixel, TikTok Pixel, Google Ads, ad networks, retargeting | After the page, if consent allows it |
| `DATA_TO_THIRD_PARTY` | Code that sends visitor data to an outside system, such as a CRM | After the page, if consent allows it |

Tracking, analytics and advertising code is never `ESSENTIAL`: that category loads whatever the visitor chose.

| Field | Values |
|---|---|
| `position` | `HEAD`, `BODY_START` or `BODY_END`. Use the place the service's instructions name; `HEAD` when they say "in the `<head>`". |
| `name` | 1-100 characters, shown in the dashboard. Name the service. |
| `embedData.html` | Up to 15,000 characters. For a longer script, embed a `<script src="…">` that loads it from the service's own URL. |
| `loadOnce` | Default `true`: loaded once per visit, not on every page change. |
| `enabled` | Default `true`. |

The code runs on every page of the site from the next page view.

## Step 4: Change or turn off

[Update Custom Embed](https://dev.wix.com/docs/api-reference/business-management/custom-embeds/update-custom-embed.md) takes the current `revision` from Step 1 and the fields that change; the fields left out keep their values. `embedData` is sent whole: an `html` without its `category` answers `400` "category value is required". An outdated `revision` answers `409` `INVALID_REVISION`; read the embed again and use its `revision`.

To change the code, such as a new measurement ID, send the full new `html` with its `category`:

```bash
curl -X PATCH 'https://www.wixapis.com/embeds/v1/custom-embeds/<custom embed id>' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  -d '{
    "customEmbed": {
      "id": "<custom embed id>",
      "revision": "<current revision>",
      "embedData": {
        "category": "ANALYTICS",
        "html": "<script async src=\"https://www.googletagmanager.com/gtag/js?id=<new id>\"></script><script>window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag(\"js\", new Date()); gtag(\"config\", \"<new id>\");</script>"
      }
    }
  }'
```

To turn code off without removing it:

```bash
curl -X PATCH 'https://www.wixapis.com/embeds/v1/custom-embeds/<custom embed id>' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  -d '{
    "customEmbed": {
      "id": "<custom embed id>",
      "revision": "<current revision>",
      "enabled": false
    }
  }'
```

To change a marketing tag's ID, upsert it again (Step 3a). [Delete Marketing Tag](https://dev.wix.com/docs/api-reference/business-management/marketing/marketing-tags.md) removes one by type: `DELETE https://www.wixapis.com/marketing/v2/tags?tagType=FACEBOOK_PIXEL`.

## Conversion events

An event tied to the site itself, such as a lead when a form is sent or a call when a phone link is tapped, is a line in the site's own code that calls the function the tag loaded: `fbq('track', 'Lead')`, or `gtag('event', 'conversion', { send_to: '<AW-…/label>' })`. Add the tag first (Step 3a or 3b); the event code does not load it.

When consent keeps the tag from loading, `fbq` and `gtag` are undefined, so the call checks first:

```js
if (typeof window.fbq === "function") window.fbq("track", "Lead");
```

## How consent applies

- `ESSENTIAL` code always loads.
- Before a visitor makes a choice, the site's default policy applies. With no cookie banner on the site, it allows every category, and all enabled code loads.
- On a Wix Headless site, a visitor who rejected any category gets none of the non-essential code, including the categories they accepted.

## Wix Headless sites

Custom embeds reach a headless page through the Wix site scripts:

- A Wix-managed Astro site serves them with every page.
- A static upload loads them in the browser through the loader tag the upload adds to each HTML page: `<script id="wix-site-script" …>`. A page without that tag runs none of the site's custom code.

On a static upload, `ESSENTIAL` code arrives through the loader as well, so it is not in the HTML the server sends. A check that reads the raw page without running JavaScript, such as a domain verification, does not find a meta tag added this way: put that tag in the page's own `<head>` instead and upload the page again.