# Tag Manager

Tag Manager reference: requirements, settings, 10 agent tools with full notes, and core events, read from the code.

A tag manager that uses each tag smartly: add an ad pixel, analytics or verification tag with only its ID, and it waits for cookie consent, avoids double-loading, and receives your forms, signups, waitlist joins, popups and affiliate clicks as the right events with values.

**Beta.** Tag Manager is in beta: it works, but things may still break. If something breaks, [report it](https://github.com/sundoggs/support/issues/new).

On the store: [Tag Manager](https://sundo.gs/apps/tags) in [Analytics and tracking](https://sundo.gs/categories/analytics-and-tracking), [pricing](https://sundo.gs/pricing).

## Price

$7 USD per site · $21 USD for all your sites, paid once. Every purchase includes 12 months of updates, and there is a full refund within 7 days. Details: [pricing](https://sundo.gs/pricing).

## Requirements

- Cloudflare® plan: Cloudflare free plan
- Works on: Cloudflare Workers; Cloudflare Pages; A site on its own server (VPS or cloud) with DNS on Cloudflare, through a Worker route in front of it (beta, tested on a live server) ([hosts](https://sundo.gs/docs/hosts.md))
- Version: 0.7.2 (needs core 0.27.0 or later; it comes in the same download)
- Runs on the Cloudflare free plan, in the same D1 database as your other site apps. Tags are added to your pages as they're served, so page views run through the site apps (as with forms and link tagging).
- You need an account (and the ID) with each vendor you add: Meta, TikTok, Google and so on. Presets need only that ID; the admin shows where to find it. Some vendors are paid (Plausible, Fathom); Clarity and Search Console are free.
- Vendors' scripts run in your visitors' browsers and talk to the vendors directly. This app never sends your site's data to us. A vendor's own terms apply to what you send it. Their code is loaded live from their servers and runs with full access to the pages it's on: each tag says which hosts, and the Check-up tab writes a Content-Security-Policy (report-only first) limited to them.
- Cookie consent: tags that need it (ads, analytics, recordings) wait for the visitor's choice when you use the Cookie Consent app or connect your own consent tool; without one, consent isn't asked for and tags load for everyone.
- No server-side conversion relays in this release (Meta Conversions API and similar). Events carry a shared id so those can be added later without double counting.
- Optional: Plausible through your own domain uses Worker requests on your plan (it is off by default).
- Cost per visit: no requests to us and no writes (the vendors' scripts load from the visitor's browser); at most one small write an hour when a duplicate tag is skipped. Past the Cloudflare free Worker request limit the site's Worker stops and tags are not added until Fail open lets pages through without them.

## What it adds to the site

- Addresses it answers: `/_st/*`
- Edits pages as they are served: yes
- Has a say when a page is not found: no
- Uses the site's [brand](https://sundo.gs/docs/core.md#brand): no
- [Core](https://sundo.gs/docs/core.md) capabilities it uses: `optout`
- Database tables (in the site's own D1 database): `tags_tags`, `tags_sources`

### Cookies and browser storage

What the app sets in a visitor's browser. Anything that is not necessary waits for [consent](https://sundo.gs/docs/core.md#consent).

| Name | Category | Kept in | Lasts | What it is for |
|---|---|---|---|---|
| `_fbp` | marketing | cookie | about 3 months | Identifies the browser for Meta ads measurement. Set by Meta's script, not by this site. (only if the Meta Pixel tag is on and marketing is allowed) |
| `_fbc` | marketing | cookie | about 3 months | Stores the Meta ad click that brought the visitor. Set by Meta's script, not by this site. (only if the Meta Pixel tag is on, marketing is allowed and the visitor came from a Meta ad) |
| `_ttp` | marketing | cookie | 13 months from last use | Identifies the browser for TikTok ads measurement. Set by TikTok's script, not by this site. (only if the TikTok Pixel tag is on and marketing is allowed) |
| `ttcsid*` | marketing | cookie | 13 months from last use | TikTok session identifiers. Set by TikTok's script, not by this site. (only if the TikTok Pixel tag is on and marketing is allowed) |
| `ttclid` | marketing | cookie | 13 months from last use | Stores the TikTok ad click that brought the visitor. Set by TikTok's script, not by this site. (only if the TikTok Pixel tag is on, marketing is allowed and the visitor came from a TikTok ad) |
| `_ga` | analytics | cookie | up to 2 years | Tells returning visitors apart for Google Analytics. Set by Google's script, not by this site. (only if the Google Analytics tag is on and analytics is allowed) |
| `_ga_*` | analytics | cookie | up to 2 years | Keeps the session state for Google Analytics 4. Set by Google's script, not by this site. (only if the Google Analytics tag is on and analytics is allowed) |
| `_gcl_*` | marketing | cookie | up to 90 days | Stores the Google Ads click that brought the visitor, to credit conversions. Set by Google's script, not by this site. (only if the Google Ads tag is on, marketing is allowed and the visitor came from a Google ad) |
| `_gcl_ls` | marketing | localStorage | until cleared | Google Ads conversion linker data kept in the browser. Set by Google's script, not by this site. (only if the Google Ads tag is on and marketing is allowed) |
| `li_adsid` | marketing | cookie | set by LinkedIn | A pseudonymous LinkedIn Ads ID (not set in the EU, EEA, UK or Quebec). Set by LinkedIn's script, not by this site. (only if the LinkedIn Insight Tag is on and marketing is allowed) |
| `li_fat_id` | marketing | cookie | set by LinkedIn | Stores the LinkedIn ad click, when enhanced conversion tracking is on. Set by LinkedIn's script, not by this site. (only if the LinkedIn Insight Tag is on, marketing is allowed and the visitor came from a LinkedIn ad) |
| `_uetsid` | marketing | cookie | 1 day | Microsoft Advertising session identifier. Set by Microsoft Advertising's script, not by this site. (only if the Microsoft UET tag is on and marketing is allowed) |
| `_uetvid` | marketing | cookie | 13 months | Microsoft Advertising visitor identifier. Set by Microsoft Advertising's script, not by this site. (only if the Microsoft UET tag is on and marketing is allowed) |
| `_clck` | analytics | cookie | 13 months | Clarity user identifier. Set by Microsoft Clarity's script, not by this site. (only if the Clarity tag is on and analytics is allowed) |
| `_clsk` | analytics | cookie | 1 day | Links a visitor's page views into one Clarity session. Set by Microsoft Clarity's script, not by this site. (only if the Clarity tag is on and analytics is allowed) |
| `_hjSessionUser_*` | analytics | cookie | 1 year | Hotjar user identifier for this site. Set by Hotjar's script, not by this site. (only if the Hotjar tag is on and analytics is allowed) |
| `_hjSession_*` | analytics | cookie | 30 minutes, extended on activity | Hotjar session identifier. Set by Hotjar's script, not by this site. (only if the Hotjar tag is on and analytics is allowed) |
| `_hjHasCachedUserAttributes` | analytics | sessionStorage | until the tab closes | Hotjar flag for cached user attributes. Set by Hotjar's script, not by this site. (only if the Hotjar tag is on and analytics is allowed) |
| `_hjUserAttributesHash` | analytics | sessionStorage | until the tab closes | Hotjar hash of user attributes. Set by Hotjar's script, not by this site. (only if the Hotjar tag is on and analytics is allowed) |
| `_hjUserAttributes` | analytics | localStorage | until cleared | Hotjar user attributes kept in the browser. Set by Hotjar's script, not by this site. (only if the Hotjar tag is on and analytics is allowed) |
| `hjActiveViewportIds` | analytics | localStorage | until cleared | Hotjar bookkeeping of the viewport. Set by Hotjar's script, not by this site. (only if the Hotjar tag is on and analytics is allowed) |
| `hjViewportId` | analytics | sessionStorage | until the tab closes | Hotjar bookkeeping of the viewport. Set by Hotjar's script, not by this site. (only if the Hotjar tag is on and analytics is allowed) |
| `_rdt_uuid` | marketing | cookie | set by Reddit | Identifies the browser for Reddit ads measurement. Set by Reddit's script, not by this site. (only if the Reddit Pixel tag is on and marketing is allowed) |
| `_scid` | marketing | cookie | 1 year | Identifies the browser for Snapchat ads measurement. Set by Snap's script, not by this site. (only if the Snap Pixel tag is on and marketing is allowed) |
| `sc_at` | marketing | cookie | 1 year | Snapchat ads measurement identifier. Set by Snap's script, not by this site. (only if the Snap Pixel tag is on and marketing is allowed) |

## Agent tools

Tag Manager adds 10 tools to the site's own [agent connection](https://sundo.gs/docs/agent-connection.md). The short text under each name is what an agent sees in its tool list; the full notes are what `site_tool_help` returns. The [shared rules](https://sundo.gs/docs/core/site-tools.md#shared-rules) for `confirm`, `dry_run` and `on` apply to every tool.

### Read (changes nothing)

#### `tags_list`

Start here. Every tag with vendor, state, consent category and mode, US opt-out handling, problems, `recommendations` (call apply only if the owner agrees) and `warnings`, including tags hard-coded in the site's pages. If a warning names a hard-coded tag: Add the tag in Tag Manager with confirm:true, then remove the hard-coded snippet in the same change (or the next deploy), and check the page.

Read only: changes nothing.

**Full notes** (what `site_tool_help` returns):

Also what still has to be created in the vendors' screens. `consentAskedOf` says who waits for consent (with mode regions, only visitors in those countries; everyone else gets tags straight away). `usOptOut` has the Do Not Sell or Share link setting and the ad tags that ignore opt-outs. `recommendations` [{id, text, why, apply?: {tool, args}}] are the admin's suggestions in its own words (consent mode, US opt-outs, Google Consent Mode and modeling): explain each to the owner in one or two plain sentences and call apply.tool with apply.args only if they agree; entries without apply are notes. `warnings` also names tags loaded outside the Tag Manager (a gtag.js or pixel snippet hard-coded in the site's pages, found by scanning the home page, up to 5 known pages (sampled automatically) and settings.checkPages): those load even when consent is required (`outsideTags` lists them with the page); and custom code that loads a remote host (custom-remote) or reads cookies or storage. If a warning names a hard-coded tag: Add the tag in Tag Manager with confirm:true, then remove the hard-coded snippet in the same change (or the next deploy), and check the page. The kill switch settings.killCustom (tags_settings_save) switches all custom code off at once. Not legal advice.

Takes no input.

#### `tags_get`

One tag in full, as tags_save takes it, with the warnings about it.

Read only: changes nothing.

| Field | Type | Required | What it is |
|---|---|---|---|
| `name` | string | yes | The tag's name from tags_list (not the vendor ID). |

#### `tags_values`

What each conversion is worth (the owner's own numbers, shared with Analytics) and every event your tags can receive, with `recommendations` (call `apply` only if the owner agrees). Change values with tags_values_save.

Read only: changes nothing.

**Full notes** (what `site_tool_help` returns):

`values.conversions` lists each conversion type with its id ("forms.submit"), `worth` (a number in `values.currency`, null when none is set) and `items` (one form, popup or link with its own worth). `events` lists what the installed apps declare, with the name tags know each by (`name`), whether it is a conversion or an action, and `legacyName` true for the original seven events tags have always known. `recommendations` are suggestions about these values (same shape as tags_list): explain each in a sentence or two and call `apply` only if the owner agrees. Change values with tags_values_save.

Takes no input.

### Change

#### `tags_optout_link`

Set the "Do Not Sell or Share My Personal Information" link, shared with the Cookie Consent app. usOptOutLink: off | auto | own. Changes the live site within about 30 seconds: confirm with the owner first.

Changes the site.

**Full notes** (what `site_tool_help` returns):

Either app can change it. auto: added at the end of every page for US visitors and visitors whose country is unknown; skipped on pages that already have the owner's link. own: the owner placed \<a href="#do-not-sell"\>…\</a\>; clicks opt the visitor out. A click opts out at once: ad tags that honor opt-outs use limited data use or stop. It is turned on automatically ("auto") when the first ad tag is added and the owner never chose.

| Field | Type | Required | What it is |
|---|---|---|---|
| `usOptOutLink` | `"off"`, `"auto"`, `"own"` | yes |  |

#### `tags_settings_save`

Change the Tag Manager's site-wide settings: pages that never get tags, pages to scan for hard-coded tags, and the custom code kill switch (killCustom). PATCH: omitted settings keep their saved values (tags_list shows them under settings). Risky input (the answer says which) does nothing until called again with confirm:true.

Changes the site.

**Full notes** (what `site_tool_help` returns):

sensitive: the "Never load tags on" page patterns (useSuggested:true adds the suggested list: checkout, cart, account, log-in pages). noForms: no tags on pages with a form. checkPages: up to 5 more pages (paths like /pricing/) that the Check-up and tags_list scan for tags hard-coded in the page's code (the home page is always scanned, and up to 5 known pages are sampled automatically: from SEO Pack's pages or the sitemap, else the most visited, so this is rarely needed). killCustom: the kill switch, true switches ALL custom code tags off at once without deleting them (use it if custom code looks wrong); false runs them again and needs confirm:true. Changes reach the live site within about 30 seconds.

| Field | Type | Required | What it is |
|---|---|---|---|
| `sensitive` | list of strings | no | Page patterns that never get tags, starting with / or \*, like /account/\*. Replaces the list. |
| `useSuggested` | boolean | no | true: add the suggested patterns to the list. |
| `noForms` | boolean | no | Don't load tags on pages that contain a form. |
| `checkPages` | list of strings | no | Paths to scan for hard-coded tags, like /pricing/. Replaces the list. |
| `killCustom` | boolean | no | true: all custom code is off. false: custom code runs again (needs confirm:true). |
| `confirm` | boolean | no | true only after an answer asked for it, with confirm_token. |
| `confirm_token` | string | no | The answer's confirmToken, sent with confirm:true and the same input. |
| `dry_run` | boolean | no | true: save nothing; answers wouldSave (the full record) and the warnings. |

#### `tags_honour_optouts`

Switch every ad tag that ignores US opt-outs (us "off") to honor them (us "gpc"). Only when the owner agrees. tags_list shows which (usOptOut.adTagsIgnoringOptOuts).

Changes the site.

**Full notes** (what `site_tool_help` returns):

These are usually tags added before 0.3.0. Saved tags never change on their own.

Takes no input.

#### `tags_values_save`

Set what conversions are worth (per conversion type, optionally per form, popup or link) and the currency, sent with conversions to ad tags and used by Analytics. Only set a number the owner gave you: never guess one. PATCH: only the keys you send change.

Changes the site.

**Full notes** (what `site_tool_help` returns):

The Tag Manager sends the value and currency with the conversion to Google Ads, Google Analytics 4, Meta, TikTok and the other tags that take a value; Analytics uses the same numbers for its totals (analytics_settings_save changes them too). Only set a number the owner gave you: never estimate, guess or work one out. Send `values` keyed by "\<app\>.\<id\>" (see tags_values), e.g. {"forms.submit":{"worth":40,"items":{"quote":200,"newsletter":2}}}; null or "" removes a value (no value means no value parameter is sent). `currency` is a 3-letter code like USD. sendToTags: setting or changing a value switches it on; values that only came from Analytics stay off until the owner agrees (see `recommendations` in tags_values). PATCH: everything you don't send keeps its saved value.

| Field | Type | Required | What it is |
|---|---|---|---|
| `values` | object | no | Keyed by "\<app\>.\<id\>", each {worth?: number \| null, items?: {"\<form, popup or link name\>": number \| null}} or just a number. Numbers are in the site's currency (40 = 40 USD). |
| `currency` | string | no | A 3-letter currency code like USD, EUR or GBP (default USD). A sign like $ is refused: it could mean several currencies. |
| `sendToTags` | boolean | no | Send the values to ad tags (true) or hold them back (false). Setting a value switches it on. Sent values are visible in the page's code. |
| `dry_run` | boolean | no | true: save nothing; answers wouldSave (the full record) and the warnings. |

#### `tags_save`

Add a tag from a preset (meta, tiktok, linkedin, ga4, gads, gtm, google-verify, bing-verify, uet, clarity, hotjar, plausible, fathom, pinterest, x, reddit, snap, custom) with the vendor ID or a pasted snippet, or change one (its name plus only what changes: PATCH). Custom code that loads a remote host or reads cookies or storage, and a duplicate tag, need confirm:true. A tag the pages already load by hand: Add the tag in Tag Manager with confirm:true, then remove the hard-coded snippet in the same change (or the next deploy), and check the page. Read the answer's warnings. Risky input (the answer says which) does nothing until called again with confirm:true.

Changes the site.

**Full notes** (what `site_tool_help` returns):

Required when adding: preset and id (or a snippet). PATCH: omitted fields keep their saved values; read them with tags_get. Name the tag with `label` when you add a second one of a kind (two custom tags otherwise both read "Custom code"). Tags load only after consent by default (only for visitors who are asked; with Cookie Consent mode regions everyone else gets them straight away); `category` may only be made stricter. New ad tags (meta, tiktok, linkedin, gads, uet, pinterest, x, reddit, snap) and new marketing custom code default to us "gpc": they honor US opt-outs (Global Privacy Control, the Do Not Sell or Share link). New gads and ga4 tags default to mode advanced with url_passthrough on (gads also ads_data_redaction); saved tags keep their mode and options. Verification tags take `tokens`: add one per owner, never replace. A GA4, Google Ads, Meta or Tag Manager ID in the wrong shape is refused (send force:true only if you are sure). Custom code (preset custom, `source`): a snippet that loads a remote host or reads document.cookie, localStorage or sessionStorage, and a tag that duplicates a snippet the pages already load (or another tag here), do nothing until you call again with confirm:true; the answer lists the hosts and the risky reads: show them to the owner first. The kill switch killCustom (tags_settings_save) turns all custom code off at once. A second tag of the same vendor with another ID (two GA4 IDs, two Meta pixels) is saved with a warning, because every page view is then sent twice, once to each. The answer has warnings: read them. us: GA4 with gpc keeps counting a visitor who opts out but switches off ad use; gpc means limited data use where the vendor has it, otherwise the tag doesn't run for them; all is limited data use for every US visitor (vendors with it: meta, tiktok, reddit, and gads as restricted data processing).

| Field | Type | Required | What it is |
|---|---|---|---|
| `name` | string | no | Change this existing tag (its name from tags_list). When adding, an optional short name; otherwise it is made from the preset. |
| `label` | string | no | A readable name for the owner and for messages, e.g. "Chat widget". Defaults to the preset's name. |
| `preset` | string | no | The vendor preset when creating. |
| `id` | string | no | The vendor's ID (or paste the snippet). |
| `ids` | object | no | A free map of a preset's extra ID fields by key (for example {"sv":"6"} for Hotjar, or X's base code as {"base":"..."}); `id` is the main one. |
| `tokens` | list of strings | no | Verification tags: the codes or whole meta tags. |
| `scope` | `"home"`, `"all"` | no | Verification tags: only the home page (default) or every page. |
| `category` | `"necessary"`, `"analytics"`, `"marketing"`, `"preferences"` | no |  |
| `confirmNoCookies` | boolean | no | Custom code in category necessary only: true confirms the code sets no cookies or identifiers and does no tracking. |
| `mode` | `"strict"`, `"hold"`, `"advanced"` | no |  |
| `exempt` | boolean | no | Plausible and Fathom only: load without waiting for consent, relying on the vendor's cookieless statement. |
| `timing` | `"immediate"`, `"load"`, `"idle"`, `"interaction"` | no | When the tag starts once it is allowed: immediate (as soon as allowed), load (after the page has loaded), idle (when the browser is idle), interaction (on the first interaction). |
| `us` | `"off"`, `"gpc"`, `"all"` | no | US opt-outs: gpc (honor Global Privacy Control and the Do Not Sell or Share link; default for new ad, GA4 and marketing custom code tags), all (limited data use for every US visitor), off (ignore opt-outs). |
| `options` | object | no | A free map of the preset's switches by key (tags_get shows them), e.g. {"urlPassthrough":true,"adsDataRedaction":true} for gads. |
| `map` | object | no | A free map of events to what the tag sends, keyed by event name, each {e, v, cur, st, cid, xid, off}; null removes one. The Events tab shows the same. |
| `include` | list of strings | no |  |
| `exclude` | list of strings | no | Path patterns like /account/\*. |
| `sensitive` | boolean | no | Skip the site's "Never load tags on" pages (default true). |
| `testAddresses` | boolean | no | Also run on preview and test addresses (\*.pages.dev). |
| `source` | string | no | Custom code only: the snippet to run (script, img, iframe, link or meta tags). |
| `placement` | `"head"`, `"body-end"` | no | Custom code only: where in the page the code goes (default head). |
| `ack` | list of strings | no | Custom code only: warnings you accept, e.g. ["document_write"]. |
| `enabled` | boolean | no |  |
| `force` | boolean | no | true: save a GA4, Google Ads, Meta or Tag Manager ID even though its shape looks wrong. Only when you are sure. |
| `confirm` | boolean | no | true only after an answer asked for it, with confirm_token. |
| `confirm_token` | string | no | The answer's confirmToken, sent with confirm:true and the same input. |
| `dry_run` | boolean | no | true: save nothing; answers wouldSave (the full record) and the warnings. |

#### `tags_toggle`

Turn a tag on or off. Without `on` it flips, which is not safe to retry. (`enabled` is the older spelling of `on`.) Risky input (the answer says which) does nothing until called again with confirm:true.

Changes the site.

| Field | Type | Required | What it is |
|---|---|---|---|
| `name` | string | yes | The tag's name from tags_list. |
| `on` | boolean | no | true: on, false: off. Sets the state (safe to retry). |
| `enabled` | boolean | no | Older spelling of `on`. |
| `confirm` | boolean | no | true only after an answer asked for it, with confirm_token. |
| `confirm_token` | string | no | The answer's confirmToken, sent with confirm:true and the same input. |

#### `tags_delete`

Delete a tag. It stops loading on the site. DESTRUCTIVE: does nothing until called again with confirm:true.

Changes the site. Destructive: does nothing until it is called again with `confirm`.

| Field | Type | Required | What it is |
|---|---|---|---|
| `name` | string | yes | The tag's name from tags_list (not the vendor ID). |
| `confirm` | boolean | no | Leave out first (the answer says what would happen); then true, with confirm_token. |
| `confirm_token` | string | no | The answer's confirmToken, sent with confirm:true and the same input. |

## Core events

It sends and listens to none.

How events work: [core events](https://sundo.gs/docs/core.md#events).

## Works with your other apps

Connects with no setup, in any install order: [Cookie Consent](https://sundo.gs/docs/apps/consent.md), [Forms](https://sundo.gs/docs/apps/forms.md), [Analytics](https://sundo.gs/docs/apps/analytics.md), [Links & Redirects](https://sundo.gs/docs/apps/links.md).

---

This page on the web: https://sundo.gs/docs/apps/tags/
