Add Tracking Codes and Third-Party Scripts

Download skillThe skill is a reference md and part of wix-manage skill. You can use the following command to add the full wix-manage skill to your project:
Copy

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

  • Custom Embeds: any HTML snippet, shown in the dashboard under Custom Code.
  • Marketing Tags: 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 givesUse
A tracking ID for Google Analytics (G-…), Google Tag Manager (GTM-…), Google Ads (AW-…), Meta Pixel, TikTok Pixel or Yandex Metrica, on a premium siteMarketing Tags (Step 3a)
The same, on a free siteA 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 networkA 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.

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.

Copy

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

Copy

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. The tag holds one object, named for its type: googleAnalytics, googleTagManager, googleAds, facebookPixel, tikTokPixel or yandexMetrica.

Copy
  • 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 (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. 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.

Copy

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

embedData.category decides when the code loads:

CategoryForLoads
ESSENTIALCode the site cannot work without: a verification meta tag, a font, a library the pages callAlways. In the page's HTML as served, except on a static upload, where the browser adds it (Wix Headless sites)
FUNCTIONALChat widgets, social feeds, review badgesAfter the page, if the visitor's consent allows it
ANALYTICSGoogle Analytics, Tag Manager, heatmaps, session recordingAfter the page, if consent allows it
ADVERTISINGMeta Pixel, TikTok Pixel, Google Ads, ad networks, retargetingAfter the page, if consent allows it
DATA_TO_THIRD_PARTYCode that sends visitor data to an outside system, such as a CRMAfter the page, if consent allows it

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

FieldValues
positionHEAD, BODY_START or BODY_END. Use the place the service's instructions name; HEAD when they say "in the <head>".
name1-100 characters, shown in the dashboard. Name the service.
embedData.htmlUp to 15,000 characters. For a longer script, embed a <script src="…"> that loads it from the service's own URL.
loadOnceDefault true: loaded once per visit, not on every page change.
enabledDefault true.

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

Step 4: Change or turn off

Update Custom Embed 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:

Copy

To turn code off without removing it:

Copy

To change a marketing tag's ID, upsert it again (Step 3a). Delete Marketing Tag 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:

Copy
  • 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.
  • After a choice, each category loads only if the visitor accepted it: a visitor who accepts analytics and rejects advertising gets the ANALYTICS code and not the ADVERTISING code.
  • A visitor who turns off sharing data with third parties (the opt-out where the default allows everything) gets none of the non-essential code, whatever else 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.

Last updated: 2 December 2026

Did this help?