@owlmeans/web-gtm 0.1.18-rc.4 → 0.1.18-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/agent-meta/manifest.json +16 -0
- package/agent-meta/skills/web-gtm/SKILL.md +96 -0
- package/package.json +2 -2
- package/build/.gitkeep +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!-- owlmeans:agent-guidance:start -->
|
|
2
|
+
## Agent guidance
|
|
3
|
+
|
|
4
|
+
This package ships embedded agent skills under `agent-meta/`. After installing your
|
|
5
|
+
`@owlmeans/*` packages, run the OwlMeans agent-skills installer to place them into
|
|
6
|
+
your project's skill store (`.agents/skills/`):
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.12
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The embedded files are version-matched to this package release. Do not edit them
|
|
13
|
+
directly — they are regenerated on each publish. To contribute guidance edits,
|
|
14
|
+
open a PR against the source monorepo.
|
|
15
|
+
<!-- owlmeans:agent-guidance:end -->
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 2,
|
|
3
|
+
"package": "@owlmeans/web-gtm",
|
|
4
|
+
"version": "0.1.18-rc.6",
|
|
5
|
+
"generatedAt": "2026-09-05T20:35:15.392Z",
|
|
6
|
+
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
|
+
"entries": [
|
|
8
|
+
{
|
|
9
|
+
"kind": "skill",
|
|
10
|
+
"name": "web-gtm",
|
|
11
|
+
"category": "package-specific",
|
|
12
|
+
"file": "skills/web-gtm/SKILL.md",
|
|
13
|
+
"canonicalPath": ".agents/skills/web-gtm/SKILL.md"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: web-gtm
|
|
3
|
+
description: How to use @owlmeans/web-gtm — the Google Tag Manager head snippet that declares Consent Mode defaults before the container loads, the noscript frame, and the script-side loader for a host that cannot edit its own HTML. Auto-invoked when adding a tag manager to a page, importing gtmHeadScript, gtmNoscriptFrame or loadGtm, or debugging why a tag ignores a stored consent decision.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
7
|
+
|
|
8
|
+
# @owlmeans/web-gtm
|
|
9
|
+
|
|
10
|
+
**Layer:** Web
|
|
11
|
+
**Install:** `"@owlmeans/web-gtm": "^0.1.18-rc.6"` in `dependencies`
|
|
12
|
+
|
|
13
|
+
The tag-manager half of the consent set. It emits **strings**, not components, and it holds no
|
|
14
|
+
state — the decision lives in `@owlmeans/consent`, which this package reads through
|
|
15
|
+
`consentBootstrapScript` and `consentStore`.
|
|
16
|
+
|
|
17
|
+
## The one idea: order
|
|
18
|
+
|
|
19
|
+
Google Tag Manager decides what a tag may do from the consent state present **when the container
|
|
20
|
+
loads**. A React bundle cannot get there first: by the time an island mounts, `gtm.js` has been
|
|
21
|
+
running for hundreds of milliseconds and has already decided. A site whose defaults arrive after
|
|
22
|
+
the container is not configured differently — it is *unconfigured for the window that matters*, and
|
|
23
|
+
nothing in the page reports it.
|
|
24
|
+
|
|
25
|
+
So `gtmHeadScript` emits the consent bootstrap and then the container, in that order, as one
|
|
26
|
+
inline script. Everything else in this package exists to serve that.
|
|
27
|
+
|
|
28
|
+
## Key Exports
|
|
29
|
+
|
|
30
|
+
| Export | Description |
|
|
31
|
+
|--------|-------------|
|
|
32
|
+
| `gtmHeadScript(opts)` | The inline `<head>` snippet: consent defaults, stored decision, then the container |
|
|
33
|
+
| `gtmNoscriptFrame(opts)` | The hidden `<noscript>` iframe, for the top of `<body>` |
|
|
34
|
+
| `loadGtm(opts)` | Script-side container load, for a host that cannot emit into its own head |
|
|
35
|
+
| `GtmOptions` | `ConsentOptions` plus `id` (e.g. `GTM-XXXXXXX`) and optional `dataLayerName` |
|
|
36
|
+
|
|
37
|
+
## Stamping it
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { gtmHeadScript, gtmNoscriptFrame } from '@owlmeans/web-gtm'
|
|
41
|
+
|
|
42
|
+
const opts = { id: 'GTM-XXXXXXX' }
|
|
43
|
+
const head = gtmHeadScript(opts) // inline <script> content for <head>, first
|
|
44
|
+
const frame = gtmNoscriptFrame(opts) // <noscript> content for the top of <body>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The snippet is stamped **from HTML**, never from the application bundle. How each surface does it:
|
|
48
|
+
|
|
49
|
+
- a Vite app — a `transformIndexHtml` plugin substituting the two markers, so the snippet cannot
|
|
50
|
+
drift from the package;
|
|
51
|
+
- an Astro site — `owlHeadScripts()` from `@owlmeans/astro`, `set:html` in the base layout.
|
|
52
|
+
|
|
53
|
+
A surface that runs no container of its own stamps only `consentBootstrapScript()` from
|
|
54
|
+
`@owlmeans/consent` — that is the case for the bundler-generated `index.html` of a generated
|
|
55
|
+
application, which carries the consent bootstrap and no tag manager. The bootstrap and this
|
|
56
|
+
snippet are separate stampings: adding a container means adding `gtmHeadScript` /
|
|
57
|
+
`gtmNoscriptFrame` beside it.
|
|
58
|
+
|
|
59
|
+
`gtmHeadScript` also **reads the stored decision** and pushes `consent/update` before the
|
|
60
|
+
container, so a returning visitor's tags are not denied for the first paint of every page. That
|
|
61
|
+
read is why the same `ConsentOptions` (categories, `storageKey`) must be passed here and to the
|
|
62
|
+
dialog: two different category sets in one page mean the snippet and the component disagree about
|
|
63
|
+
what was asked.
|
|
64
|
+
|
|
65
|
+
## Gotchas
|
|
66
|
+
|
|
67
|
+
- **The container id and queue name are injected as data, never interpolated raw.** Both come from
|
|
68
|
+
configuration, and configuration reaches these functions as a string. `gtmHeadScript` JSON-encodes
|
|
69
|
+
them, so a quote inside an id is escaped rather than closing the literal and turning the rest into
|
|
70
|
+
executable script; `gtmNoscriptFrame` URL-encodes the id so it cannot break out of the attribute.
|
|
71
|
+
Never build either string by hand.
|
|
72
|
+
- **`dataLayerName` is for a page running more than one container.** It is passed through to the
|
|
73
|
+
container the way Google's own snippet does (`&l=` when it is not `dataLayer`); leave it unset
|
|
74
|
+
otherwise, or tags looking at the default queue see nothing.
|
|
75
|
+
- **`loadGtm` is the fallback, not the default.** It is for a single-page app whose HTML is not
|
|
76
|
+
yours to edit. It still pushes the defaults first (through `consentStore.init`) and refuses to
|
|
77
|
+
load a second time — it marks its own `<script>` element with an id derived from the container —
|
|
78
|
+
but it runs after the bundle, which is exactly the window the head snippet closes. Prefer the
|
|
79
|
+
head snippet wherever the document can be edited.
|
|
80
|
+
- **A second `consent/default` after a tag has loaded can WIDEN what was already narrowed**, so the
|
|
81
|
+
bootstrap is idempotent through a window flag. A page may therefore carry the call twice — once
|
|
82
|
+
inline, once from the bundle that mounts the dialog — without harm. Do not defeat the flag.
|
|
83
|
+
- `loadGtm` returns immediately when there is no `document`, so it is safe to call from code that
|
|
84
|
+
also runs during server rendering.
|
|
85
|
+
|
|
86
|
+
## Depends On
|
|
87
|
+
|
|
88
|
+
- `@owlmeans/consent` — `consentBootstrapScript`, `consentStore`, `ConsentOptions`, the category
|
|
89
|
+
model and the Consent Mode signal mapping
|
|
90
|
+
|
|
91
|
+
## Related
|
|
92
|
+
|
|
93
|
+
- `consent` — categories, the storage record and its migration, Consent Mode v2 signalling, and the
|
|
94
|
+
ordering rule this package implements
|
|
95
|
+
- `web-consent` — the dialog and the cookie-policy page that produce the decision
|
|
96
|
+
- `astro` — `owlHeadScripts()`, which composes both strings for an Astro layout
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/web-gtm",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@owlmeans/consent": "^0.1.18-rc.
|
|
25
|
+
"@owlmeans/consent": "^0.1.18-rc.4"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@owlmeans/dep-config": "workspace:*",
|
package/build/.gitkeep
DELETED
|
File without changes
|