Repository navigation
Conversation
…ed, all off) New module src/visitor-token.ts: the token client (POST /v1/visitor-token, cache in memory and sessionStorage dl_vt, 15-minute renewal, anon_<uuid> only) and the link decorator (empty fields only, re-stamp on click, renewal while a link is on the page, original hrefs kept so stamps can be removed). Settings visitorToken, consentHeader, edgeCookieV2 and optOutDeletesVisitorId added to the init options and the remote config allowlist; nothing reads them yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l (behind visitorToken, off)
New public getVisitorToken(): Promise<string|null>. Only when a provider is
switched on in the visitorToken setting, tracking is allowed and marketing
consent is not denied, for anon_<uuid> ids: POST <endpoint>/v1/visitor-token
with { workspace_id, visitor_id } and X-DL-Consent: granted. Cached in memory
and sessionStorage dl_vt until 15 minutes old. reset() clears the cache so
the next token names the new visitor. With the setting off nothing is created
or sent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…en in client_reference_id (behind visitorToken.stripe, off) With visitorToken.stripe on, buy.stripe.com / stripeLinkDomains links and the stripe-pricing-table / stripe-buy-button embeds get client_reference_id = the signed token instead of the raw visitor id: only when the field is empty (a raw id an older stamp wrote is replaced), re-stamped on click, renewed every 15 minutes while such a link is on the page, re-issued after reset(). The raw-id decorator stops writing client_reference_id while the token is on; prefilled_email is unchanged. stripePaymentLinks: false still turns all Stripe decoration off. Off: unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…turn the signed token (behind visitorToken.stripe / .whop, off) When the provider is on and the token is ready: getStripeMetadata() returns client_reference_id = token and metadata.dl_vt = token; getWhopCheckoutMetadata() returns dl_vt = token. Before the token is ready (owner answer 8): the raw id (today's value) while raw ids are accepted (visitorToken.rawIdFallback, default true), else empty values; the first call starts the token request. Return types gain an optional dl_vt. Off: unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t dl_vt (behind visitorToken.calendly / .iclosed, off) With visitorToken.calendly on, calendly.com (and subdomain) links, inline-widget data-url values and iframes get salesforce_uuid = the signed token; with visitorToken.iclosed on, iclosed.io links, data-url values and iframes get dl_vt = the token. Only empty fields; iframes are stamped once (rewriting src reloads the widget). Off: unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…und links to checkoutChampDomains (behind visitorToken.checkoutchamp, off) With visitorToken.checkoutchamp on and checkoutChampDomains set, links to those domains (and their subdomains) get dl_vt = the signed token, only when empty. The raw _dl_* bridge stays off and an inbound dl_vt is never adopted by the funnel page's script. Off: unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l_consent= on their beacons (behind consentHeader, off) With consentHeader on, event requests to a first-party endpoint (the customer's own domain, never *.datalyr.com) carry X-DL-Consent: granted or denied (denied when tracking is off or marketing consent is withdrawn), and their beacons carry dl_consent= in the URL (beacons cannot set headers). The token request always sends X-DL-Consent: granted (it is only made when allowed). Off: headers and beacon URL byte-identical to today. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and ask the edge to clear its copy (script side; POST /v/clear behind edgeCookieV2, off) optOut(), setConsent() withdrawal (analytics or marketing) and a Shopify decline now stop the token decorator, put every link it stamped back to its original href, and clear the cached token (memory and sessionStorage dl_vt). With edgeCookieV2 on and a first-party endpoint, they also call POST <endpoint>/v/clear once (credentials included, no body, no custom header) so the edge clears __dl_vid_h. With every setting off nothing new is sent and no link changes (no decorator exists). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tDeletesVisitorId, off) Owner answer 9. With optOutDeletesVisitorId on, optOut() deletes the __dl_visitor_id cookie (root domain and other domain forms) and the localStorage copy, and keeps a new anon_<uuid> in memory only; optIn() or a consent grant persists the new id, so a visitor who opts in again starts as a new visitor. Off: the id is kept, as today. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dge collect names none and the SDK adopts the edge's id (behind edgeCookieV2, off) When the browser has no stored visitor id (no cookie, no storage, no live session record, no handoff; e.g. Safari wiped it) and edgeCookieV2 is on, the first event request to a first-party endpoint goes without visitor_id, anonymous_id, distinct_id and canonical_id equal to the id minted on this page, so the edge fills the visitor it kept (__dl_vid_h). The SDK adopts the visitor_id the edge answers with (persisted like any id); events queued before that are rewritten to it; the token cache and stamped links follow. Never over a stored id, never after reset(). Beacons cannot read the answer, so they are not stripped. Off: payloads byte-identical to today. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he body, read expiresAt, stop for the session when there is no mint route; decorator fixes
Review fixes for web#31:
- The token is opaque (dv2, visitor id encrypted): checked only as
^[A-Za-z0-9_-]{16,64}$ on mint and cache; removing a stamp uses the token
kept in the stamp record, not a format test.
- Minting always goes to ingest (ingest.datalyr.com, or the configured
endpoint when it is a DATALYR one), never the own-domain edge; no cookies.
Consent goes in the JSON body (consent: 'granted'), no X-DL-Consent header
on this call. Expiry from T1's expiresAt.
- 404 / other 4xx / 204 / not JSON / no token: stop minting for the tab
session (sessionStorage dl_vt_off); only network, 429 and 5xx retry after a
minute.
- Decorator (C13/C15 area): reissue() leaves iframes alone (no second widget
reload; opt-out still strips them); pagehide pauses and a back-forward-cache
pageshow re-arms; records are per attribute, so href and data-url on one
element are both kept and restored.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The edge clears __dl_vid_h only when it sees denied, so with edgeCookieV2 on first-party event requests carry X-DL-Consent (and beacons dl_consent=) even when consentHeader is off. Both off: unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… an id keep the local one, inner ids handled, opted-out browsers never adopt Review fixes for the edge adoption (behind edgeCookieV2, off): - Every send goes through one gate: while the page's minted id is pending only ONE id-less request is in flight (critical sends included); the rest wait for its answer and go with the adopted id (or the local one). - An answer naming no visitor_id (old edge, switch off) stops the stripping; the local id is used. An answer that names one is adopted even on 5xx (the edge kept that id for the retry). - Beacons while pending go without the id too. - The minted id inside event_data (two levels: $identify / $alias data) is stripped while pending and rewritten to the adopted id after. - A browser with a __dl_opt_out cookie (either value) at init, or that calls optOut() on this page, never adopts the edge's id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
While the page's minted id waits for the edge's answer (edgeCookieV2, own- domain endpoint, nothing stored), the token client's get() and peek() return null: nothing is minted for an id the server may never see, and the getters fall back as before a token is ready. Once the edge id is adopted, or the edge answers without one, the decorator re-stamps and the token is minted for the settled id. Off: unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alendly salesforce_uuid / iClosed dl_vt with the token Today's setup has customers put the raw visitor id in salesforce_uuid (and iClosed links), so 'only empty fields' never gave those links a token. A field whose value is this browser's current raw visitor id, or one it had earlier on this page (before reset(), or before an adopted edge id), is now replaced by the token; any other value is kept. Stripe's replaceable rule uses the same test. Behind visitorToken.calendly / .iclosed (off). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FX-083 unit T4: the script side of the signed visitor token. Spec:
docs/factory/v1-baseline/whole/FX-083-VISITOR-TOKEN-SPEC.md(sections 2 to 5, the script tests in 6, owner answers in 7).Everything ships off. New settings (init options, and the dashboard config through the remote-config allowlist):
visitorToken: { stripe, whop, calendly, iclosed, checkoutchamp, rawIdFallback },consentHeader,edgeCookieV2,optOutDeletesVisitorId. With all off: no new request, no link changed, getters unchanged (tests insrc/visitor-token-sdk.test.ts, "all settings off", plus an "off" test in each C section andsrc/queue-consent-header.test.ts).What is built
src/visitor-token.ts(new): the token client and the link decorator.POST /v1/visitor-token(ingest.datalyr.com, or the configured endpoint when it is a DATALYR one; never the own-domain edge, no cookies) with{ workspace_id, visitor_id, consent: 'granted' }in the body (no consent header: ingest's preflight does not allow it). Onlyanon_<uuid>ids, never while tracking is off or marketing consent is denied. The token is opaque (dv2, visitor id encrypted): accepted as^[A-Za-z0-9_-]{16,64}$; expiry fromexpiresAt, at most 2 hours. Cached in memory and sessionStoragedl_vt(bound to the visitor id); renewed when 15 minutes old; one request at a time. 404 / other 4xx / 204 / not JSON / no token: no more minting for the tab session; network, 429 and 5xx retry after a minute.stop(true)restores it (removal uses the stamped token, not a format test). Iframes are stamped once and left alone byreset()re-issue (rewritingsrcreloads the widget). Paused onpagehide, re-armed on a back-forward-cachepageshow.src/index.ts:getVisitorToken(), the getters, wiring, reset / opt-out / withdrawal.src/queue.ts: the consent signal (C18).src/identity.ts:forgetAnonymousId()(C21).dl_vtin the page URL is never adopted (test). It is not stripped from the URL either: the CheckoutChamp funnel page needs it.Changes to what the SDK sends (each its own commit, each behind a setting that is off)
SEND CHANGE C17getVisitorToken()and thePOST /v1/visitor-tokencall (only on pages with a decoratable link, or when a getter is used);reset()clears the cachevisitorToken.*SEND CHANGE C13client_reference_id= token, not the raw id. A raw id stamped before a late dashboard config arrives is replaced;stripePaymentLinks: falsestill turns it off;prefilled_emailunchangedvisitorToken.stripeSEND CHANGE C14getStripeMetadata()returnsclient_reference_id= token andmetadata.dl_vt;getWhopCheckoutMetadata()returnsdl_vt. Before the token is ready: raw id while raw ids are accepted (rawIdFallback, default true), else empty (owner answer 8).metadata.visitor_idkeeps the raw id while acceptedvisitorToken.stripe/.whopSEND CHANGE C15data-url/ iframes:salesforce_uuid; iClosed:dl_vtvisitorToken.calendly/.iclosedSEND CHANGE C16dl_vton links tocheckoutChampDomains(raw_dl_*bridge stays off)visitorToken.checkoutchampSEND CHANGE C18on first-party event requests,dl_consent=` on their beaconsSEND CHANGE C19POST <endpoint>/v/clear(no body, no custom header, credentials included) once, only on a first-party endpointedgeCookieV2for the callSEND CHANGE C19 (script side)visitor_id/anonymous_id/distinct_id/canonical_idequal to the id minted on this page; the SDK adopts thevisitor_idthe edge answers with (from__dl_vid_h, T3 contract) and persists it; events queued before are rewritten; token cache and stamped links follow. Never over a stored id, never afterreset(); beacons are not strippededgeCookieV2SEND CHANGE C17 (fix)expiresAt, stop for the session; decorator: iframes skipped on re-issue, bfcache re-arm, per-attribute recordsSEND CHANGE C18 (fix)edgeCookieV2on implies the consent header (the edge clears__dl_vid_honly when it sees denied)edgeCookieV2SEND CHANGE C19 (fix)visitor_idkeeps the local id; beacons stripped while pending; the minted id insideevent_datastripped, then rewritten; a browser with__dl_opt_out(either value) or anoptOut()on the page never adoptsedgeCookieV2SEND CHANGE C21optOut()deletes the stored visitor id (cookie + storage); a new id is persisted after opt-in (owner answer 9)optOutDeletesVisitorIdNo Whop link decoration (owner answer 5). C20 is server-side and not in this PR.
Tests
src/visitor-token.test.ts: client (request shape, cache, 15-minute renewal, expiry, consent,anon_<uuid>only, other-visitor cache dropped, clear, malformed token, inbounddl_vtnot adopted) and decorator (only empty fields, exact host, re-stamp on click, 15-minute renewal while a link is present and none after, iframes once, no consent no request, restore, raw-id replace).src/visitor-token-sdk.test.ts: full init with network mocked; all off; each C change on and off;reset()gives the new visitor's token; withdrawal strips stamped links;/v/clearonly withedgeCookieV2and a first-party endpoint.src/queue-consent-header.test.ts: C18 headers and beacon URL, off byte-identical; edge adoption at queue level.Rollout order
visitorTokenprovider setting goes on: a decorated Stripe link carries only the token, no raw id.EDGE_VISITOR_COOKIE_V2) and the script settingsedgeCookieV2(which implies the consent header) go on together.visitorTokenproviders one at a time, canary hosts first;optOutDeletesVisitorIdseparately.Notes for review
Core bundle:
datalyr.min.js146954 B min / 40435 B gzip on main; 163134 B min / 44766 B gzip here (+16180 B min, +4331 B gzip). The link decorator is not lazy-loaded yet: that needs a new published bundle (dl.tokens.<v>.js) in datalyr-v2's tracking build, so it is left for a follow-up.X-DL-Consentgoes only on event requests (and the new token call); never on/container-scriptsor/sdk-consent-policy.Edge adoption: ingest must accept events whose only visitor field is the
visitor_idedge fills. A raw-id Stripe link stamped before adoption keeps the minted id (only when the Stripe token is off).Commits depend on the first two (module, C17); C13 to C21 can each be dropped alone.
The consent header is not added to the GET requests for
/container-scriptsand/sdk-consent-policy(a custom header would add a CORS preflight to them).Server pieces this relies on (ingest route, edge
/v/clear, preflight forX-DL-Consent, handlers) are other FX-083 units.Not done
🤖 Generated with Claude Code