Skip to content

FX-126 Klaviyo: dl.js keeps the signed link token for the session (off) - #33

Draft
czypnt wants to merge 2 commits into
mainfrom
feat/klaviyo-dljs-token-fx126
Draft

czypnt wants to merge 2 commits into
mainfrom
feat/klaviyo-dljs-token-fx126

Conversation

@czypnt

@czypnt czypnt commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What it does

This is part of DATALYR's Klaviyo event sending (datalyr/datalyr#884 and #898).

When a shopper clicks a DATALYR-signed link in a Klaviyo email (dl_kprofile_id=dlk1… or dlk2…), the website script now keeps that signed token for the browser session. It attaches the token to each later view_item, add_to_cart and checkout_started, and ingest verifies it again on every event. Before this change, the token rode on only the first event after landing, so a later cart event could never reach the shopper's Klaviyo profile under the "trusted sources only" rule (decision R120).

  • Only the signed token shapes are kept, never a raw profile id. A raw dl_kprofile_id keeps today's one-shot behaviour.
  • A dlk2 token is never kept past its own expiry (45 days).
  • The token is tied to one session. A token never used in its session is dropped at the next session, and a session change or reset() drops it (verify N3, 28c4f8c).
  • It is kept only while marketing consent allows, and stored encrypted.

Switch

The remote container-config key klaviyoSessionToken, off by default. init() can never turn it on. Ingest serves it only to workspaces named in INGEST_KLAVIYO_SESSION_TOKEN (off, in datalyr/datalyr#884), and never to sensitive verticals. Turning it off clears what was kept.

Reviews

  • An independent verify read this PR and raised one finding, N3: a token not yet used would carry into a later session, and reset() did not clear it. It is closed in 28c4f8c with two tests.
  • The security review (A2) and the send-path review (B2) covered the worker side that verifies the token.

Not built or not tested

  • The N3 tests were written before the fix, but the local test run hung on the laptop's iCloud file stalls, so CI on 28c4f8c is the first run.
  • The Shopify Web Pixel does not keep the token. That is listed, not built.
  • Not tried in a real browser.

Release

This is an SDK release. After it, datalyr/datalyr repins infra/tracking/dl.dev.js and rebuilds dl.js and dl.min.js, and the website-script upload carries those three. It touches no postback, ingest, queue, sync, api, cleanup, edge or webhooks files.

🤖 Generated with Claude Code

czypnt and others added 2 commits November 24, 2026 11:50
…itch, off)

With the container config switch klaviyoSessionToken (served by ingest only
when INGEST_KLAVIYO_SESSION_TOKEN names the workspace; init() cannot set it),
a dl_kprofile_id that has a DATALYR-signed shape (dlk1 / dlk2, never a raw id)
is kept, encrypted, for the browser session, never past a dlk2 token's own
expiry, and added as external_ids.klaviyo to each later view_item,
add_to_cart and checkout_started. Ingest verifies it on every event. A new
session, withdrawn marketing consent or the switch going off drops it. Raw
ids keep today's one-shot. Off: nothing stored, nothing added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…leared by reset()

A token never used in its session is dropped at the next session; a session change or reset() drops it. Tests: klaviyo-session-token.test.ts (two new cases).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant