@analitikisler/ai-tag-debugger 0.22.2 → 0.22.4
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/CHANGELOG.md +15 -0
- package/README.md +7 -2
- package/README.tr.md +7 -2
- package/package.json +1 -1
- package/src/agent.js +2 -1
- package/src/browser.js +59 -4
- package/src/checks.js +13 -1
- package/src/frames.js +129 -0
- package/src/html/scope.js +41 -1
- package/src/i18n.js +66 -0
- package/src/mcp.js +68 -6
- package/src/report.js +36 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.22.4 (2026-11-04)
|
|
4
|
+
|
|
5
|
+
- Runs can report a finding 0.22.3 did not on the same site (`iframe_message_unhandled`). A baseline written with 0.22.3 can then list new entries; `--update-baseline` rewrites it.
|
|
6
|
+
- New **Messages from iframes** card under the inventory and a table in `report.md`: each event an iframe posted to the page with `postMessage` (a form or checkout saying it is done), and what the page did next: pushed or sent the same event, did something else within 3 seconds (perhaps the same event under another name), or nothing. Only the message's name and field names are recorded, never values. Housekeeping messages (resizing, ready and heartbeat pings) are left out. `capture.json` keeps them under `frameMessages`.
|
|
7
|
+
- New check `iframe_message_unhandled` (info): an iframe posted an event to the page, but the page pushed nothing to its dataLayer and sent no hit right after, so a conversion completed in the iframe can go untracked.
|
|
8
|
+
- MCP: step results list the messages iframes posted at that step, `finish_audit` and `run_audit` end with them and what the page did, the JSON timeline lists them per step under `iframe_messages`, and `get_report` returns them with `part: "messages"`.
|
|
9
|
+
- New guide, [Google containers, embedded widgets and iframes](docs/guides/containers-and-widgets.md), in English and Turkish: what the containers, widgets and messages cards show, what each of their findings usually means and how to fix it, with a page listener that relays an iframe's event to the dataLayer.
|
|
10
|
+
|
|
11
|
+
## 0.22.3 (2026-11-04)
|
|
12
|
+
|
|
13
|
+
- Runs can report a finding 0.22.2 did not on the same site (`widget_events_unshared`). A baseline written with 0.22.2 can then list new entries; `--update-baseline` rewrites it.
|
|
14
|
+
- New **Embedded widgets** card under the inventory and a table in `report.md`: per third-party widget (a booking, chat or payment widget, a video), the pages it was embedded in, the containers it loaded, the tracking it sent to its own accounts and to the site's, the events and consent commands in its own dataLayer, and the events it pushed that never reached the site's accounts.
|
|
15
|
+
- New check `widget_events_unshared` (info): a widget pushed events to its own dataLayer, such as a completed booking, that none of its hits to the site's accounts carried. The page's tags can't read a widget's dataLayer, so those conversions can be missing from the site's analytics and ad accounts.
|
|
16
|
+
- MCP: the new `get_widgets` tool lists the embedded widgets an open audit's pages had so far. `finish_audit` and `run_audit` end with them, `get_report` returns them with `part: "widgets"`, and the JSON timeline lists a widget's dataLayer events per step under `widget_pushes`.
|
|
17
|
+
|
|
3
18
|
## 0.22.2 (2026-11-04)
|
|
4
19
|
|
|
5
20
|
- Runs can report a finding 0.22.1 did not on the same site (`container_failed`). A baseline written with 0.22.1 can then list new entries; `--update-baseline` rewrites it.
|
package/README.md
CHANGED
|
@@ -327,7 +327,7 @@ Under the inventory, **Google containers** lists every GTM container (`gtm.js`)
|
|
|
327
327
|
|
|
328
328
|
Each row also gives the container's published version (the number its `gtm.js` or `gtag/js` data opens with, as in GTM's Versions tab), the script's size and how long it took to load, the dataLayer the container reads (`l=`), whether it came from Google or from the site's own domain (the Google tag gateway or a server container), the GTM environment when the snippet names one, and the pages it loaded on. A container reading a dataLayer of another name has its pushes recorded too, marked with that name. `report.md` has the same table. Over MCP, step results and `get_step` list the containers each step loaded, `get_containers` lists them all while the audit is open, `finish_audit` and `run_audit` end with them, `get_report` returns them with `part: "containers"` and the JSON timeline carries them per step. `capture.json` keeps the loads under `containerLoads`. The environment token (`gtm_auth`) and the page's query string are never kept.
|
|
329
329
|
|
|
330
|
-
Five checks read it: `container_failed` (warning) for a container script that failed to load or was answered with an error, so none of its tags ran, `container_duplicate` (warning) for a container loaded more than once into one page, `container_environment` (warning) for a GTM environment (`gtm_preview`, `gtm_auth`) loaded instead of Live, `datalayer_split` (info) for containers on one page reading different dataLayers, and `container_send_to_only` (info) for a destination that only an event's `send_to` loaded, with no `gtag('config')` for it.
|
|
330
|
+
[The guide](docs/guides/containers-and-widgets.md) explains each finding below with what to do. Five checks read it: `container_failed` (warning) for a container script that failed to load or was answered with an error, so none of its tags ran, `container_duplicate` (warning) for a container loaded more than once into one page, `container_environment` (warning) for a GTM environment (`gtm_preview`, `gtm_auth`) loaded instead of Live, `datalayer_split` (info) for containers on one page reading different dataLayers, and `container_send_to_only` (info) for a destination that only an event's `send_to` loaded, with no `gtag('config')` for it.
|
|
331
331
|
|
|
332
332
|
### Embedded widgets and iframes
|
|
333
333
|
|
|
@@ -335,6 +335,10 @@ Hits, dataLayer pushes, vendor calls and container loads sent from inside an ifr
|
|
|
335
335
|
|
|
336
336
|
A widget's own hits are left out of everything that judges the site's tracking: plan matching, coverage, duplicates, unplanned events and the scores. A widget's `purchase` to its vendor's property can't pass for the site's, and its events aren't listed as the site's. They still count for consent and personal data, since the site answers for what the widgets it embeds collect; those findings begin with "In an embedded widget from …". Each widget that tracked is named once in a `widget_tracking` (info) finding with its accounts and events, and a container running in a same-site iframe beside one in the page is noted as `iframe_container` (info): the page's dataLayer pushes and consent never reach it. A widget's dataLayer pushes are kept apart too, so its consent commands don't stand in for the site's.
|
|
337
337
|
|
|
338
|
+
Each widget also gets a line in the **Embedded widgets** card under the inventory and a table in `report.md`: the pages it was embedded in, the containers it loaded itself, the tracking it sent to its own accounts and to the site's, and the events and consent commands in its own dataLayer. The page's tags can't read a widget's dataLayer, so an event the widget pushed there (a `booking_complete`, say) reaches the site's accounts only if the widget sends it to them. The events no hit to the site's accounts carried are listed as not sent, and reported as `widget_events_unshared` (info): a booking or payment completed in the widget can be missing from the site's analytics and ad accounts.
|
|
339
|
+
|
|
340
|
+
When an iframe posts an event to the page with `postMessage` (a form or checkout saying it is done), the **Messages from iframes** card lists it with what the page did next: pushed or sent the same event, did something else within 3 seconds (perhaps the same event under another name), or nothing, which is reported as `iframe_message_unhandled` (info). Only the message's name and field names are recorded, never values; housekeeping messages (resizing, ready and heartbeat pings) are left out. `capture.json` keeps them under `frameMessages`. The guide [Google containers, embedded widgets and iframes](docs/guides/containers-and-widgets.md) explains every finding here with what to do, including a page listener that relays an iframe's event to the dataLayer.
|
|
341
|
+
|
|
338
342
|
`capture.json` keeps the widget's hits under `widgetHits` and its pushes under `widgetDataLayerLog`, and every iframe entry has a `frame`. The Google containers card says which ran in an iframe. Over MCP, step results mark each hit from an iframe and whether the plan checks will count it, pushes from an iframe are prefixed with it, and the JSON timeline lists a widget's hits per step under `widget_hits`. Captures from older versions have no frames, so all of their hits stay the site's.
|
|
339
343
|
|
|
340
344
|
### Folder layout and plan IDs
|
|
@@ -666,7 +670,8 @@ Tools the server offers:
|
|
|
666
670
|
| `finish_audit` | Checks everything against your measurement plan (JSON), a saved one given as `against` (`latest`, `first`, a plan ID, or on a local server a path), or the ready-made journey's events, optionally only the `events` you name, and writes the full HTML report with the timeline. The site comes from the audit. The result ends with a compact JSON timeline, one entry per step: the hits with their consent, consent commands, other tracking calls, the Google tag's consent when it changed, and the cookies and ids that changed. |
|
|
667
671
|
| `consent_matrix` | Opens a site's start page like an ad click once per consent choice (no choice and on to the next page, accept all, reject all, analytics only), each in a fresh browser, and returns which tags sent after each choice and the [consent matrix](#consent-scenarios). `campaign` takes the campaign parameters to check (as in `start_audit`), `concurrency` how many choices run at once (default 2, at most 4). About half a minute. |
|
|
668
672
|
| `get_containers` | Lists every GTM container and Google tag the open audit's pages loaded so far, with how each reached the page (see [Google containers](#google-containers)), its dataLayer, host, GTM environment and the step it loaded at, as text and JSON. |
|
|
669
|
-
| `
|
|
673
|
+
| `get_widgets` | Lists every embedded third-party widget the open audit's pages had so far (see [Embedded widgets and iframes](#embedded-widgets-and-iframes)): where it was embedded, its containers, the tracking it sent to its own accounts and to the site's, its own dataLayer events, and the events that never reached the site's accounts, as text and JSON. |
|
|
674
|
+
| `get_report` | Reads a report this server wrote, by the name `finish_audit` or `run_audit` gave: `part` `markdown` (default, `report.md`), `summary` (`summary.json`), `timeline` (the JSON timeline of every journey, with the containers each step loaded) `containers` (every Google container with how it reached the page, as JSON) `widgets` (every embedded widget with its tracking and dataLayer events, as JSON) or `messages` (every event an iframe posted to the page, with what the page did next, as JSON). Only this server's own reports, over HTTP too. |
|
|
670
675
|
| `run_audit` | Runs a config file end to end. With `against`, it checks the run against a saved plan and, when the config has no journeys, walks the journeys derived from that plan. `concurrency` runs that many journeys at once, each in its own browser (default 1), and `baseline` names a file of accepted findings written with `--update-baseline` (default: the config's `baseline`; see [Accept known findings](#accept-known-findings)). Local only for file paths. |
|
|
671
676
|
|
|
672
677
|
`against` takes the same values as the CLI's `--against`. Over HTTP it takes only `latest`, `first` or a plan ID, never a path. Plans are the ones saved by `aitd plan --site <url>` or by `make_plan`. Ask for a plan when you want to know what to track, and for an audit when you want to know what the site sends.
|
package/README.tr.md
CHANGED
|
@@ -327,7 +327,7 @@ Envanterin altında **Google container'ları**, sayfaların yüklediği her GTM
|
|
|
327
327
|
|
|
328
328
|
Her satır ayrıca container'ın yayımlanmış sürümünü (`gtm.js` ya da `gtag/js` verisinin başladığı numara; GTM'deki Sürümler sekmesindekiyle aynı), betiğin boyutunu ve ne kadar sürede yüklendiğini, container'ın okuduğu dataLayer'ı (`l=`), Google'dan mı yoksa sitenin kendi alan adından mı (Google etiket ağ geçidi ya da bir sunucu container'ı) geldiğini, snippet bir GTM ortamı adlandırıyorsa onu ve yüklendiği sayfaları verir. Başka adlı bir dataLayer okuyan container'ın push'ları da o adla işaretlenerek kaydedilir. `report.md` aynı tabloyu içerir. MCP'de adım sonuçları ve `get_step` her adımın yüklediği container'ları listeler, `get_containers` denetim açıkken hepsini listeler, `finish_audit` ve `run_audit` sonuçları onlarla biter, `get_report` onları `part: "containers"` ile döndürür ve JSON zaman akışı onları adım adım taşır. `capture.json` yüklemeleri `containerLoads` altında saklar. Ortam belirteci (`gtm_auth`) ve sayfanın sorgu dizesi asla saklanmaz.
|
|
329
329
|
|
|
330
|
-
Beş kontrol bunu okur: yüklenemeyen ya da hatayla yanıtlanan, bu yüzden etiketlerinin hiçbiri çalışmayan bir container betiği için `container_failed` (uyarı), aynı sayfaya birden fazla kez yüklenen bir container için `container_duplicate` (uyarı), Live yerine yüklenen bir GTM ortamı (`gtm_preview`, `gtm_auth`) için `container_environment` (uyarı), aynı sayfada farklı dataLayer'ları okuyan container'lar için `datalayer_split` (bilgi) ve kendisi için `gtag('config')` olmadan yalnızca bir olayın `send_to` değeriyle yüklenen bir hedef için `container_send_to_only` (bilgi).
|
|
330
|
+
[Rehber](docs/guides/containers-and-widgets.tr.md) aşağıdaki her bulguyu ne yapılacağıyla anlatır. Beş kontrol bunu okur: yüklenemeyen ya da hatayla yanıtlanan, bu yüzden etiketlerinin hiçbiri çalışmayan bir container betiği için `container_failed` (uyarı), aynı sayfaya birden fazla kez yüklenen bir container için `container_duplicate` (uyarı), Live yerine yüklenen bir GTM ortamı (`gtm_preview`, `gtm_auth`) için `container_environment` (uyarı), aynı sayfada farklı dataLayer'ları okuyan container'lar için `datalayer_split` (bilgi) ve kendisi için `gtag('config')` olmadan yalnızca bir olayın `send_to` değeriyle yüklenen bir hedef için `container_send_to_only` (bilgi).
|
|
331
331
|
|
|
332
332
|
### Gömülü widget'lar ve iframe'ler
|
|
333
333
|
|
|
@@ -335,6 +335,10 @@ Bir iframe içinden gönderilen istekler, dataLayer push'ları, sağlayıcı ça
|
|
|
335
335
|
|
|
336
336
|
Bir widget'ın kendi istekleri, sitenin izlemesini değerlendiren her şeyin dışında tutulur: plan eşleştirme, kapsam, tekrarlar, planda olmayan olaylar ve puanlar. Widget'ın sağlayıcısının mülküne giden bir `purchase` sitenin yerine geçemez ve olayları sitenin olayları olarak listelenmez. Yine de onay ve kişisel veri için sayılırlar, çünkü site gömdüğü widget'ların topladıklarından sorumludur; bu bulgular "… kaynaklı gömülü bir widget içinde:" ile başlar. İzleme yapan her widget, hesapları ve olaylarıyla bir kez `widget_tracking` (bilgi) bulgusunda adlandırılır; sayfadakinin yanında aynı sitedeki bir iframe'de çalışan container ise `iframe_container` (bilgi) olarak not edilir: sayfanın dataLayer push'ları ve onayı ona hiç ulaşmaz. Widget'ın dataLayer push'ları da ayrı tutulur, böylece onay komutları sitenin komutlarının yerine geçmez.
|
|
337
337
|
|
|
338
|
+
Her widget ayrıca envanterin altındaki **Gömülü widget'lar** kartında bir satır, `report.md` içinde de bir tablo alır: gömülü olduğu sayfalar, kendi yüklediği container'lar, kendi hesaplarına ve sitenin hesaplarına gönderdiği izleme ve kendi dataLayer'ındaki olaylar ve onay komutları. Sayfanın etiketleri bir widget'ın dataLayer'ını okuyamaz; bu yüzden widget'ın oraya gönderdiği bir olay (örneğin `booking_complete`) sitenin hesaplarına ancak widget onu oraya gönderirse ulaşır. Sitenin hesaplarına giden hiçbir isteğin taşımadığı olaylar gönderilmemiş olarak listelenir ve `widget_events_unshared` (bilgi) olarak bildirilir: widget içinde tamamlanan bir rezervasyon ya da ödeme sitenin analitik ve reklam hesaplarında eksik kalabilir.
|
|
339
|
+
|
|
340
|
+
Bir iframe sayfaya `postMessage` ile bir olay gönderdiğinde (bir formun ya da ödemenin bittiğini söylemesi), **iframe'lerden gelen mesajlar** kartı onu sayfanın ardından ne yaptığıyla listeler: aynı olayı dataLayer'a gönderdi ya da iletti, 3 saniye içinde başka bir şey yaptı (belki aynı olayı başka bir adla) ya da hiçbir şey yapmadı; sonuncusu `iframe_message_unhandled` (bilgi) olarak bildirilir. Mesajın yalnızca adı ve alan adları kaydedilir, değerleri asla; düzenleme mesajları (boyutlandırma, hazır ve canlılık sinyalleri) dışarıda bırakılır. `capture.json` bunları `frameMessages` altında saklar. [Google container'ları, gömülü widget'lar ve iframe'ler](docs/guides/containers-and-widgets.tr.md) rehberi buradaki her bulguyu ne yapılacağıyla anlatır; bir iframe'in olayını dataLayer'a ileten bir sayfa dinleyicisi de içerir.
|
|
341
|
+
|
|
338
342
|
`capture.json` widget'ın isteklerini `widgetHits`, push'larını `widgetDataLayerLog` altında saklar ve her iframe kaydında bir `frame` bulunur. Google container'ları kartı hangilerinin bir iframe'de çalıştığını söyler. MCP'de adım sonuçları iframe'den gelen her isteği ve plan kontrollerinin onu sayıp saymayacağını işaretler, iframe'den gelen push'ların başına iframe yazılır ve JSON zaman akışı bir widget'ın isteklerini adım adım `widget_hits` altında listeler. Eski sürümlerin kayıtlarında frame bilgisi yoktur, bu yüzden tüm istekleri sitenin olarak kalır.
|
|
339
343
|
|
|
340
344
|
### Klasör yapısı ve plan kimlikleri
|
|
@@ -666,7 +670,8 @@ Sunucunun sunduğu araçlar:
|
|
|
666
670
|
| `finish_audit` | Her şeyi ölçümleme planınıza (JSON) ya da `against` olarak verilen kayıtlı bir plana (`latest`, `first`, bir plan kimliği ya da yerel bir sunucuda bir yol) ya da hazır yolculuğun event'lerine karşı kontrol eder; isterseniz yalnızca adını verdiğiniz `events` için, ve zaman akışıyla birlikte tam HTML raporunu yazar. Site denetimden alınır. Sonuç, adım başına bir kayıt içeren kısa bir JSON zaman akışıyla biter: onay durumlarıyla istekler, onay komutları, diğer takip çağrıları, değiştiğinde Google etiketinin onay durumu, değişen çerezler ve kimlikler. |
|
|
667
671
|
| `consent_matrix` | Bir sitenin başlangıç sayfasını her onay seçimi için (seçim yapmadan sonraki sayfa, tümünü kabul, tümünü reddet, yalnızca analitik) bir reklam tıklaması gibi, her seferinde yeni bir tarayıcıda açar; her seçimden sonra hangi etiketlerin gönderdiğini ve [onay matrisini](#onay-senaryoları) döndürür. `campaign` kontrol edilecek kampanya parametrelerini (`start_audit`'teki gibi), `concurrency` aynı anda kaç seçimin çalışacağını alır (varsayılan 2, en fazla 4). Yaklaşık yarım dakika sürer. |
|
|
668
672
|
| `get_containers` | Açık denetimin sayfalarının şimdiye kadar yüklediği her GTM container'ını ve Google etiketini, her birinin sayfaya nasıl geldiğiyle ([Google container'ları](#google-containerları)), dataLayer'ı, sunucusu, GTM ortamı ve yüklendiği adımla birlikte metin ve JSON olarak listeler. |
|
|
669
|
-
| `
|
|
673
|
+
| `get_widgets` | Açık denetimin sayfalarında şimdiye kadar bulunan her gömülü üçüncü taraf widget'ı ([Gömülü widget'lar ve iframe'ler](#gömülü-widgetlar-ve-iframeler)) listeler: gömülü olduğu yer, container'ları, kendi hesaplarına ve sitenin hesaplarına gönderdiği izleme, kendi dataLayer olayları ve sitenin hesaplarına hiç ulaşmayan olaylar; metin ve JSON olarak. |
|
|
674
|
+
| `get_report` | Bu sunucunun yazdığı bir raporu, `finish_audit` ya da `run_audit`'in verdiği adla okur: `part` `markdown` (varsayılan, `report.md`), `summary` (`summary.json`), `timeline` (her yolculuğun JSON zaman akışı; her adımın yüklediği container'larla) `containers` (sayfaya nasıl geldiğiyle her Google container'ı, JSON olarak) `widgets` (izlemesi ve dataLayer olaylarıyla her gömülü widget, JSON olarak) ya da `messages` (bir iframe'in sayfaya gönderdiği her olay, sayfanın ardından ne yaptığıyla, JSON olarak). Yalnızca bu sunucunun kendi raporları, HTTP üzerinden de. |
|
|
670
675
|
| `run_audit` | Bir ayar dosyasını baştan sona çalıştırır. `against` ile çalıştırmayı kayıtlı bir plana karşı kontrol eder; ayar dosyasında yolculuk yoksa, plandan türetilen yolculukları gezer. `concurrency` o kadar yolculuğu aynı anda, her birini kendi tarayıcısında çalıştırır (varsayılan 1); `baseline`, `--update-baseline` ile yazılmış kabul edilen bulgular dosyasını adlandırır (varsayılan: ayar dosyasındaki `baseline`; bkz. [Bilinen bulguları kabul edin](#bilinen-bulguları-kabul-edin)). Dosya yolları yalnızca yerelde çalışır. |
|
|
671
676
|
|
|
672
677
|
`against`, CLI'deki `--against` ile aynı değerleri alır. HTTP üzerinden yalnızca `latest`, `first` ya da bir plan kimliği kabul edilir, asla bir yol değil. Planlar, `aitd plan --site <url>` ya da `make_plan` ile kaydedilmiş olanlardır. Neyin takip edileceğini öğrenmek için plan, sitenin ne gönderdiğini öğrenmek için denetim isteyin.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@analitikisler/ai-tag-debugger",
|
|
3
3
|
"mcpName": "io.github.analitikisler/ai-tag-debugger",
|
|
4
|
-
"version": "0.22.
|
|
4
|
+
"version": "0.22.4",
|
|
5
5
|
"description": "Open-source AI agent that QA-tests your website's analytics, ad and consent tracking (GA4, GTM, Google Ads, Meta, TikTok). Bring your own model (Claude, OpenAI, Gemini) or use it from your chat app over MCP.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
package/src/agent.js
CHANGED
|
@@ -238,7 +238,7 @@ export const journeyError = (err) => `The journey stopped with an error: ${err?.
|
|
|
238
238
|
export function failedRun(journey, viewport, err, providers) {
|
|
239
239
|
return {
|
|
240
240
|
journeyId: journey.id, viewport, completed: false, note: journeyError(err), hits: [], steps: [], consentStep: null, rejectStep: null,
|
|
241
|
-
cookieLog: [], cookieChanges: [], dataLayerLog: [], containerLoads: [], network: [], widgetHits: [], widgetDataLayerLog: [], containerScripts: [], providers, skipped: {}, bodyBudgetStep: null, startedAt: Date.now(), pageErrors: [],
|
|
241
|
+
cookieLog: [], cookieChanges: [], dataLayerLog: [], containerLoads: [], network: [], widgetHits: [], widgetDataLayerLog: [], containerScripts: [], frameMessages: [], providers, skipped: {}, bodyBudgetStep: null, startedAt: Date.now(), pageErrors: [],
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
|
|
@@ -259,6 +259,7 @@ export function collect(session, journey, viewport) {
|
|
|
259
259
|
...(session.opts.blockHits === false ? { live: true } : {}),
|
|
260
260
|
containerLoads: session.containerLoads,
|
|
261
261
|
containerScripts: session.containerScripts,
|
|
262
|
+
frameMessages: session.frameMessages,
|
|
262
263
|
network: session.network,
|
|
263
264
|
providers: session.providers,
|
|
264
265
|
skipped: session.skipped,
|
package/src/browser.js
CHANGED
|
@@ -5,7 +5,7 @@ import { readFile, rm, writeFile } from "node:fs/promises";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { chromium, devices } from "playwright";
|
|
7
7
|
import { parseTrackingRequest, isCollectionEndpoint, providerOf, vendorOf, resolveProviders, PROVIDERS } from "./parsers.js";
|
|
8
|
-
import { redactBody, redactParams, redactPush, redactUrl } from "./redact.js";
|
|
8
|
+
import { redactBody, redactParams, redactPush, redactUrl, siteOf } from "./redact.js";
|
|
9
9
|
import { hostScope, isPrivateAddress, navigationError, privateHostChecker } from "./guard.js";
|
|
10
10
|
import { startEgressProxy } from "./egress.js";
|
|
11
11
|
import { campaignParamsIn } from "./campaign.js";
|
|
@@ -36,7 +36,7 @@ export const CMP_BANNER_SELECTORS = `#onetrust-banner-sdk, #onetrust-consent-sdk
|
|
|
36
36
|
// Efilli draws its banner inside the open shadow root of <efilli-layout-dynamic>, so the checks below also look inside open shadow roots.
|
|
37
37
|
|
|
38
38
|
// Caps on what one audit records, so a looping page can't grow memory without limit.
|
|
39
|
-
const LOG_LIMITS = { hits: 5000, dataLayerLog: 5000, network: 10000, containerLoads: 500, containerScripts: 500 };
|
|
39
|
+
const LOG_LIMITS = { hits: 5000, dataLayerLog: 5000, network: 10000, containerLoads: 500, containerScripts: 500, frameMessages: 1000 };
|
|
40
40
|
|
|
41
41
|
// Secrets the browser process has no use for. It gets the rest of the environment
|
|
42
42
|
// (PATH, HOME, DISPLAY...) so Chromium still starts normally.
|
|
@@ -111,6 +111,33 @@ const CONTAINER_HOOK = `
|
|
|
111
111
|
} catch {}
|
|
112
112
|
`;
|
|
113
113
|
|
|
114
|
+
// Runs inside INIT_SCRIPT, in the page itself only: records each message an iframe posts to the page, through
|
|
115
|
+
// window.__atdMessage. Only a name and the field names are kept, never the values, since a form iframe's message
|
|
116
|
+
// can carry what the visitor typed. A message with nothing that reads as a name is not reported.
|
|
117
|
+
const MESSAGE_HOOK = `
|
|
118
|
+
if (window === window.top) {
|
|
119
|
+
const nameKeys = ["event", "eventName", "event_name", "type", "action", "name", "message"];
|
|
120
|
+
const summarize = (data) => {
|
|
121
|
+
let d = data;
|
|
122
|
+
if (typeof d === "string") {
|
|
123
|
+
try { d = JSON.parse(d); } catch {
|
|
124
|
+
return d.length <= 80 && /^[\\w.:\\- ]+$/.test(d) ? { name: d, keys: [] } : null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!d || typeof d !== "object" || Array.isArray(d)) return null;
|
|
128
|
+
const key = nameKeys.find((k) => typeof d[k] === "string" && d[k] && d[k].length <= 80);
|
|
129
|
+
return key ? { name: d[key], nameKey: key, keys: Object.keys(d).slice(0, 20) } : null;
|
|
130
|
+
};
|
|
131
|
+
addEventListener("message", (e) => {
|
|
132
|
+
try {
|
|
133
|
+
if (e.source === window || !window.__atdMessage) return;
|
|
134
|
+
const info = summarize(e.data);
|
|
135
|
+
if (info) window.__atdMessage({ origin: String(e.origin), ...info });
|
|
136
|
+
} catch {}
|
|
137
|
+
}, true);
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
|
|
114
141
|
const INIT_SCRIPT = `(() => {
|
|
115
142
|
const record = (entry, layer = "dataLayer") => {
|
|
116
143
|
let value = entry;
|
|
@@ -172,6 +199,7 @@ const INIT_SCRIPT = `(() => {
|
|
|
172
199
|
};
|
|
173
200
|
watch("dataLayer");
|
|
174
201
|
${CONTAINER_HOOK}
|
|
202
|
+
${MESSAGE_HOOK}
|
|
175
203
|
})();`;
|
|
176
204
|
|
|
177
205
|
// Labels the interactive elements of one frame with numeric refs, starting at
|
|
@@ -549,6 +577,10 @@ export class AuditSession {
|
|
|
549
577
|
this.dataLayerLog = [];
|
|
550
578
|
this.containerLoads = []; // each Google container script the page added, with how (see src/containers.js)
|
|
551
579
|
this.containerScripts = []; // each container script's answer: status, version, size and load time
|
|
580
|
+
this.frameMessages = []; // each named message an iframe posted to the page: origin, name and field names, never values
|
|
581
|
+
// The order hits, dataLayer pushes and iframe messages were recorded in. Several often share a millisecond, and
|
|
582
|
+
// telling which came first matters: a page's push answers the message just before it (see messageOutcomes).
|
|
583
|
+
this.seq = 0;
|
|
552
584
|
this.network = [];
|
|
553
585
|
this.providers = resolveProviders(this.opts.providers);
|
|
554
586
|
this.landing = null; // the first page: { step, requested, chain, final }
|
|
@@ -593,8 +625,9 @@ export class AuditSession {
|
|
|
593
625
|
const frame = frameInfo(source?.frame);
|
|
594
626
|
if (frame) entry = { ...entry, frame };
|
|
595
627
|
this.lastTrackingAt = Date.now();
|
|
596
|
-
this.record("dataLayerLog", { ...this.redactEntry(entry), step: this.currentStep, t: Date.now() });
|
|
628
|
+
this.record("dataLayerLog", { ...this.redactEntry(entry), step: this.currentStep, t: Date.now(), seq: ++this.seq });
|
|
597
629
|
});
|
|
630
|
+
await this.context.exposeBinding("__atdMessage", (source, m) => this.recordMessage(m, source?.frame));
|
|
598
631
|
await this.context.exposeBinding("__atdLoad", (source, entry) => this.recordLoad(entry, frameInfo(source?.frame)));
|
|
599
632
|
await this.context.addInitScript(INIT_SCRIPT);
|
|
600
633
|
this.page = await this.context.newPage();
|
|
@@ -626,7 +659,7 @@ export class AuditSession {
|
|
|
626
659
|
const frame = this.frameOf(request);
|
|
627
660
|
for (const hit of hits) {
|
|
628
661
|
if (!this.checks(hit.platform)) continue;
|
|
629
|
-
const entry = { ...this.redactHit(hit), step: this.stepForHit(hit), pageUrl: this.page.url(), t: Date.now(), ...(frame ? { frame } : {}) };
|
|
662
|
+
const entry = { ...this.redactHit(hit), step: this.stepForHit(hit), pageUrl: this.page.url(), t: Date.now(), seq: ++this.seq, ...(frame ? { frame } : {}) };
|
|
630
663
|
const late = this.lateFor(hit, entry);
|
|
631
664
|
if (late) Object.assign(entry, late);
|
|
632
665
|
if (this.record("hits", entry)) recorded.push(entry);
|
|
@@ -874,6 +907,28 @@ export class AuditSession {
|
|
|
874
907
|
});
|
|
875
908
|
}
|
|
876
909
|
|
|
910
|
+
/**
|
|
911
|
+
* A message an iframe posted to the page: the iframe's origin, whether it is on the site's own site, the name the
|
|
912
|
+
* message carries and the names of its fields. The page's main frame reports it; values never leave the page.
|
|
913
|
+
*/
|
|
914
|
+
recordMessage(m, frame) {
|
|
915
|
+
if (!m || (frame && frame !== this.page?.mainFrame())) return;
|
|
916
|
+
let party = "third";
|
|
917
|
+
try {
|
|
918
|
+
party = siteOf(new URL(m.origin).hostname) === siteOf(new URL(this.page.url()).hostname) ? "site" : "third";
|
|
919
|
+
} catch { /* an opaque origin ("null"): a sandboxed iframe, someone else's */ }
|
|
920
|
+
this.record("frameMessages", {
|
|
921
|
+
origin: String(m.origin).slice(0, 200),
|
|
922
|
+
party,
|
|
923
|
+
name: String(m.name ?? "").slice(0, 80),
|
|
924
|
+
...(m.nameKey ? { nameKey: String(m.nameKey).slice(0, 20) } : {}),
|
|
925
|
+
keys: (Array.isArray(m.keys) ? m.keys : []).slice(0, 20).map((k) => String(k).slice(0, 40)),
|
|
926
|
+
step: this.currentStep,
|
|
927
|
+
t: Date.now(),
|
|
928
|
+
seq: ++this.seq,
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
|
|
877
932
|
/** The iframe a request came from, as frameInfo gives it; null for the page itself or a worker. */
|
|
878
933
|
frameOf(request) {
|
|
879
934
|
try {
|
package/src/checks.js
CHANGED
|
@@ -6,7 +6,7 @@ import { isOwnAddress } from "./redact.js";
|
|
|
6
6
|
import { campaignParamsIn } from "./campaign.js";
|
|
7
7
|
import { CONSENT_SIGNALS } from "./parsers.js";
|
|
8
8
|
import { duplicateLoads, loadSources, scriptFailed, splitLayers } from "./containers.js";
|
|
9
|
-
import { widgetsOf } from "./frames.js";
|
|
9
|
+
import { messageOutcomes, widgetSummaries, widgetsOf } from "./frames.js";
|
|
10
10
|
|
|
11
11
|
const platformName = (p) => ({ meta: "Meta", tiktok: "TikTok" })[p] ?? p;
|
|
12
12
|
const NON_GOOGLE_AD_PLATFORMS = new Set(["meta", "tiktok"]);
|
|
@@ -399,6 +399,18 @@ export function checkRun(plan, run, { lang = "en" } = {}) {
|
|
|
399
399
|
const first = (run.widgetHits ?? []).find((h) => h.frame.origin === w.origin);
|
|
400
400
|
findings.push({ ...base, severity: "info", check: "widget_tracking", step: stepLabel(first.step), detail: d.widgetTracking(w.origin, w.platforms) });
|
|
401
401
|
}
|
|
402
|
+
// Events a widget pushed to its own dataLayer that never reached the site's accounts: the page's tags can't see them.
|
|
403
|
+
for (const w of widgetSummaries([run], (a, b) => canonicalEvent(a) === canonicalEvent(b)).filter((x) => x.unshared.length)) {
|
|
404
|
+
findings.push({ ...base, severity: "info", check: "widget_events_unshared", step: stepLabel(w.step), detail: d.widgetEventsUnshared(w.origin, w.unshared.slice(0, 10)) });
|
|
405
|
+
}
|
|
406
|
+
// An event an iframe posted to the page that the page never acted on: no push, no hit, not even under another name.
|
|
407
|
+
const unhandled = new Set();
|
|
408
|
+
for (const msg of messageOutcomes(run, (a, b) => canonicalEvent(a) === canonicalEvent(b)).filter((x) => x.outcome === "nothing")) {
|
|
409
|
+
const k = `${msg.origin}|${canonicalEvent(msg.name)}`;
|
|
410
|
+
if (unhandled.has(k)) continue;
|
|
411
|
+
unhandled.add(k);
|
|
412
|
+
findings.push({ ...base, severity: "info", check: "iframe_message_unhandled", event: msg.name, step: stepLabel(msg.step), detail: d.iframeMessageUnhandled(msg.origin, msg.name, msg.party) });
|
|
413
|
+
}
|
|
402
414
|
// A container in a same-site iframe beside one in the page: two documents, two dataLayers.
|
|
403
415
|
const iframeLoad = loads.find((l) => l.frame?.party === "site" && loads.some((t) => !t.frame && t.step <= l.step));
|
|
404
416
|
if (iframeLoad) findings.push({ ...base, severity: "info", check: "iframe_container", step: stepLabel(iframeLoad.step), detail: d.iframeContainer(iframeLoad.id, iframeLoad.frame.origin, iframeLoad.frame.parent) });
|
package/src/frames.js
CHANGED
|
@@ -88,3 +88,132 @@ export function widgetsOf(widgetHits = []) {
|
|
|
88
88
|
platforms: [...w.platforms.values()].map((p) => ({ platform: p.platform, ids: [...p.ids], events: [...p.events] })),
|
|
89
89
|
}));
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
/** The event a dataLayer push names, { event: "x" } or gtag's ["event", "x", ...], or null. GTM's own (gtm.js, gtm.dom...) are left out. */
|
|
93
|
+
export function pushedEvent(value) {
|
|
94
|
+
const name = Array.isArray(value) ? (value[0] === "event" ? value[1] : null) : value?.event;
|
|
95
|
+
return typeof name === "string" && name && !name.startsWith("gtm.") ? name : null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const plainName = (n) => String(n).toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
99
|
+
const isConsentPush = (v) => Array.isArray(v) && v[0] === "consent";
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* One summary per embedded widget (third-party iframe origin) across runs: { origin, parents, containers,
|
|
103
|
+
* own, shared, pushes, unshared, step }.
|
|
104
|
+
* - parents: the pages it was embedded in; containers: [{ id, script }] it loaded itself
|
|
105
|
+
* - own: [{ platform, id, events }] it sent to its own accounts; shared: the same for what it sent to the site's
|
|
106
|
+
* - pushes: { total, consent, events: [{ name, count }] } of its own dataLayer
|
|
107
|
+
* - unshared: the events it pushed that none of its hits to the site's accounts carried
|
|
108
|
+
* - step: the first step it was seen at, in the first run it was seen in
|
|
109
|
+
* same(a, b) compares event names; checks.js passes canonicalEvent so add_to_cart and addToCart are one event.
|
|
110
|
+
*/
|
|
111
|
+
export function widgetSummaries(runs, same = (a, b) => plainName(a) === plainName(b)) {
|
|
112
|
+
const byOrigin = new Map();
|
|
113
|
+
const of = (frame, step) => {
|
|
114
|
+
const w = byOrigin.get(frame.origin) ?? {
|
|
115
|
+
origin: frame.origin, parents: new Set(), containers: new Map(), own: new Map(), shared: new Map(),
|
|
116
|
+
total: 0, consent: 0, events: new Map(), step,
|
|
117
|
+
};
|
|
118
|
+
if (frame.parent) w.parents.add(frame.parent);
|
|
119
|
+
byOrigin.set(frame.origin, w);
|
|
120
|
+
return w;
|
|
121
|
+
};
|
|
122
|
+
const addHit = (map, h) => {
|
|
123
|
+
const k = `${h.platform}|${h.id ?? ""}`;
|
|
124
|
+
const e = map.get(k) ?? { platform: h.platform, ...(h.id ? { id: h.id } : {}), events: new Set() };
|
|
125
|
+
e.events.add(h.name);
|
|
126
|
+
map.set(k, e);
|
|
127
|
+
};
|
|
128
|
+
for (const run of runs) {
|
|
129
|
+
for (const l of run.containerLoads ?? []) if (l.frame?.party === "third") of(l.frame, l.step).containers.set(l.id, { id: l.id, script: l.script });
|
|
130
|
+
for (const h of run.widgetHits ?? []) addHit(of(h.frame, h.step).own, h);
|
|
131
|
+
for (const h of run.hits ?? []) if (h.frame?.party === "third") addHit(of(h.frame, h.step).shared, h);
|
|
132
|
+
for (const e of run.widgetDataLayerLog ?? []) {
|
|
133
|
+
if (!e.frame) continue;
|
|
134
|
+
const w = of(e.frame, e.step);
|
|
135
|
+
w.total++;
|
|
136
|
+
if (isConsentPush(e.value)) w.consent++;
|
|
137
|
+
const name = pushedEvent(e.value);
|
|
138
|
+
if (name) w.events.set(name, (w.events.get(name) ?? 0) + 1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const list = (map) => [...map.values()].map((e) => ({ ...e, events: [...e.events] }));
|
|
142
|
+
return [...byOrigin.values()].map((w) => {
|
|
143
|
+
const shared = list(w.shared);
|
|
144
|
+
const sent = shared.flatMap((e) => e.events);
|
|
145
|
+
return {
|
|
146
|
+
origin: w.origin,
|
|
147
|
+
parents: [...w.parents].sort(),
|
|
148
|
+
containers: [...w.containers.values()],
|
|
149
|
+
own: list(w.own),
|
|
150
|
+
shared,
|
|
151
|
+
pushes: { total: w.total, consent: w.consent, events: [...w.events].map(([name, count]) => ({ name, count })) },
|
|
152
|
+
unshared: [...w.events.keys()].filter((name) => !sent.some((s) => same(s, name))),
|
|
153
|
+
step: w.step,
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// A message counts as an event when it is dataLayer-shaped ({ event: ... }) or its name reads like one; frame
|
|
159
|
+
// housekeeping (resizing, ready and heartbeat pings, scroll and focus) never does.
|
|
160
|
+
const EVENT_KEYS = new Set(["event", "eventName", "event_name"]);
|
|
161
|
+
const EVENT_WORDS = /(submit|complete|success|confirm|purchase|order|lead|book|reserv|sign.?up|register|checkout|payment|paid|conversion|subscribe|contact|quote|enquir|inquir|apply|download|add.?to.?cart)/i;
|
|
162
|
+
const HOUSEKEEPING = /^(resize|height|setheight|size|ready|loaded|load|init|initialized|heartbeat|ping|pong|scroll|focus|blur|close|open|visible|hidden|iframeresizer.*|.*resize.*)$/i;
|
|
163
|
+
|
|
164
|
+
/** Whether an iframe's message reads as an event the page might need to track. */
|
|
165
|
+
export function isEventMessage(m) {
|
|
166
|
+
const name = String(m.name ?? "");
|
|
167
|
+
if (!name || HOUSEKEEPING.test(name.replace(/[^a-z0-9]/gi, ""))) return false;
|
|
168
|
+
return EVENT_KEYS.has(m.nameKey) || EVENT_WORDS.test(name);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// How long after a message the page has to react for the reaction to count as its relay under another name.
|
|
172
|
+
export const RELAY_WINDOW_MS = 3000;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* What the page did after each event message an iframe posted to it, one per iframe, name and step:
|
|
176
|
+
* { origin, party, name, keys, step, t, outcome, relay? }. outcome "relayed": the page pushed or sent the same event
|
|
177
|
+
* (relay: { kind: "push"|"hit", name, ms }); "followed": within RELAY_WINDOW_MS it pushed another event or sent a hit,
|
|
178
|
+
* maybe the same event under another name; "nothing": neither. Only the page's own pushes and the site's own hits
|
|
179
|
+
* count (not an iframe's). same(a, b) compares event names, as in widgetSummaries.
|
|
180
|
+
*
|
|
181
|
+
* Each reaction of the page answers one message at most, so one iframe's relayed event never makes another's look
|
|
182
|
+
* handled. A reaction carrying a message's own name belongs to that message. Any other belongs to the latest message
|
|
183
|
+
* before it, since a page's listener reacts as the message arrives; when that message already has its answer, the
|
|
184
|
+
* reaction is a second effect of it (the hit after a push) and answers nothing else.
|
|
185
|
+
*/
|
|
186
|
+
export function messageOutcomes(run, same = (a, b) => plainName(a) === plainName(b)) {
|
|
187
|
+
// In recording order: seq where both have one (several often share a millisecond), else the time.
|
|
188
|
+
const order = (a, b) => (a.seq != null && b.seq != null ? a.seq - b.seq : (a.t ?? 0) - (b.t ?? 0));
|
|
189
|
+
const pushes = (run.dataLayerLog ?? []).filter((e) => !e.frame && pushedEvent(e.value)).map((e) => ({ kind: "push", name: pushedEvent(e.value), t: e.t ?? 0, seq: e.seq }));
|
|
190
|
+
const hits = (run.hits ?? []).filter((h) => !h.frame).map((h) => ({ kind: "hit", name: h.name, t: h.t ?? 0, seq: h.seq }));
|
|
191
|
+
const reactions = [...pushes, ...hits].sort(order);
|
|
192
|
+
const seen = new Set();
|
|
193
|
+
const messages = [];
|
|
194
|
+
for (const m of [...(run.frameMessages ?? [])].sort(order)) {
|
|
195
|
+
if (!isEventMessage(m)) continue;
|
|
196
|
+
const k = `${m.origin}|${m.name}|${m.step}`;
|
|
197
|
+
if (seen.has(k)) continue;
|
|
198
|
+
seen.add(k);
|
|
199
|
+
messages.push({ m, relay: null, outcome: "nothing" });
|
|
200
|
+
}
|
|
201
|
+
const used = new Set();
|
|
202
|
+
for (const msg of messages) {
|
|
203
|
+
const r = reactions.find((x) => !used.has(x) && order(x, msg.m) >= 0 && same(x.name, msg.m.name));
|
|
204
|
+
if (!r) continue;
|
|
205
|
+
Object.assign(msg, { relay: r, outcome: "relayed" });
|
|
206
|
+
used.add(r);
|
|
207
|
+
}
|
|
208
|
+
for (const r of reactions) {
|
|
209
|
+
if (used.has(r)) continue;
|
|
210
|
+
const latest = messages.filter((x) => order(x.m, r) <= 0).at(-1);
|
|
211
|
+
if (!latest || latest.relay || r.t - latest.m.t > RELAY_WINDOW_MS) continue;
|
|
212
|
+
Object.assign(latest, { relay: r, outcome: "followed" });
|
|
213
|
+
used.add(r);
|
|
214
|
+
}
|
|
215
|
+
return messages.map(({ m, relay, outcome }) => ({
|
|
216
|
+
origin: m.origin, party: m.party, name: m.name, keys: m.keys ?? [], step: m.step, t: m.t, outcome,
|
|
217
|
+
...(relay ? { relay: { kind: relay.kind, name: relay.name, ms: Math.max(0, relay.t - m.t) } } : {}),
|
|
218
|
+
}));
|
|
219
|
+
}
|
package/src/html/scope.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
// vendors, the trend) is the 0.17 renderer's, so the numbers match the Markdown report and the CLI.
|
|
5
5
|
import { buildInventory } from "../inventory.js";
|
|
6
6
|
import { containerRows } from "../containers.js";
|
|
7
|
+
import { messageOutcomes, widgetSummaries } from "../frames.js";
|
|
8
|
+
import { canonicalEvent } from "../checks.js";
|
|
7
9
|
import { providerOf } from "../parsers.js";
|
|
8
10
|
import { siteOf } from "../redact.js";
|
|
9
11
|
import { VERSION, BUCKET_ORDER, coverageLines, pcSort, planChangeItems, routeList } from "../report-shared.js";
|
|
@@ -205,13 +207,49 @@ function containersCard(ctx) {
|
|
|
205
207
|
return `<li><details class="card inv" id="inv-containers"><summary><span class="t">${esc(m.ui.containersTitle)}</span>${plain(n(ids.length))}<span class="inv-m">${esc(ids.slice(0, 3).join(", "))}${ids.length > 3 ? " …" : ""}</span></summary><div class="body"><p class="xs muted">${esc(m.ui.containersIntro)}</p><ul class="inv-list">${items}</ul></div></details></li>`;
|
|
206
208
|
}
|
|
207
209
|
|
|
210
|
+
/** The embedded widgets card: per third-party iframe, where it was embedded, its containers, its tracking and its dataLayer. Null when none. */
|
|
211
|
+
function widgetsCard(ctx) {
|
|
212
|
+
const { m, runs } = ctx;
|
|
213
|
+
const widgets = widgetSummaries(runs, (a, b) => canonicalEvent(a) === canonicalEvent(b));
|
|
214
|
+
if (!widgets.length) return null;
|
|
215
|
+
const w = m.ui.widgets;
|
|
216
|
+
const line = (label, html) => `<li><span class="inv-n">${esc(label)}</span>${html}</li>`;
|
|
217
|
+
const hits = (list) => (list.length ? list.map((e) => code(w.hits(e.platform, e.id, e.events))).join(" ") : `<span class="muted xs">${esc(w.none)}</span>`);
|
|
218
|
+
const items = widgets.map((x) => {
|
|
219
|
+
const events = x.pushes.events.map((e) => code(w.event(e.name, e.count))).join(" ");
|
|
220
|
+
return `<li><details class="card inv"><summary><code>${esc(x.origin)}</code>${plain(esc(w.pushes(x.pushes.total, x.pushes.consent)))}${x.unshared.length ? badge("info", `${m.ui.widgets.unshared}: ${x.unshared.length}`) : ""}</summary><div class="body"><ul class="inv-list">
|
|
221
|
+
${line(m.ui.embeddedCol, x.parents.map((p) => `${use("ui-page", 13)}<code>${esc(p)}</code>`).join(" ") || `<span class="muted xs">${esc(w.none)}</span>`)}
|
|
222
|
+
${line(w.containers, x.containers.length ? x.containers.map((c) => code(c.id)).join(" ") : `<span class="muted xs">${esc(w.none)}</span>`)}
|
|
223
|
+
${line(m.ui.ownCol, hits(x.own))}
|
|
224
|
+
${line(m.ui.sharedCol, hits(x.shared))}
|
|
225
|
+
${line(m.ui.pushesCol, events || `<span class="muted xs">${esc(w.none)}</span>`)}
|
|
226
|
+
${x.unshared.length ? line(w.unshared, x.unshared.map(code).join(" ")) : ""}</ul></div></details></li>`;
|
|
227
|
+
}).join("");
|
|
228
|
+
return `<li><details class="card inv" id="inv-widgets"><summary><span class="t">${esc(m.ui.widgetsTitle)}</span>${plain(n(widgets.length))}<span class="inv-m">${esc(widgets.slice(0, 3).map((x) => x.origin.replace(/^https?:\/\//, "")).join(", "))}${widgets.length > 3 ? " …" : ""}</span></summary><div class="body"><p class="xs muted">${esc(m.ui.widgetsIntro)}</p><ul class="inv-rows">${items}</ul></div></details></li>`;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** The events iframes posted to the page and what the page did next, one line each. Null when there were none. */
|
|
232
|
+
function messagesCard(ctx) {
|
|
233
|
+
const { m, runs } = ctx;
|
|
234
|
+
const same = (a, b) => canonicalEvent(a) === canonicalEvent(b);
|
|
235
|
+
const list = runs.flatMap((r) => messageOutcomes(r, same).map((x) => ({ ...x, run: r })));
|
|
236
|
+
if (!list.length) return null;
|
|
237
|
+
const t = m.ui.messages;
|
|
238
|
+
const word = (x) => (x.outcome === "nothing" ? t.nothing : t[x.outcome](x.relay.kind, x.relay.name, x.relay.ms));
|
|
239
|
+
const items = list.map((x) => `<li>${code(x.name)}<span class="inv-n">${esc(x.origin)}</span>${plain(esc(m.ui.party[x.party === "site" ? "first" : "third"]))}${x.outcome === "nothing" ? badge("info", word(x)) : plain(esc(word(x)))}<span class="inv-n">${esc(`${x.run.journeyId} · ${x.run.steps?.[x.step]?.label ?? x.step}`)}</span></li>`).join("");
|
|
240
|
+
const silent = list.filter((x) => x.outcome === "nothing").length;
|
|
241
|
+
return `<li><details class="card inv" id="inv-messages"><summary><span class="t">${esc(m.ui.messagesTitle)}</span>${plain(n(list.length))}${silent ? badge("info", `${t.nothing.split(":")[0]}: ${silent}`) : ""}</summary><div class="body"><p class="xs muted">${esc(m.ui.messagesIntro)}</p><ul class="inv-list">${items}</ul></div></details></li>`;
|
|
242
|
+
}
|
|
243
|
+
|
|
208
244
|
function inventorySection(ctx) {
|
|
209
245
|
const { m, runs } = ctx;
|
|
210
246
|
const t = m.html.scope;
|
|
211
247
|
const { lines, otherCookies } = inventoryLines(ctx);
|
|
212
248
|
const skipped = skippedTotals(runs);
|
|
213
249
|
const containers = containersCard(ctx);
|
|
214
|
-
|
|
250
|
+
const widgets = widgetsCard(ctx);
|
|
251
|
+
const messages = messagesCard(ctx);
|
|
252
|
+
if (!lines.length && !skipped.length && !containers && !widgets && !messages) return sectionBlock("inventory", esc(m.html.shell.sections.inventory), `<p class="muted">${esc(m.ui.noInventory)}</p>`);
|
|
215
253
|
const counts = (x) => `<span class="inv-m">${t.requests(x.requests, bold(x.requests))}</span><span class="inv-m">${t.pages(x.pages.size, bold(x.pages.size))}</span><span class="inv-m${x.cookies.length ? "" : " zero"}">${t.cookies(x.cookies.length, bold(x.cookies.length))}</span>`;
|
|
216
254
|
const out = lines.map((x) => {
|
|
217
255
|
const id = `inv-${safeKey(x.p)}`;
|
|
@@ -227,6 +265,8 @@ function inventorySection(ctx) {
|
|
|
227
265
|
<div role="tabpanel" id="${tid("pages")}" data-label="${esc(m.ui.pagesCol)}">${pages ? `<ul class="inv-list">${pages}</ul>` : none}</div>
|
|
228
266
|
<div role="tabpanel" id="${tid("cookies")}" data-label="${esc(m.ui.cookiesCol)}">${x.cookies.length ? `<ul class="inv-list">${x.cookies.map((ck) => `<li>${code(ck)}</li>`).join("")}</ul>` : none}</div></div></div></details></li>`;
|
|
229
267
|
});
|
|
268
|
+
if (messages) out.unshift(messages);
|
|
269
|
+
if (widgets) out.unshift(widgets);
|
|
230
270
|
if (containers) out.unshift(containers);
|
|
231
271
|
const skippedN = skipped.reduce((a, [, k]) => a + k, 0);
|
|
232
272
|
if (skipped.length) {
|
package/src/i18n.js
CHANGED
|
@@ -210,6 +210,31 @@ const en = {
|
|
|
210
210
|
layerCol: "dataLayer",
|
|
211
211
|
servedCol: "Served from",
|
|
212
212
|
scriptCol: "Version and size",
|
|
213
|
+
widgetsTitle: "Embedded widgets",
|
|
214
|
+
widgetsIntro: "Third-party iframes on the site's pages, such as booking, chat or payment widgets: the containers they loaded, the tracking they sent to their own accounts and to the site's, and the events in their own dataLayer, which the page's tags never see.",
|
|
215
|
+
widgetCol: "Widget",
|
|
216
|
+
embeddedCol: "Embedded in",
|
|
217
|
+
ownCol: "Own tracking",
|
|
218
|
+
sharedCol: "To the site's accounts",
|
|
219
|
+
pushesCol: "dataLayer events",
|
|
220
|
+
messagesTitle: "Messages from iframes",
|
|
221
|
+
messagesIntro: "Events iframes posted to the page with postMessage, such as a form or checkout telling the page it is done, and what the page did next: pushed or sent the same event, did something else within 3 seconds (perhaps the same event under another name), or nothing.",
|
|
222
|
+
messageCol: "Message",
|
|
223
|
+
fromCol: "From",
|
|
224
|
+
outcomeCol: "What the page did",
|
|
225
|
+
messages: {
|
|
226
|
+
relayed: (kind, name, ms) => `${kind === "push" ? "pushed" : "sent"} ${name} ${ms} ms later`,
|
|
227
|
+
followed: (kind, name, ms) => `${kind === "push" ? "pushed" : "sent"} ${name} ${ms} ms later (another name)`,
|
|
228
|
+
nothing: "nothing: no dataLayer push or hit followed",
|
|
229
|
+
},
|
|
230
|
+
widgets: {
|
|
231
|
+
containers: "Containers",
|
|
232
|
+
unshared: "Not sent to the site's accounts",
|
|
233
|
+
pushes: (n, consent) => `${n} ${n === 1 ? "push" : "pushes"}${consent ? `, ${consent} consent ${consent === 1 ? "command" : "commands"}` : ""}`,
|
|
234
|
+
event: (name, count) => (count > 1 ? `${name} ×${count}` : name),
|
|
235
|
+
hits: (platform, id, events) => `${label(platform)}${id ? ` ${id}` : ""}: ${events.join(", ")}`,
|
|
236
|
+
none: "none",
|
|
237
|
+
},
|
|
213
238
|
containers: {
|
|
214
239
|
script: { gtm: "GTM container", gtag: "Google tag" },
|
|
215
240
|
served: { google: "Google", site: "The site's own domain" },
|
|
@@ -360,6 +385,8 @@ const en = {
|
|
|
360
385
|
widgetTracking: (origin, platforms) => `An embedded widget from ${origin} sent its own tracking: ${platforms.map((p) => `${label(p.platform)}${p.ids.length ? ` (${p.ids.join(", ")})` : ""} ${p.events.map(q).join(", ")}`).join("; ")}. It goes to accounts the site's own tags don't use, so it was left out of the plan, coverage and duplicate checks; the consent and personal data checks still include it.`,
|
|
361
386
|
iframeContainer: (id, origin, parent) => `${id} runs in an iframe from ${origin} embedded in ${parent}. The iframe has its own dataLayer: events and consent commands pushed in the page never reach it, so it needs its own.`,
|
|
362
387
|
containerFailed: (id, host, status) => `The ${id} script from ${host} ${status === "failed" ? "failed to load" : `was answered with HTTP ${status}`}, so none of its tags ran on that page.`,
|
|
388
|
+
widgetEventsUnshared: (origin, names) => `An embedded widget from ${origin} pushed ${names.map(q).join(", ")} to its own dataLayer, but none of its hits to the site's accounts carried ${names.length === 1 ? "it" : "them"}. The page's tags can't read a widget's dataLayer, so ${names.length === 1 ? "this event reaches" : "these events reach"} only the widget's own tracking.`,
|
|
389
|
+
iframeMessageUnhandled: (origin, name, party) => `${party === "site" ? "An iframe on the site" : "An embedded widget"} from ${origin} posted ${q(name)} to the page, but the page pushed nothing to its dataLayer and sent no hit in the 3 seconds after, nor ${q(name)} later. If it is a conversion, the page isn't relaying it to its tags.`,
|
|
363
390
|
consentDefaultMissing: () => "No Google Consent Mode default command (gtag('consent', 'default', ...)) was found in the dataLayer.",
|
|
364
391
|
consentDefaultLate: () => "The Consent Mode default was set after the first tracking hit was sent.",
|
|
365
392
|
consentDefaultNotApplied: () => "The page pushed a Consent Mode default, but the Google tag never applied it, so its tags ran without one. Tag Assistant shows Consent Mode as not configured.",
|
|
@@ -422,6 +449,8 @@ const en = {
|
|
|
422
449
|
widget_tracking: "Nothing is wrong with the site's tracking: the widget's own hits were kept out of the plan checks so they can't pass for the site's.",
|
|
423
450
|
iframe_container: "Tags in the iframe miss what the page pushes, so conversions completed in it can go untracked or be sent without the visitor's consent.",
|
|
424
451
|
container_failed: "None of the container's tags ran: page views, conversions and consent signals it sends were all lost on that page.",
|
|
452
|
+
widget_events_unshared: "Conversions completed in the widget, such as a booking, a payment or a form, can be missing from the site's analytics and ad accounts.",
|
|
453
|
+
iframe_message_unhandled: "A conversion completed in the iframe, such as a form sent or a booking made, can go untracked although the iframe told the page about it.",
|
|
425
454
|
campaign_params: "Campaign parameters survived the landing redirect and reached the hits, so paid clicks are credited to their campaigns.",
|
|
426
455
|
event_id_reused: "Two different events share one event ID, so the platform keeps the first and silently drops the other: a real event is lost.",
|
|
427
456
|
event_id_mismatch: "The browser and server copies of this event carry different IDs, so Meta cannot pair them and counts the conversion twice.",
|
|
@@ -471,6 +500,8 @@ const en = {
|
|
|
471
500
|
widget_tracking: "Nothing to fix for the plan. If the widget sets cookies or sends data before consent, the consent findings name it; ask its vendor how to hold it back.",
|
|
472
501
|
iframe_container: "Push the events and the consent state inside the iframe as well (or pass them in with postMessage), or track the iframe's steps from the page.",
|
|
473
502
|
container_failed: "Check the container ID and the address in the snippet; for a server container or the Google tag gateway, check that it serves gtm.js and gtag/js.",
|
|
503
|
+
widget_events_unshared: "If the site needs these events, have the widget send them to the site's accounts (most booking and form widgets take a GA4 or GTM ID), or pass them to the page with postMessage and push them to the page's dataLayer.",
|
|
504
|
+
iframe_message_unhandled: "Add a message listener on the page that checks event.origin and pushes the event to the dataLayer, so a GTM trigger can fire on it; or have the iframe send the event to the site's accounts itself.",
|
|
474
505
|
campaign_params: "Nothing to fix. Check the redirects again when the landing pages change.",
|
|
475
506
|
event_id_reused: "Generate a new event ID for every event, not once per page load.",
|
|
476
507
|
event_id_mismatch: "Use one event ID for the pixel event and the server copy: pass the same value to both tags.",
|
|
@@ -520,6 +551,8 @@ const en = {
|
|
|
520
551
|
widget_tracking: "hygiene",
|
|
521
552
|
iframe_container: "hygiene",
|
|
522
553
|
container_failed: "money",
|
|
554
|
+
widget_events_unshared: "money",
|
|
555
|
+
iframe_message_unhandled: "money",
|
|
523
556
|
campaign_params: "money",
|
|
524
557
|
event_id_reused: "money",
|
|
525
558
|
event_id_mismatch: "money",
|
|
@@ -1046,6 +1079,31 @@ const tr = {
|
|
|
1046
1079
|
layerCol: "dataLayer",
|
|
1047
1080
|
servedCol: "Sunulduğu yer",
|
|
1048
1081
|
scriptCol: "Sürüm ve boyut",
|
|
1082
|
+
widgetsTitle: "Gömülü widget'lar",
|
|
1083
|
+
widgetsIntro: "Sitenin sayfalarındaki üçüncü taraf iframe'ler, örneğin rezervasyon, sohbet ya da ödeme widget'ları: yükledikleri container'lar, kendi hesaplarına ve sitenin hesaplarına gönderdikleri izleme ve sayfanın etiketlerinin hiç görmediği kendi dataLayer'larındaki olaylar.",
|
|
1084
|
+
widgetCol: "Widget",
|
|
1085
|
+
embeddedCol: "Gömülü olduğu yer",
|
|
1086
|
+
ownCol: "Kendi izlemesi",
|
|
1087
|
+
sharedCol: "Sitenin hesaplarına",
|
|
1088
|
+
pushesCol: "dataLayer olayları",
|
|
1089
|
+
messagesTitle: "iframe'lerden gelen mesajlar",
|
|
1090
|
+
messagesIntro: "iframe'lerin postMessage ile sayfaya gönderdiği olaylar (örneğin bir formun ya da ödemenin sayfaya bittiğini söylemesi) ve sayfanın ardından ne yaptığı: aynı olayı dataLayer'a gönderdi ya da iletti, 3 saniye içinde başka bir şey yaptı (belki aynı olayı başka bir adla) ya da hiçbir şey yapmadı.",
|
|
1091
|
+
messageCol: "Mesaj",
|
|
1092
|
+
fromCol: "Gönderen",
|
|
1093
|
+
outcomeCol: "Sayfanın yaptığı",
|
|
1094
|
+
messages: {
|
|
1095
|
+
relayed: (kind, name, ms) => `${ms} ms sonra ${name} ${kind === "push" ? "dataLayer'a gönderdi" : "isteğini gönderdi"}`,
|
|
1096
|
+
followed: (kind, name, ms) => `${ms} ms sonra ${name} ${kind === "push" ? "dataLayer'a gönderdi" : "isteğini gönderdi"} (başka bir ad)`,
|
|
1097
|
+
nothing: "hiçbir şey: ardından ne dataLayer push'u ne de istek geldi",
|
|
1098
|
+
},
|
|
1099
|
+
widgets: {
|
|
1100
|
+
containers: "Container'lar",
|
|
1101
|
+
unshared: "Sitenin hesaplarına gönderilmeyen",
|
|
1102
|
+
pushes: (n, consent) => `${n} push${consent ? `, ${consent} onay komutu` : ""}`,
|
|
1103
|
+
event: (name, count) => (count > 1 ? `${name} ×${count}` : name),
|
|
1104
|
+
hits: (platform, id, events) => `${label(platform)}${id ? ` ${id}` : ""}: ${events.join(", ")}`,
|
|
1105
|
+
none: "yok",
|
|
1106
|
+
},
|
|
1049
1107
|
containers: {
|
|
1050
1108
|
script: { gtm: "GTM container'ı", gtag: "Google etiketi" },
|
|
1051
1109
|
served: { google: "Google", site: "Sitenin kendi alan adı" },
|
|
@@ -1192,6 +1250,8 @@ const tr = {
|
|
|
1192
1250
|
widgetTracking: (origin, platforms) => `${origin} kaynaklı gömülü bir widget kendi izlemesini gönderdi: ${platforms.map((p) => `${label(p.platform)}${p.ids.length ? ` (${p.ids.join(", ")})` : ""} ${p.events.map(q).join(", ")}`).join("; ")}. Bunlar sitenin kendi etiketlerinin kullanmadığı hesaplara gidiyor; bu yüzden plan, kapsam ve tekrar kontrollerinin dışında tutuldu, onay ve kişisel veri kontrolleri ise onları yine içeriyor.`,
|
|
1193
1251
|
iframeContainer: (id, origin, parent) => `${id}, ${parent} içine gömülü ${origin} kaynaklı bir iframe içinde çalışıyor. iframe'in kendi dataLayer'ı var: sayfada gönderilen olaylar ve onay komutları ona hiç ulaşmaz, bu yüzden kendi olaylarına ve onayına ihtiyacı var.`,
|
|
1194
1252
|
containerFailed: (id, host, status) => `${host} adresinden gelen ${id} betiği ${status === "failed" ? "yüklenemedi" : `HTTP ${status} ile yanıtlandı`}; bu yüzden o sayfada etiketlerinin hiçbiri çalışmadı.`,
|
|
1253
|
+
widgetEventsUnshared: (origin, names) => `${origin} kaynaklı gömülü bir widget kendi dataLayer'ına ${names.map(q).join(", ")} gönderdi, ancak sitenin hesaplarına giden isteklerinin hiçbiri ${names.length === 1 ? "onu" : "onları"} taşımadı. Sayfanın etiketleri bir widget'ın dataLayer'ını okuyamaz; bu yüzden ${names.length === 1 ? "bu olay" : "bu olaylar"} yalnızca widget'ın kendi izlemesine ulaşıyor.`,
|
|
1254
|
+
iframeMessageUnhandled: (origin, name, party) => `${origin} kaynaklı ${party === "site" ? "sitedeki bir iframe" : "gömülü bir widget"} sayfaya ${q(name)} gönderdi, ancak sayfa ardından 3 saniye içinde dataLayer'a hiçbir şey göndermedi ve istek yollamadı, sonradan ${q(name)} da göndermedi. Bu bir dönüşümse sayfa onu etiketlerine iletmiyor.`,
|
|
1195
1255
|
consentDefaultMissing: () => "dataLayer'da Google Consent Mode varsayılan komutu (gtag('consent', 'default', ...)) bulunamadı.",
|
|
1196
1256
|
consentDefaultLate: () => "Consent Mode varsayılanı, ilk izleme isteği gönderildikten sonra ayarlandı.",
|
|
1197
1257
|
consentDefaultNotApplied: () => "Sayfa bir Consent Mode varsayılanı gönderdi, ancak Google etiketi onu hiç uygulamadı; etiketleri varsayılan olmadan çalıştı. Tag Assistant, Consent Mode'u yapılandırılmamış gösterir.",
|
|
@@ -1253,6 +1313,8 @@ const tr = {
|
|
|
1253
1313
|
widget_tracking: "Sitenin izlemesinde bir sorun yok: widget'ın kendi istekleri sitenin isteklerinin yerine geçmesin diye plan kontrollerinin dışında tutuldu.",
|
|
1254
1314
|
iframe_container: "iframe içindeki etiketler sayfanın gönderdiklerini görmez; içinde tamamlanan dönüşümler izlenmeyebilir ya da ziyaretçinin onayı olmadan gönderilebilir.",
|
|
1255
1315
|
container_failed: "Container'ın etiketlerinin hiçbiri çalışmadı: gönderdiği sayfa görüntülemeleri, dönüşümler ve onay sinyalleri o sayfada kayboldu.",
|
|
1316
|
+
widget_events_unshared: "Widget içinde tamamlanan dönüşümler, örneğin bir rezervasyon, ödeme ya da form, sitenin analitik ve reklam hesaplarında eksik kalabilir.",
|
|
1317
|
+
iframe_message_unhandled: "iframe içinde tamamlanan bir dönüşüm (gönderilen bir form, yapılan bir rezervasyon), iframe sayfaya bildirdiği hâlde izlenmeyebilir.",
|
|
1256
1318
|
campaign_params: "Kampanya parametreleri açılış yönlendirmesinden geçip isteklere ulaştı; ücretli tıklamalar kendi kampanyalarına yazılıyor.",
|
|
1257
1319
|
event_id_reused: "İki farklı olay tek bir olay kimliğini paylaşıyor; platform ilkini tutup diğerini sessizce atıyor, gerçek bir olay kayboluyor.",
|
|
1258
1320
|
event_id_mismatch: "Bu olayın tarayıcı ve sunucu kopyaları farklı kimlik taşıyor; Meta ikisini eşleştiremiyor ve dönüşümü iki kez sayıyor.",
|
|
@@ -1300,6 +1362,8 @@ const tr = {
|
|
|
1300
1362
|
widget_tracking: "Plan için düzeltilecek bir şey yok. Widget onaydan önce çerez yazıyor ya da veri gönderiyorsa onay bulguları onu adlandırır; nasıl durdurulacağını sağlayıcısına sorun.",
|
|
1301
1363
|
iframe_container: "Olayları ve onay durumunu iframe içinde de gönderin (ya da postMessage ile iletin) veya iframe'deki adımları sayfadan izleyin.",
|
|
1302
1364
|
container_failed: "Snippet'teki container kimliğini ve adresi kontrol edin; sunucu container'ı ya da Google etiket ağ geçidi için gtm.js ve gtag/js sunduğunu kontrol edin.",
|
|
1365
|
+
widget_events_unshared: "Site bu olaylara ihtiyaç duyuyorsa widget'ın onları sitenin hesaplarına göndermesini sağlayın (çoğu rezervasyon ve form widget'ı bir GA4 ya da GTM kimliği kabul eder) ya da onları postMessage ile sayfaya iletip sayfanın dataLayer'ına gönderin.",
|
|
1366
|
+
iframe_message_unhandled: "Sayfaya event.origin'i kontrol eden ve olayı dataLayer'a gönderen bir message dinleyicisi ekleyin, böylece bir GTM tetikleyicisi onunla çalışabilir; ya da iframe'in olayı sitenin hesaplarına kendisi göndermesini sağlayın.",
|
|
1303
1367
|
campaign_params: "Düzeltilecek bir şey yok. Açılış sayfaları değiştiğinde yönlendirmeleri yeniden kontrol edin.",
|
|
1304
1368
|
event_id_reused: "Her olay için yeni bir olay kimliği üretin; sayfa yüklemesi başına bir kez değil.",
|
|
1305
1369
|
event_id_mismatch: "Piksel olayı ve sunucu kopyası için tek bir olay kimliği kullanın: aynı değeri iki etikete de verin.",
|
|
@@ -1348,6 +1412,8 @@ const tr = {
|
|
|
1348
1412
|
widget_tracking: "hygiene",
|
|
1349
1413
|
iframe_container: "hygiene",
|
|
1350
1414
|
container_failed: "money",
|
|
1415
|
+
widget_events_unshared: "money",
|
|
1416
|
+
iframe_message_unhandled: "money",
|
|
1351
1417
|
campaign_params: "money",
|
|
1352
1418
|
event_id_reused: "money",
|
|
1353
1419
|
event_id_mismatch: "money",
|
package/src/mcp.js
CHANGED
|
@@ -17,7 +17,7 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
|
|
|
17
17
|
import { AuditSession } from "./browser.js";
|
|
18
18
|
import { navigationError, privateHostChecker } from "./guard.js";
|
|
19
19
|
import { collect, pageView, SYSTEM_PROMPT } from "./agent.js";
|
|
20
|
-
import { checkRun, groupFindings, isConsentCommand, summarize } from "./checks.js";
|
|
20
|
+
import { canonicalEvent, checkRun, groupFindings, isConsentCommand, summarize } from "./checks.js";
|
|
21
21
|
import { LANGUAGES, messages } from "./i18n.js";
|
|
22
22
|
import { loadConfig, readJson, runAudit, writeReports } from "./audit.js";
|
|
23
23
|
import { validatePlan } from "./schema.js";
|
|
@@ -34,7 +34,7 @@ import { hitParams } from "./hit-params.js";
|
|
|
34
34
|
import { CAMPAIGN_PARAMS, campaignParamsIn, withCampaignParams } from "./campaign.js";
|
|
35
35
|
import { cmpFacts } from "./cmp.js";
|
|
36
36
|
import { containerRows, loadSources } from "./containers.js";
|
|
37
|
-
import { isWidgetHit, siteIds } from "./frames.js";
|
|
37
|
+
import { isEventMessage, isWidgetHit, messageOutcomes, pushedEvent, siteIds, splitRun, widgetSummaries } from "./frames.js";
|
|
38
38
|
import { consentMatrixMarkdown, consentTable, runConsentScenarios } from "./consent.js";
|
|
39
39
|
import { expectEvents, filterFindings, JOURNEY_PRESETS, onlyEvents, presetFor, withPresetEvents } from "./journeys.js";
|
|
40
40
|
|
|
@@ -192,6 +192,8 @@ export function stepCapture(audit, step) {
|
|
|
192
192
|
if (pushes.length) lines.push("dataLayer pushes:", ...pushes.map(describePush));
|
|
193
193
|
const loads = loadSources({ containerLoads: (session.containerLoads ?? []).filter((l) => l.step === step), containerScripts: session.containerScripts, dataLayerLog: session.dataLayerLog });
|
|
194
194
|
if (loads.length) lines.push("Google containers loaded:", ...loads.map(describeLoad));
|
|
195
|
+
const posted = (session.frameMessages ?? []).filter((x) => x.step === step);
|
|
196
|
+
if (posted.length) lines.push("Messages iframes posted to the page (name and field names only):", ...posted.map((x) => ` ${x.name} from ${x.origin} (${x.party === "site" ? "same site" : "third party"})${x.keys?.length ? `, fields ${x.keys.join(", ")}` : ""}${isEventMessage(x) ? "" : "; housekeeping, not checked"}`));
|
|
195
197
|
lines.push(...cookieLines(session, step));
|
|
196
198
|
const tag = session.steps[step]?.tagConsent;
|
|
197
199
|
if (tag) {
|
|
@@ -269,6 +271,38 @@ export function containerLines(runs) {
|
|
|
269
271
|
];
|
|
270
272
|
}
|
|
271
273
|
|
|
274
|
+
/** The embedded widgets of the runs as summaries (see widgetSummaries), compared by canonical event name. */
|
|
275
|
+
const widgetsIn = (runs) => widgetSummaries(runs, (a, b) => canonicalEvent(a) === canonicalEvent(b));
|
|
276
|
+
|
|
277
|
+
/** The events iframes posted to the page, with what the page did next, as lines for a tool result; [] when none. */
|
|
278
|
+
export function messageLines(runs) {
|
|
279
|
+
const t = messages("en").ui.messages;
|
|
280
|
+
const list = runs.flatMap((r) => messageOutcomes(r, (a, b) => canonicalEvent(a) === canonicalEvent(b)));
|
|
281
|
+
if (!list.length) return [];
|
|
282
|
+
return [
|
|
283
|
+
"Messages from iframes (events posted to the page with postMessage, and what the page did next):",
|
|
284
|
+
...list.map((x) => ` ${x.name} from ${x.origin} (${x.party === "site" ? "same site" : "third party"}), step ${x.step}: ${x.outcome === "nothing" ? t.nothing : t[x.outcome](x.relay.kind, x.relay.name, x.relay.ms)}`),
|
|
285
|
+
];
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** The embedded widgets as lines for a tool result; [] when there were none. */
|
|
289
|
+
export function widgetLines(runs) {
|
|
290
|
+
const widgets = widgetsIn(runs);
|
|
291
|
+
if (!widgets.length) return [];
|
|
292
|
+
const w = messages("en").ui.widgets;
|
|
293
|
+
const hits = (list) => list.map((e) => w.hits(e.platform, e.id, e.events)).join("; ") || w.none;
|
|
294
|
+
return [
|
|
295
|
+
"Embedded widgets (third-party iframes; their own dataLayer is invisible to the page's tags):",
|
|
296
|
+
...widgets.map((x) => [
|
|
297
|
+
` ${x.origin}, embedded in ${x.parents.join(", ") || "?"}${x.containers.length ? `; containers ${x.containers.map((c) => c.id).join(", ")}` : ""}`,
|
|
298
|
+
` own tracking: ${hits(x.own)}`,
|
|
299
|
+
` to the site's accounts: ${hits(x.shared)}`,
|
|
300
|
+
` dataLayer: ${w.pushes(x.pushes.total, x.pushes.consent)}${x.pushes.events.length ? `: ${x.pushes.events.map((e) => w.event(e.name, e.count)).join(", ")}` : ""}`,
|
|
301
|
+
...(x.unshared.length ? [` not sent to the site's accounts: ${x.unshared.join(", ")}`] : []),
|
|
302
|
+
].join("\n")),
|
|
303
|
+
];
|
|
304
|
+
}
|
|
305
|
+
|
|
272
306
|
export function timelineOf(run) {
|
|
273
307
|
let lastIds = null;
|
|
274
308
|
return (run.steps ?? []).map((st) => {
|
|
@@ -282,6 +316,10 @@ export function timelineOf(run) {
|
|
|
282
316
|
if (hits.length) entry.hits = hits.map((h) => ({ platform: h.platform, event: h.name, ...(h.consent ? { consent: h.consent } : {}), ...(h.late ? { late_ms: h.late.ms } : {}), ...(h.frame ? { iframe: h.frame.origin } : {}) }));
|
|
283
317
|
// An embedded widget's own hits, kept apart from the site's (see src/frames.js).
|
|
284
318
|
const widget = (run.widgetHits ?? []).filter((h) => h.step === st.index);
|
|
319
|
+
const posted = messageOutcomes({ ...run, frameMessages: (run.frameMessages ?? []).filter((x) => x.step === st.index) }, (a, b) => canonicalEvent(a) === canonicalEvent(b));
|
|
320
|
+
if (posted.length) entry.iframe_messages = posted.map((x) => ({ from: x.origin, name: x.name, outcome: x.outcome, ...(x.relay ? { relay: x.relay } : {}) }));
|
|
321
|
+
const widgetPushes = (run.widgetDataLayerLog ?? []).filter((e) => e.step === st.index && e.frame && pushedEvent(e.value));
|
|
322
|
+
if (widgetPushes.length) entry.widget_pushes = widgetPushes.map((e) => ({ widget: e.frame.origin, event: pushedEvent(e.value) }));
|
|
285
323
|
if (widget.length) entry.widget_hits = widget.map((h) => ({ widget: h.frame.origin, platform: h.platform, event: h.name, ...(h.id ? { id: h.id } : {}), ...(h.consent ? { consent: h.consent } : {}) }));
|
|
286
324
|
if (others.length) entry.other_tracking_calls = others.length;
|
|
287
325
|
if (commands.length) entry.consent_commands = commands.map((e) => ({ [e.value[1]]: e.value[2] }));
|
|
@@ -544,15 +582,33 @@ export function buildServer(opts) {
|
|
|
544
582
|
},
|
|
545
583
|
);
|
|
546
584
|
|
|
585
|
+
server.registerTool(
|
|
586
|
+
"get_widgets",
|
|
587
|
+
{
|
|
588
|
+
title: "List the embedded widgets seen so far",
|
|
589
|
+
description:
|
|
590
|
+
"Returns every third-party iframe (a booking, chat or payment widget, a video) this audit's pages embedded that tracked or loaded a Google container so far: the pages it was embedded in, the containers it loaded, the tracking it sent to its own accounts and to the site's, the events and consent commands in its own dataLayer, and the events it pushed that never reached the site's accounts. The page's tags can't read a widget's dataLayer, so those events only reach the widget's own tracking. Widgets' own hits are left out of the plan checks; finish_audit still checks them for consent and personal data.",
|
|
591
|
+
inputSchema: { audit_id: z.string() },
|
|
592
|
+
annotations: { readOnlyHint: true },
|
|
593
|
+
},
|
|
594
|
+
async ({ audit_id }) => {
|
|
595
|
+
const { session } = getAudit(audit_id);
|
|
596
|
+
const run = { ...splitRun(session), containerLoads: session.containerLoads };
|
|
597
|
+
const lines = widgetLines([run]);
|
|
598
|
+
if (!lines.length) return text("No embedded third-party widget has tracked or loaded a Google container on this audit's pages yet.");
|
|
599
|
+
return text(`${lines.join("\n")}\n\nAs JSON: ${JSON.stringify(widgetsIn([run]))}`);
|
|
600
|
+
},
|
|
601
|
+
);
|
|
602
|
+
|
|
547
603
|
server.registerTool(
|
|
548
604
|
"get_report",
|
|
549
605
|
{
|
|
550
606
|
title: "Read a report this server wrote",
|
|
551
607
|
description:
|
|
552
|
-
"Returns a report finish_audit or run_audit wrote, so it can be read without access to the computer running this server. part markdown (default): report.md, the verdict, findings, consent and journeys in about 120 lines. summary: summary.json, the counts, journeys and findings as JSON. timeline: one JSON entry per step of each journey (hits with their consent, consent commands, the Google tag's consent, cookies and ids, the Google containers loaded). containers: every GTM container and Google tag the journeys loaded as JSON, with how each reached the page (source html, inline, script, custom_html, google_tag, nested, config, send_to or destination, and by: the container or script that loaded it), its dataLayer, host, GTM environment and pages.",
|
|
608
|
+
"Returns a report finish_audit or run_audit wrote, so it can be read without access to the computer running this server. part markdown (default): report.md, the verdict, findings, consent and journeys in about 120 lines. summary: summary.json, the counts, journeys and findings as JSON. timeline: one JSON entry per step of each journey (hits with their consent, consent commands, the Google tag's consent, cookies and ids, the Google containers loaded). containers: every GTM container and Google tag the journeys loaded as JSON, with how each reached the page (source html, inline, script, custom_html, google_tag, nested, config, send_to or destination, and by: the container or script that loaded it), its dataLayer, host, GTM environment, version, size, load time and pages. widgets: every embedded third-party widget as JSON: where it was embedded, the containers it loaded, the tracking it sent to its own accounts and to the site's, its own dataLayer events, and the events it pushed that never reached the site's accounts (unshared). messages: every event an iframe posted to the page with postMessage as JSON, with what the page did next (outcome relayed, followed or nothing, and relay: the push or hit that followed).",
|
|
553
609
|
inputSchema: {
|
|
554
610
|
report: z.string().describe("The report name finish_audit or run_audit gave."),
|
|
555
|
-
part: z.enum(["markdown", "summary", "timeline", "containers"]).optional().describe("Default markdown."),
|
|
611
|
+
part: z.enum(["markdown", "summary", "timeline", "containers", "widgets", "messages"]).optional().describe("Default markdown."),
|
|
556
612
|
},
|
|
557
613
|
annotations: { readOnlyHint: true },
|
|
558
614
|
},
|
|
@@ -564,6 +620,8 @@ export function buildServer(opts) {
|
|
|
564
620
|
if (part === "summary") return text(await readFile(path.join(dir, "summary.json"), "utf8"));
|
|
565
621
|
const capture = JSON.parse(await readFile(path.join(dir, "capture.json"), "utf8"));
|
|
566
622
|
if (part === "containers") return text(JSON.stringify(containerRows(capture.runs ?? []).map(containerJson)));
|
|
623
|
+
if (part === "widgets") return text(JSON.stringify(widgetsIn(capture.runs ?? [])));
|
|
624
|
+
if (part === "messages") return text(JSON.stringify((capture.runs ?? []).flatMap((r) => messageOutcomes(r, (a, b) => canonicalEvent(a) === canonicalEvent(b)).map((x) => ({ journey: r.journeyId, viewport: r.viewport, ...x })))));
|
|
567
625
|
return text(JSON.stringify((capture.runs ?? []).map((r) => ({ journey: r.journeyId, viewport: r.viewport, steps: timelineOf(r) }))));
|
|
568
626
|
} catch (err) {
|
|
569
627
|
return fail(`Could not read the report: ${err.message}`);
|
|
@@ -674,13 +732,15 @@ export function buildServer(opts) {
|
|
|
674
732
|
skippedLine(run),
|
|
675
733
|
...((platform) => (platform ? [`Consent platform: ${platform.vendor}. ${platform.facts.join(" ")}`] : []))(cmpFacts(messages("en"), [run])),
|
|
676
734
|
...containerLines([run]),
|
|
735
|
+
...widgetLines([run]),
|
|
736
|
+
...messageLines([run]),
|
|
677
737
|
opts.allowFiles
|
|
678
738
|
? `Full report with the event timeline: ${reportPath}`
|
|
679
739
|
: opts.reportsUrl
|
|
680
740
|
? `Full report with the event timeline: ${opts.reportsUrl}/${path.basename(outDir)}/report.html`
|
|
681
741
|
: "",
|
|
682
742
|
"",
|
|
683
|
-
`To read the report here: get_report with report "${path.basename(outDir)}" (markdown, summary, timeline or
|
|
743
|
+
`To read the report here: get_report with report "${path.basename(outDir)}" (markdown, summary, timeline, containers, widgets or messages).`,
|
|
684
744
|
"Explain each problem to the user with its likely cause and fix.",
|
|
685
745
|
];
|
|
686
746
|
return {
|
|
@@ -827,8 +887,10 @@ export function buildServer(opts) {
|
|
|
827
887
|
...result.runs.map((r) => `${r.journeyId} (${r.viewport}): ${r.completed ? "completed" : "not completed"}, ${r.note}`),
|
|
828
888
|
...grouped.map((f) => `- ${m.severity[f.severity]}${f.accepted ? ` (${m.ui.accepted})` : ""}: ${f.detail}`),
|
|
829
889
|
...containerLines(result.runs),
|
|
890
|
+
...widgetLines(result.runs),
|
|
891
|
+
...messageLines(result.runs),
|
|
830
892
|
`Report: ${result.reportPath}`,
|
|
831
|
-
`To read the report here: get_report with report "${path.basename(result.outDir)}" (markdown, summary, timeline or
|
|
893
|
+
`To read the report here: get_report with report "${path.basename(result.outDir)}" (markdown, summary, timeline, containers, widgets or messages).`,
|
|
832
894
|
].join("\n"),
|
|
833
895
|
);
|
|
834
896
|
},
|
package/src/report.js
CHANGED
|
@@ -6,6 +6,7 @@ import { canonicalEvent, groupFindings, summarize } from "./checks.js";
|
|
|
6
6
|
import { messages } from "./i18n.js";
|
|
7
7
|
import { buildInventory } from "./inventory.js";
|
|
8
8
|
import { containerRows } from "./containers.js";
|
|
9
|
+
import { messageOutcomes, widgetSummaries } from "./frames.js";
|
|
9
10
|
import { computeMetrics } from "./metrics.js";
|
|
10
11
|
import { historySummaryLines, sparkline } from "./history.js";
|
|
11
12
|
import { cardIds } from "./html/lib.js";
|
|
@@ -403,6 +404,39 @@ export function scriptCell(c, r) {
|
|
|
403
404
|
return [r.version && c.version(r.version), r.bytes && c.size(r.bytes), r.ms != null && c.loadTime(r.ms)].filter(Boolean).join(", ");
|
|
404
405
|
}
|
|
405
406
|
|
|
407
|
+
/** The events iframes posted to the page and what the page did next, one row each. Omitted when there were none. */
|
|
408
|
+
function mdMessages(m, runs) {
|
|
409
|
+
const same = (a, b) => canonicalEvent(a) === canonicalEvent(b);
|
|
410
|
+
const list = runs.flatMap((r) => messageOutcomes(r, same));
|
|
411
|
+
if (!list.length) return [];
|
|
412
|
+
const t = m.ui.messages;
|
|
413
|
+
const lines = [`## ${m.ui.messagesTitle}`, "", `| ${m.ui.messageCol} | ${m.ui.fromCol} | ${m.ui.outcomeCol} |`, "|---|---|---|"];
|
|
414
|
+
for (const x of list.slice(0, MD_INVENTORY_ROWS)) {
|
|
415
|
+
const what = x.outcome === "nothing" ? t.nothing : t[x.outcome](x.relay.kind, x.relay.name, x.relay.ms);
|
|
416
|
+
lines.push(`| ${mdText(x.name)} | ${mdText(x.origin)} (${m.ui.party[x.party === "site" ? "first" : "third"]}) | ${mdText(what)} |`);
|
|
417
|
+
}
|
|
418
|
+
if (list.length > MD_INVENTORY_ROWS) lines.push("", m.ui.md.moreIn(list.length - MD_INVENTORY_ROWS, "report.html"));
|
|
419
|
+
lines.push("");
|
|
420
|
+
return lines;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** The embedded widgets, one row each: where they were embedded, their tracking and their own dataLayer events. Omitted when none. */
|
|
424
|
+
function mdWidgets(m, runs) {
|
|
425
|
+
const widgets = widgetSummaries(runs, (a, b) => canonicalEvent(a) === canonicalEvent(b));
|
|
426
|
+
if (!widgets.length) return [];
|
|
427
|
+
const w = m.ui.widgets;
|
|
428
|
+
const hits = (list) => list.map((e) => w.hits(e.platform, e.id, e.events)).join("; ") || w.none;
|
|
429
|
+
const lines = [`## ${m.ui.widgetsTitle}`, "", `| ${m.ui.widgetCol} | ${m.ui.embeddedCol} | ${m.ui.ownCol} | ${m.ui.sharedCol} | ${m.ui.pushesCol} |`, "|---|---|---|---|---|"];
|
|
430
|
+
for (const x of widgets.slice(0, MD_INVENTORY_ROWS)) {
|
|
431
|
+
const events = x.pushes.events.map((e) => w.event(e.name, e.count)).join(", ") || w.none;
|
|
432
|
+
const unshared = x.unshared.length ? ` (${w.unshared}: ${x.unshared.join(", ")})` : "";
|
|
433
|
+
lines.push(`| ${mdText(x.origin)} | ${mdText(x.parents.join(", ")) || "–"} | ${mdText(hits(x.own))} | ${mdText(hits(x.shared))} | ${mdText(events + unshared)} |`);
|
|
434
|
+
}
|
|
435
|
+
if (widgets.length > MD_INVENTORY_ROWS) lines.push("", m.ui.md.moreIn(widgets.length - MD_INVENTORY_ROWS, "report.html"));
|
|
436
|
+
lines.push("");
|
|
437
|
+
return lines;
|
|
438
|
+
}
|
|
439
|
+
|
|
406
440
|
/** The Google containers and how each reached the page, one row per container and source. Omitted when none loaded. */
|
|
407
441
|
function mdContainers(m, runs) {
|
|
408
442
|
const rows = containerRows(runs);
|
|
@@ -470,6 +504,8 @@ export function renderMarkdown({ title, site = null, generatedAt, findings, expl
|
|
|
470
504
|
lines.push(...mdNotChecked(m, runs, rows, plan, consentScenarios));
|
|
471
505
|
lines.push(...mdInventory(m, runs));
|
|
472
506
|
lines.push(...mdContainers(m, runs));
|
|
507
|
+
lines.push(...mdWidgets(m, runs));
|
|
508
|
+
lines.push(...mdMessages(m, runs));
|
|
473
509
|
// A report with its own name or logo carries no Analitik İşler credit; the ai tag debugger one stays.
|
|
474
510
|
if (brand?.name || brand?.logo) lines.push("---", "", `_${brand.name ? `${brand.name} · ` : ""}${m.ui.generatedBy}_`, "");
|
|
475
511
|
else if (branding) lines.push("---", "", `_${m.ui.generatedBy} · [analitikisler.com](https://analitikisler.com)_`, "");
|