@shware/analytics 13.0.3 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/link/index.cjs +17 -13
- package/dist/link/index.cjs.map +1 -1
- package/dist/link/index.d.cts +7 -0
- package/dist/link/index.d.cts.map +1 -1
- package/dist/link/index.d.mts +7 -0
- package/dist/link/index.d.mts.map +1 -1
- package/dist/link/index.mjs +17 -13
- package/dist/link/index.mjs.map +1 -1
- package/dist/native/index.cjs +1 -1
- package/dist/native/index.mjs +1 -1
- package/dist/react-router/index.cjs +1 -1
- package/dist/react-router/index.mjs +1 -1
- package/dist/tanstack/analytics.cjs +1 -1
- package/dist/tanstack/analytics.mjs +1 -1
- package/dist/third-parties/google-analytics.cjs +1 -1
- package/dist/third-parties/google-analytics.cjs.map +1 -1
- package/dist/third-parties/google-analytics.mjs +1 -1
- package/dist/third-parties/google-analytics.mjs.map +1 -1
- package/dist/third-parties/meta-pixel.cjs +1 -1
- package/dist/third-parties/meta-pixel.mjs +1 -1
- package/dist/third-parties/posthog.cjs +7 -2
- package/dist/third-parties/posthog.cjs.map +1 -1
- package/dist/third-parties/posthog.d.cts +3 -0
- package/dist/third-parties/posthog.d.cts.map +1 -1
- package/dist/third-parties/posthog.d.mts +3 -0
- package/dist/third-parties/posthog.d.mts.map +1 -1
- package/dist/third-parties/posthog.mjs +7 -2
- package/dist/third-parties/posthog.mjs.map +1 -1
- package/dist/track/gtag.cjs.map +1 -1
- package/dist/track/gtag.d.cts +2 -2
- package/dist/track/gtag.d.mts +2 -2
- package/dist/track/gtag.mjs.map +1 -1
- package/dist/track/index.cjs +4 -1
- package/dist/track/index.cjs.map +1 -1
- package/dist/track/index.d.cts +6 -2
- package/dist/track/index.d.cts.map +1 -1
- package/dist/track/index.d.mts +6 -2
- package/dist/track/index.d.mts.map +1 -1
- package/dist/track/index.mjs +4 -1
- package/dist/track/index.mjs.map +1 -1
- package/dist/track/once.cjs +11 -1
- package/dist/track/once.cjs.map +1 -1
- package/dist/track/once.d.cts +7 -1
- package/dist/track/once.d.cts.map +1 -1
- package/dist/track/once.d.mts +7 -1
- package/dist/track/once.d.mts.map +1 -1
- package/dist/track/once.mjs +11 -1
- package/dist/track/once.mjs.map +1 -1
- package/dist/visitor/id.cjs.map +1 -1
- package/dist/visitor/id.mjs.map +1 -1
- package/dist/visitor/index.cjs +13 -4
- package/dist/visitor/index.cjs.map +1 -1
- package/dist/visitor/index.d.cts +6 -1
- package/dist/visitor/index.d.cts.map +1 -1
- package/dist/visitor/index.d.mts +6 -1
- package/dist/visitor/index.d.mts.map +1 -1
- package/dist/visitor/index.mjs +13 -4
- package/dist/visitor/index.mjs.map +1 -1
- package/dist/web/index.cjs +5 -4
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts.map +1 -1
- package/dist/web/index.d.mts.map +1 -1
- package/dist/web/index.mjs +5 -4
- package/dist/web/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/track/once.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"once.mjs","names":["uuidv7"],"sources":["../../src/track/once.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { config } from '../setup/index';\nimport { type TrackOptions, queueEvent } from './index';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport interface TrackOnceOptions extends TrackOptions {\n /**\n * What makes this occurrence the same one again: a checkout session id for `purchase`, an order\n * id, a transaction id. Required, never derived from the properties, so the caller decides what\n * \"once\" means. The same key under another event name is a different occurrence.\n */\n key: string;\n /** How long a sent key is remembered, in milliseconds. 90 days by default. */\n ttl?: number;\n}\n\nconst DEFAULT_TTL = 90 * 24 * 60 * 60 * 1000;\n/** Keys remembered per event name; the oldest are forgotten first. */\nconst MAX_ENTRIES = 20;\n\n/**\n * `{\"v\":2,\"entries\":[[key, id, expiresAt, sent], …]}`, oldest first. Entries are tuples in an\n * array rather than an object keyed by `key`: an object would move integer-like keys (\"123\") to\n * the front and lose the order the oldest are dropped by. Escaping the value for the medium is the\n * storage's job, so this is plain JSON.\n *\n * `id` is the event id the key goes out under, decided by the first call and kept while `sent`\n * is false — a send that failed, or a page reloaded before its batch went out. The third-party\n * trackers fire when the event is tracked, not when it is sent, so that first call has already\n * reported the occurrence to them: the next call reuses the id, fires none of them again, and\n * the server (`on conflict (id) do nothing`) stores the event once even if the failed send had in\n * fact arrived.\n *\n * Version 1 records (`[key, expiresAt]`, written before the id was kept) are read as sent: that\n * is all a v1 record ever held, and dropping them would report every remembered occurrence again.\n */\nconst VERSION = 2;\n\ntype Entry = { key: string; id: string; expiresAt: number; sent: boolean };\n\nfunction storageKey(name: string) {\n return `track_once.${name}`;\n}\n\n/** The stored entries, or none for a record that is missing, of another version or malformed. */\nfunction read(name: string): Entry[] {\n const raw = config.storage.getItem(storageKey(name));\n if (!raw) return [];\n let record: unknown;\n try {\n record = JSON.parse(raw);\n } catch {\n return [];\n }\n if (typeof record !== 'object' || record === null) return [];\n const { v, entries } = record as { v?: unknown; entries?: unknown };\n if (!Array.isArray(entries)) return [];\n if (v === 1) {\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, expiresAt] = entry as unknown[];\n if (typeof key !== 'string' || typeof expiresAt !== 'number') return [];\n // Sent is all v1 remembered; the id it went out under is gone, and no longer needed.\n return [{ key, id: '', expiresAt, sent: true }];\n });\n }\n if (v !== VERSION) return [];\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, id, expiresAt, sent] = entry as unknown[];\n if (typeof key !== 'string' || typeof id !== 'string' || typeof expiresAt !== 'number') {\n return [];\n }\n if (typeof sent !== 'boolean') return [];\n return [{ key, id, expiresAt, sent }];\n });\n}\n\nfunction write(name: string, entries: Entry[]) {\n const record = {\n v: VERSION,\n entries: entries.slice(-MAX_ENTRIES).map((e) => [e.key, e.id, e.expiresAt, e.sent]),\n };\n config.storage.setItem(storageKey(name), JSON.stringify(record));\n}\n\nfunction live(entries: Entry[], now: number) {\n return entries.filter((entry) => entry.expiresAt > now);\n}\n\n/** Keys queued in this page (or app process) but not confirmed sent yet, per event name. */\nconst pending = new Map<string, Set<string>>();\n\nfunction isPending(name: string, key: string) {\n return pending.get(name)?.has(key) ?? false;\n}\n\nfunction markPending(name: string, key: string) {\n const keys = pending.get(name);\n if (keys) keys.add(key);\n else pending.set(name, new Set([key]));\n}\n\nfunction clearPending(name: string, key: string) {\n const keys = pending.get(name);\n if (!keys) return;\n keys.delete(key);\n if (keys.size === 0) pending.delete(name);\n}\n\n/**\n * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a\n * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event\n * was queued.\n *\n * The key is marked sent in `config.storage` only once the event has been sent (`onSucceed`), so a\n * send that fails is tried again by the next call instead of being lost — under the same event id,\n * so the third-party trackers fired by the first call are not fired again (see `VERSION`); within\n * one page a key already queued is not queued twice. When the storage cannot be read or written\n * the event is tracked anyway: a rare duplicate is better than a lost conversion.\n *\n * Deduplication is per device and storage. A second device still reports its own occurrence, so\n * figures that must be exact (revenue) belong to server-side records.\n */\nexport function trackOnce<T extends EventName = EventName>(\n name: TrackName<T>,\n properties: TrackProperties<T> | undefined,\n { key, ttl = DEFAULT_TTL, ...options }: TrackOnceOptions\n): boolean {\n if (isPending(name, key)) return false;\n\n const now = Date.now();\n // An earlier call that failed to send: its id, and its pixels already fired.\n let earlier: Entry | undefined;\n let id = uuidv7();\n try {\n const entries = live(read(name), now);\n earlier = entries.find((entry) => entry.key === key);\n if (earlier?.sent) return false;\n if (earlier) id = earlier.id;\n else write(name, [...entries, { key, id, expiresAt: now + ttl, sent: false }]);\n } catch (e: unknown) {\n // Unrecorded, a failed send would fire the pixels again on the next call: a rare duplicate\n // there beats not tracking.\n if (e instanceof Error) console.log(e.message);\n }\n\n markPending(name, key);\n queueEvent(\n name,\n properties,\n {\n ...options,\n onSucceed: (response) => {\n clearPending(name, key);\n try {\n const entries = live(read(name), Date.now()).filter((entry) => entry.key !== key);\n write(name, [...entries, { key, id, expiresAt: Date.now() + ttl, sent: true }]);\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n options.onSucceed?.(response);\n },\n onError: (error) => {\n // Not sent: the entry stays unsent, with its id, so a later call can try again.\n clearPending(name, key);\n options.onError?.(error);\n },\n },\n earlier ? { id, pixels: false } : { id }\n );\n return true;\n}\n"],"mappings":";;;;AAgBA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAoBpB,MAAM,UAAU;AAIhB,SAAS,WAAW,MAAc;CAChC,OAAO,cAAc;AACvB;;AAGA,SAAS,KAAK,MAAuB;CACnC,MAAM,MAAM,OAAO,QAAQ,QAAQ,WAAW,IAAI,CAAC;CACnD,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,GAAG;CACzB,QAAQ;EACN,OAAO,CAAC;CACV;CACA,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO,CAAC;CAC3D,MAAM,EAAE,GAAG,YAAY;CACvB,IAAI,CAAC,MAAM,QAAQ,OAAO,GAAG,OAAO,CAAC;CACrC,IAAI,MAAM,GACR,OAAO,QAAQ,SAAS,UAAmB;EACzC,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC;EACnC,MAAM,CAAC,KAAK,aAAa;EACzB,IAAI,OAAO,QAAQ,YAAY,OAAO,cAAc,UAAU,OAAO,CAAC;EAEtE,OAAO,CAAC;GAAE;GAAK,IAAI;GAAI;GAAW,MAAM;EAAK,CAAC;CAChD,CAAC;CAEH,IAAI,MAAM,SAAS,OAAO,CAAC;CAC3B,OAAO,QAAQ,SAAS,UAAmB;EACzC,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC;EACnC,MAAM,CAAC,KAAK,IAAI,WAAW,QAAQ;EACnC,IAAI,OAAO,QAAQ,YAAY,OAAO,OAAO,YAAY,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AAQ,MAAM,UAAU,MAAM,QAAQ,GAAG;EACnD,IAAI,SAAS,MAAM,OAAO;EAC1B,IAAI,SAAS,KAAK,QAAQ;OACrB,MAAM,MAAM,CAAC,GAAG,SAAS;GAAE;GAAK;GAAI,WAAW,MAAM;GAAK,MAAM;EAAM,CAAC,CAAC;CAC/E,SAAS,GAAY;EAGnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;CAC/C;CAEA,YAAY,MAAM,GAAG;CACrB,WACE,MACA,YACA;EACE,GAAG;EACH,YAAY,aAAa;GACvB,aAAa,MAAM,GAAG;GACtB,IAAI;IAEF,MAAM,MAAM,CAAC,GADG,KAAK,KAAK,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,UAAU,MAAM,QAAQ,GACvD,GAAG;KAAE;KAAK;KAAI,WAAW,KAAK,IAAI,IAAI;KAAK,MAAM;IAAK,CAAC,CAAC;GAChF,SAAS,GAAY;IACnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;GAC/C;GACA,QAAQ,YAAY,QAAQ;EAC9B;EACA,UAAU,UAAU;GAElB,aAAa,MAAM,GAAG;GACtB,QAAQ,UAAU,KAAK;EACzB;CACF,GACA,UAAU;EAAE;EAAI,QAAQ;CAAM,IAAI,EAAE,GAAG,CACzC;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"once.mjs","names":["uuidv7"],"sources":["../../src/track/once.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { config } from '../setup/index';\nimport { type TrackOptions, queueEvent } from './index';\nimport type { EventName, TrackName, TrackProperties } from './types';\n\nexport interface TrackOnceOptions extends TrackOptions {\n /**\n * What makes this occurrence the same one again: a checkout session id for `purchase`, an order\n * id, a transaction id. Required, never derived from the properties, so the caller decides what\n * \"once\" means. The same key under another event name is a different occurrence.\n */\n key: string;\n /** How long a sent key is remembered, in milliseconds. 90 days by default. */\n ttl?: number;\n}\n\nconst DEFAULT_TTL = 90 * 24 * 60 * 60 * 1000;\n/** Keys remembered per event name; the oldest are forgotten first. */\nconst MAX_ENTRIES = 20;\n\n/**\n * `{\"v\":2,\"entries\":[[key, id, expiresAt, sent], …]}`, oldest first. Entries are tuples in an\n * array rather than an object keyed by `key`: an object would move integer-like keys (\"123\") to\n * the front and lose the order the oldest are dropped by. Escaping the value for the medium is the\n * storage's job, so this is plain JSON.\n *\n * `id` is the event id the key goes out under, decided by the first call and kept while `sent`\n * is false — a send that failed, or a page reloaded before its batch went out. The third-party\n * trackers fire when the event is tracked, not when it is sent, so that first call has already\n * reported the occurrence to them: the next call reuses the id, fires none of them again, and\n * the server (`on conflict (id) do nothing`) stores the event once even if the failed send had in\n * fact arrived.\n *\n * Version 1 records (`[key, expiresAt]`, written before the id was kept) are read as sent: that\n * is all a v1 record ever held, and dropping them would report every remembered occurrence again.\n */\nconst VERSION = 2;\n\ntype Entry = { key: string; id: string; expiresAt: number; sent: boolean };\n\nfunction storageKey(name: string) {\n return `track_once.${name}`;\n}\n\n/** The stored entries, or none for a record that is missing, of another version or malformed. */\nfunction read(name: string): Entry[] {\n const raw = config.storage.getItem(storageKey(name));\n if (!raw) return [];\n let record: unknown;\n try {\n record = JSON.parse(raw);\n } catch {\n return [];\n }\n if (typeof record !== 'object' || record === null) return [];\n const { v, entries } = record as { v?: unknown; entries?: unknown };\n if (!Array.isArray(entries)) return [];\n if (v === 1) {\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, expiresAt] = entry as unknown[];\n if (typeof key !== 'string' || typeof expiresAt !== 'number') return [];\n // Sent is all v1 remembered; the id it went out under is gone, and no longer needed.\n return [{ key, id: '', expiresAt, sent: true }];\n });\n }\n if (v !== VERSION) return [];\n return entries.flatMap((entry: unknown) => {\n if (!Array.isArray(entry)) return [];\n const [key, id, expiresAt, sent] = entry as unknown[];\n if (typeof key !== 'string' || typeof id !== 'string' || typeof expiresAt !== 'number') {\n return [];\n }\n if (typeof sent !== 'boolean') return [];\n return [{ key, id, expiresAt, sent }];\n });\n}\n\nfunction write(name: string, entries: Entry[]) {\n const record = {\n v: VERSION,\n entries: entries.slice(-MAX_ENTRIES).map((e) => [e.key, e.id, e.expiresAt, e.sent]),\n };\n config.storage.setItem(storageKey(name), JSON.stringify(record));\n}\n\nfunction live(entries: Entry[], now: number) {\n return entries.filter((entry) => entry.expiresAt > now);\n}\n\n/** Keys queued in this page (or app process) but not confirmed sent yet, per event name. */\nconst pending = new Map<string, Set<string>>();\n\nfunction isPending(name: string, key: string) {\n return pending.get(name)?.has(key) ?? false;\n}\n\nfunction markPending(name: string, key: string) {\n const keys = pending.get(name);\n if (keys) keys.add(key);\n else pending.set(name, new Set([key]));\n}\n\nfunction clearPending(name: string, key: string) {\n const keys = pending.get(name);\n if (!keys) return;\n keys.delete(key);\n if (keys.size === 0) pending.delete(name);\n}\n\n/**\n * Tracks an event at most once per `key`: a reloaded or revisited payment result page, a\n * re-delivered store transaction, a confirmation screen opened twice. Returns whether the event\n * was queued.\n *\n * The key is marked sent in `config.storage` only once the event has been sent (`onSucceed`), so a\n * send that fails is tried again by the next call instead of being lost — under the same event id,\n * so the third-party trackers fired by the first call are not fired again (see `VERSION`); within\n * one page a key already queued is not queued twice.\n *\n * An event that leaves by beacon (`sendPendingEvents`, the page hidden or left) is not marked\n * sent: a beacon cannot tell delivered from dropped, so it counts as unconfirmed and the entry\n * stays unsent with its id. The next call for the key — the result page opened again — sends the\n * event once more under that id and without pixels, which the server ignores when the beacon did\n * arrive (it drops an event id it already has): one idempotent request more, against a lost one. When the storage cannot be read or written\n * the event is tracked anyway: a rare duplicate is better than a lost conversion.\n *\n * Deduplication is per device and storage. A second device still reports its own occurrence, so\n * figures that must be exact (revenue) belong to server-side records.\n */\nexport function trackOnce<T extends EventName = EventName>(\n name: TrackName<T>,\n properties: TrackProperties<T> | undefined,\n { key, ttl = DEFAULT_TTL, ...options }: TrackOnceOptions\n): boolean {\n if (isPending(name, key)) return false;\n\n const now = Date.now();\n // An earlier call that failed to send: its id, and its pixels already fired.\n let earlier: Entry | undefined;\n let id = uuidv7();\n try {\n const entries = live(read(name), now);\n earlier = entries.find((entry) => entry.key === key);\n if (earlier?.sent) return false;\n if (earlier) id = earlier.id;\n else write(name, [...entries, { key, id, expiresAt: now + ttl, sent: false }]);\n } catch (e: unknown) {\n // Unrecorded, a failed send would fire the pixels again on the next call: a rare duplicate\n // there beats not tracking.\n if (e instanceof Error) console.log(e.message);\n }\n\n markPending(name, key);\n queueEvent(\n name,\n properties,\n {\n ...options,\n onSucceed: (response) => {\n clearPending(name, key);\n // A beacon was only queued by the browser: the entry stays unsent, so a later call\n // sends it again under the same id.\n if (response?.beacon) {\n options.onSucceed?.(response);\n return;\n }\n try {\n const entries = live(read(name), Date.now()).filter((entry) => entry.key !== key);\n write(name, [...entries, { key, id, expiresAt: Date.now() + ttl, sent: true }]);\n } catch (e: unknown) {\n if (e instanceof Error) console.log(e.message);\n }\n options.onSucceed?.(response);\n },\n onError: (error) => {\n // Not sent: the entry stays unsent, with its id, so a later call can try again.\n clearPending(name, key);\n options.onError?.(error);\n },\n },\n earlier ? { id, pixels: false } : { id }\n );\n return true;\n}\n"],"mappings":";;;;AAgBA,MAAM,cAAc;;;;;;;;;;;;;;;;;AAoBpB,MAAM,UAAU;AAIhB,SAAS,WAAW,MAAc;CAChC,OAAO,cAAc;AACvB;;AAGA,SAAS,KAAK,MAAuB;CACnC,MAAM,MAAM,OAAO,QAAQ,QAAQ,WAAW,IAAI,CAAC;CACnD,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,IAAI;CACJ,IAAI;EACF,SAAS,KAAK,MAAM,GAAG;CACzB,QAAQ;EACN,OAAO,CAAC;CACV;CACA,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,OAAO,CAAC;CAC3D,MAAM,EAAE,GAAG,YAAY;CACvB,IAAI,CAAC,MAAM,QAAQ,OAAO,GAAG,OAAO,CAAC;CACrC,IAAI,MAAM,GACR,OAAO,QAAQ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B,aAAa,MAAM,GAAG;GACtB,QAAQ,UAAU,KAAK;EACzB;CACF,GACA,UAAU;EAAE;EAAI,QAAQ;CAAM,IAAI,EAAE,GAAG,CACzC;CACA,OAAO;AACT"}
|
package/dist/visitor/id.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id.cjs","names":["config","keys","uuidv7"],"sources":["../../src/visitor/id.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { config } from '../setup/index';\n\n/**\n * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so\n * it exists the moment the page loads. The first events, and the beacon of a visit left within a\n * second, go out without waiting for a round trip; the server creates the visitor from its first\n * events. An id a server issued to an older client is kept as it is: the visitor continues.\n *\n * Needs a server that creates visitors from events (see the README, \"Visitors\"); one that still\n * only creates them on `POST /visitors` rejects the events of a new visitor.\n */\nexport function visitorId(): string {\n const stored = config.storage.getItem(keys.visitor_id);\n if (stored && stored !== 'undefined') return stored;\n const id = uuidv7();\n config.storage.setItem(keys.visitor_id, id);\n return id;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,YAAoB;CAClC,MAAM,SAASA,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,UAAU;
|
|
1
|
+
{"version":3,"file":"id.cjs","names":["config","keys","uuidv7"],"sources":["../../src/visitor/id.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { config } from '../setup/index';\n\n/**\n * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so\n * it exists the moment the page loads. The first events, and the beacon of a visit left within a\n * second, go out without waiting for a round trip; the server creates the visitor from its first\n * events. An id a server issued to an older client is kept as it is: the visitor continues.\n *\n * Needs a server that creates visitors from events (see the README, \"Visitors\"); one that still\n * only creates them on `POST /visitors` rejects the events of a new visitor.\n */\nexport function visitorId(): string {\n const stored = config.storage.getItem(keys.visitor_id);\n // An old client stored the string 'undefined' as the id (it wrote an unset id): not an id, so it\n // is replaced below with a new one, which also clears the bad value from storage for good.\n if (stored && stored !== 'undefined') return stored;\n const id = uuidv7();\n config.storage.setItem(keys.visitor_id, id);\n return id;\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,YAAoB;CAClC,MAAM,SAASA,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,UAAU;CAGrD,IAAI,UAAU,WAAW,aAAa,OAAO;CAC7C,MAAM,MAAA,GAAKC,KAAAA,GAAAA,CAAO;CAClB,oBAAA,OAAO,QAAQ,QAAQD,0BAAAA,KAAK,YAAY,EAAE;CAC1C,OAAO;AACT"}
|
package/dist/visitor/id.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id.mjs","names":["uuidv7"],"sources":["../../src/visitor/id.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { config } from '../setup/index';\n\n/**\n * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so\n * it exists the moment the page loads. The first events, and the beacon of a visit left within a\n * second, go out without waiting for a round trip; the server creates the visitor from its first\n * events. An id a server issued to an older client is kept as it is: the visitor continues.\n *\n * Needs a server that creates visitors from events (see the README, \"Visitors\"); one that still\n * only creates them on `POST /visitors` rejects the events of a new visitor.\n */\nexport function visitorId(): string {\n const stored = config.storage.getItem(keys.visitor_id);\n if (stored && stored !== 'undefined') return stored;\n const id = uuidv7();\n config.storage.setItem(keys.visitor_id, id);\n return id;\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,YAAoB;CAClC,MAAM,SAAS,OAAO,QAAQ,QAAQ,KAAK,UAAU;
|
|
1
|
+
{"version":3,"file":"id.mjs","names":["uuidv7"],"sources":["../../src/visitor/id.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { config } from '../setup/index';\n\n/**\n * This visitor's id: generated here on the first visit (uuidv7) and kept in `config.storage`, so\n * it exists the moment the page loads. The first events, and the beacon of a visit left within a\n * second, go out without waiting for a round trip; the server creates the visitor from its first\n * events. An id a server issued to an older client is kept as it is: the visitor continues.\n *\n * Needs a server that creates visitors from events (see the README, \"Visitors\"); one that still\n * only creates them on `POST /visitors` rejects the events of a new visitor.\n */\nexport function visitorId(): string {\n const stored = config.storage.getItem(keys.visitor_id);\n // An old client stored the string 'undefined' as the id (it wrote an unset id): not an id, so it\n // is replaced below with a new one, which also clears the bad value from storage for good.\n if (stored && stored !== 'undefined') return stored;\n const id = uuidv7();\n config.storage.setItem(keys.visitor_id, id);\n return id;\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,YAAoB;CAClC,MAAM,SAAS,OAAO,QAAQ,QAAQ,KAAK,UAAU;CAGrD,IAAI,UAAU,WAAW,aAAa,OAAO;CAC7C,MAAM,KAAKA,GAAO;CAClB,OAAO,QAAQ,QAAQ,KAAK,YAAY,EAAE;CAC1C,OAAO;AACT"}
|
package/dist/visitor/index.cjs
CHANGED
|
@@ -9,7 +9,10 @@ const require_track_index = require("../track/index.cjs");
|
|
|
9
9
|
* batch — which also creates the visitor when it is new, so the binding can never arrive before it.
|
|
10
10
|
*/
|
|
11
11
|
const IDENTIFY_EVENT = "identify";
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The user this page has identified the visitor as: identify once per user, not per call. Cleared
|
|
14
|
+
* on sign-out, so the same user signing back in on this page is identified again.
|
|
15
|
+
*/
|
|
13
16
|
let identified;
|
|
14
17
|
/**
|
|
15
18
|
* Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,
|
|
@@ -18,16 +21,22 @@ let identified;
|
|
|
18
21
|
* event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters
|
|
19
22
|
* only, never stored with the event.
|
|
20
23
|
*
|
|
21
|
-
*
|
|
24
|
+
* Without a `user_id` (missing, or `''`) it signs the visitor out: `setVisitor({})` is
|
|
25
|
+
* sign-out. Nothing goes to the server, the setters get `distinct_id: null` (PostHog resets its
|
|
26
|
+
* identity on it), and the next sign-in is identified again even if it is the same user. Still
|
|
27
|
+
* `track('logout')` as usual — that is an ordinary event, and resets nothing.
|
|
28
|
+
*
|
|
29
|
+
* Synchronous and never throws: sign-in and sign-out must not fail on analytics.
|
|
22
30
|
*/
|
|
23
31
|
function setVisitor(dto) {
|
|
24
|
-
if (dto.user_id
|
|
32
|
+
if (!dto.user_id) identified = void 0;
|
|
33
|
+
else if (dto.user_id !== identified) {
|
|
25
34
|
identified = dto.user_id;
|
|
26
35
|
require_track_index.track(IDENTIFY_EVENT, { user_id: dto.user_id }, { enableThirdPartyTracking: false });
|
|
27
36
|
}
|
|
28
37
|
const identity = {
|
|
29
38
|
...dto,
|
|
30
|
-
distinct_id: dto.user_id
|
|
39
|
+
distinct_id: dto.user_id || null
|
|
31
40
|
};
|
|
32
41
|
require_setup_index.config.thirdPartyUserSetters.forEach((setter) => {
|
|
33
42
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { config } from '../setup/index';\nimport { track } from '../track/index';\n\nexport { visitorId } from './id';\n\n/**\n * The event that binds the visitor to the user who signed in on it: the server sets the visitor's\n * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the\n * batch — which also creates the visitor when it is new, so the binding can never arrive before it.\n */\nexport const IDENTIFY_EVENT = 'identify';\n\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { config } from '../setup/index';\nimport { track } from '../track/index';\n\nexport { visitorId } from './id';\n\n/**\n * The event that binds the visitor to the user who signed in on it: the server sets the visitor's\n * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the\n * batch — which also creates the visitor when it is new, so the binding can never arrive before it.\n */\nexport const IDENTIFY_EVENT = 'identify';\n\n/**\n * The user this page has identified the visitor as: identify once per user, not per call. Cleared\n * on sign-out, so the same user signing back in on this page is identified again.\n */\nlet identified: string | undefined;\n\n/**\n * Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,\n * and the server through an `identify` event, sent when the user differs from the one this page\n * last identified — a host calls this on every page load once someone is signed in. Like any\n * event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters\n * only, never stored with the event.\n *\n * Without a `user_id` (missing, or `''`) it signs the visitor out: `setVisitor({})` is\n * sign-out. Nothing goes to the server, the setters get `distinct_id: null` (PostHog resets its\n * identity on it), and the next sign-in is identified again even if it is the same user. Still\n * `track('logout')` as usual — that is an ordinary event, and resets nothing.\n *\n * Synchronous and never throws: sign-in and sign-out must not fail on analytics.\n */\nexport function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>) {\n if (!dto.user_id) {\n identified = undefined;\n } else if (dto.user_id !== identified) {\n identified = dto.user_id;\n track(IDENTIFY_EVENT, { user_id: dto.user_id }, { enableThirdPartyTracking: false });\n }\n\n // Once bound, the server's person key for the visitor is the user's id, so the setters are told\n // that rather than waiting for the server to say it.\n const identity = { ...dto, distinct_id: dto.user_id || null };\n config.thirdPartyUserSetters.forEach((setter) => {\n try {\n setter(identity);\n } catch (e: unknown) {\n // One third-party script does not get to stop the others.\n if (e instanceof Error) console.log(e.message);\n }\n });\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAa,iBAAiB;;;;;AAM9B,IAAI;;;;;;;;;;;;;;;AAgBJ,SAAgB,WAAW,KAAqC;CAC9D,IAAI,CAAC,IAAI,SACP,aAAa,KAAA;MACR,IAAI,IAAI,YAAY,YAAY;EACrC,aAAa,IAAI;EACjB,oBAAA,MAAM,gBAAgB,EAAE,SAAS,IAAI,QAAQ,GAAG,EAAE,0BAA0B,MAAM,CAAC;CACrF;CAIA,MAAM,WAAW;EAAE,GAAG;EAAK,aAAa,IAAI,WAAW;CAAK;CAC5D,oBAAA,OAAO,sBAAsB,SAAS,WAAW;EAC/C,IAAI;GACF,OAAO,QAAQ;EACjB,SAAS,GAAY;GAEnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;EAC/C;CACF,CAAC;AACH"}
|
package/dist/visitor/index.d.cts
CHANGED
|
@@ -14,7 +14,12 @@ export declare const IDENTIFY_EVENT = "identify";
|
|
|
14
14
|
* event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters
|
|
15
15
|
* only, never stored with the event.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
17
|
+
* Without a `user_id` (missing, or `''`) it signs the visitor out: `setVisitor({})` is
|
|
18
|
+
* sign-out. Nothing goes to the server, the setters get `distinct_id: null` (PostHog resets its
|
|
19
|
+
* identity on it), and the next sign-in is identified again even if it is the same user. Still
|
|
20
|
+
* `track('logout')` as usual — that is an ordinary event, and resets nothing.
|
|
21
|
+
*
|
|
22
|
+
* Synchronous and never throws: sign-in and sign-out must not fail on analytics.
|
|
18
23
|
*/
|
|
19
24
|
export declare function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>): void;
|
|
20
25
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;qBAWa
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;qBAWa;;;;;;;;;;;;;;;wBAsBG,WAAW,KAAK,KAAK"}
|
package/dist/visitor/index.d.mts
CHANGED
|
@@ -14,7 +14,12 @@ export declare const IDENTIFY_EVENT = "identify";
|
|
|
14
14
|
* event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters
|
|
15
15
|
* only, never stored with the event.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
17
|
+
* Without a `user_id` (missing, or `''`) it signs the visitor out: `setVisitor({})` is
|
|
18
|
+
* sign-out. Nothing goes to the server, the setters get `distinct_id: null` (PostHog resets its
|
|
19
|
+
* identity on it), and the next sign-in is identified again even if it is the same user. Still
|
|
20
|
+
* `track('logout')` as usual — that is an ordinary event, and resets nothing.
|
|
21
|
+
*
|
|
22
|
+
* Synchronous and never throws: sign-in and sign-out must not fail on analytics.
|
|
18
23
|
*/
|
|
19
24
|
export declare function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>): void;
|
|
20
25
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;qBAWa
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/visitor/index.ts"],"mappings":";;;;;;;;qBAWa;;;;;;;;;;;;;;;wBAsBG,WAAW,KAAK,KAAK"}
|
package/dist/visitor/index.mjs
CHANGED
|
@@ -8,7 +8,10 @@ import { track } from "../track/index.mjs";
|
|
|
8
8
|
* batch — which also creates the visitor when it is new, so the binding can never arrive before it.
|
|
9
9
|
*/
|
|
10
10
|
const IDENTIFY_EVENT = "identify";
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The user this page has identified the visitor as: identify once per user, not per call. Cleared
|
|
13
|
+
* on sign-out, so the same user signing back in on this page is identified again.
|
|
14
|
+
*/
|
|
12
15
|
let identified;
|
|
13
16
|
/**
|
|
14
17
|
* Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,
|
|
@@ -17,16 +20,22 @@ let identified;
|
|
|
17
20
|
* event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters
|
|
18
21
|
* only, never stored with the event.
|
|
19
22
|
*
|
|
20
|
-
*
|
|
23
|
+
* Without a `user_id` (missing, or `''`) it signs the visitor out: `setVisitor({})` is
|
|
24
|
+
* sign-out. Nothing goes to the server, the setters get `distinct_id: null` (PostHog resets its
|
|
25
|
+
* identity on it), and the next sign-in is identified again even if it is the same user. Still
|
|
26
|
+
* `track('logout')` as usual — that is an ordinary event, and resets nothing.
|
|
27
|
+
*
|
|
28
|
+
* Synchronous and never throws: sign-in and sign-out must not fail on analytics.
|
|
21
29
|
*/
|
|
22
30
|
function setVisitor(dto) {
|
|
23
|
-
if (dto.user_id
|
|
31
|
+
if (!dto.user_id) identified = void 0;
|
|
32
|
+
else if (dto.user_id !== identified) {
|
|
24
33
|
identified = dto.user_id;
|
|
25
34
|
track(IDENTIFY_EVENT, { user_id: dto.user_id }, { enableThirdPartyTracking: false });
|
|
26
35
|
}
|
|
27
36
|
const identity = {
|
|
28
37
|
...dto,
|
|
29
|
-
distinct_id: dto.user_id
|
|
38
|
+
distinct_id: dto.user_id || null
|
|
30
39
|
};
|
|
31
40
|
config.thirdPartyUserSetters.forEach((setter) => {
|
|
32
41
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { config } from '../setup/index';\nimport { track } from '../track/index';\n\nexport { visitorId } from './id';\n\n/**\n * The event that binds the visitor to the user who signed in on it: the server sets the visitor's\n * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the\n * batch — which also creates the visitor when it is new, so the binding can never arrive before it.\n */\nexport const IDENTIFY_EVENT = 'identify';\n\n
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/visitor/index.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport { config } from '../setup/index';\nimport { track } from '../track/index';\n\nexport { visitorId } from './id';\n\n/**\n * The event that binds the visitor to the user who signed in on it: the server sets the visitor's\n * `user_id` and `distinct_id` from its `user_id` property, in the transaction that stores the\n * batch — which also creates the visitor when it is new, so the binding can never arrive before it.\n */\nexport const IDENTIFY_EVENT = 'identify';\n\n/**\n * The user this page has identified the visitor as: identify once per user, not per call. Cleared\n * on sign-out, so the same user signing back in on this page is identified again.\n */\nlet identified: string | undefined;\n\n/**\n * Hands the signed-in user to the analytics: the third-party user setters (gtag, the pixels) now,\n * and the server through an `identify` event, sent when the user differs from the one this page\n * last identified — a host calls this on every page load once someone is signed in. Like any\n * event it goes with the next batch or the page-hide beacon; `user_data` is handed to the setters\n * only, never stored with the event.\n *\n * Without a `user_id` (missing, or `''`) it signs the visitor out: `setVisitor({})` is\n * sign-out. Nothing goes to the server, the setters get `distinct_id: null` (PostHog resets its\n * identity on it), and the next sign-in is identified again even if it is the same user. Still\n * `track('logout')` as usual — that is an ordinary event, and resets nothing.\n *\n * Synchronous and never throws: sign-in and sign-out must not fail on analytics.\n */\nexport function setVisitor(dto: Omit<UpdateVisitorDTO, 'tags'>) {\n if (!dto.user_id) {\n identified = undefined;\n } else if (dto.user_id !== identified) {\n identified = dto.user_id;\n track(IDENTIFY_EVENT, { user_id: dto.user_id }, { enableThirdPartyTracking: false });\n }\n\n // Once bound, the server's person key for the visitor is the user's id, so the setters are told\n // that rather than waiting for the server to say it.\n const identity = { ...dto, distinct_id: dto.user_id || null };\n config.thirdPartyUserSetters.forEach((setter) => {\n try {\n setter(identity);\n } catch (e: unknown) {\n // One third-party script does not get to stop the others.\n if (e instanceof Error) console.log(e.message);\n }\n });\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,iBAAiB;;;;;AAM9B,IAAI;;;;;;;;;;;;;;;AAgBJ,SAAgB,WAAW,KAAqC;CAC9D,IAAI,CAAC,IAAI,SACP,aAAa,KAAA;MACR,IAAI,IAAI,YAAY,YAAY;EACrC,aAAa,IAAI;EACjB,MAAM,gBAAgB,EAAE,SAAS,IAAI,QAAQ,GAAG,EAAE,0BAA0B,MAAM,CAAC;CACrF;CAIA,MAAM,WAAW;EAAE,GAAG;EAAK,aAAa,IAAI,WAAW;CAAK;CAC5D,OAAO,sBAAsB,SAAS,WAAW;EAC/C,IAAI;GACF,OAAO,QAAQ;EACjB,SAAS,GAAY;GAEnB,IAAI,aAAa,OAAO,QAAQ,IAAI,EAAE,OAAO;EAC/C;CACF,CAAC;AACH"}
|
package/dist/web/index.cjs
CHANGED
|
@@ -3,8 +3,8 @@ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
|
3
3
|
const require_setup_index = require("../setup/index.cjs");
|
|
4
4
|
const require_constants_storage = require("../constants/storage.cjs");
|
|
5
5
|
const require_link_index = require("../link/index.cjs");
|
|
6
|
-
const require_es5$1 = require("../node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.cjs");
|
|
7
6
|
const require_utils_redact_url = require("../utils/redact-url.cjs");
|
|
7
|
+
const require_es5$1 = require("../node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.cjs");
|
|
8
8
|
const require_web_page_key = require("./page-key.cjs");
|
|
9
9
|
let uuid = require("uuid");
|
|
10
10
|
let cookie = require("cookie");
|
|
@@ -75,9 +75,10 @@ const links = /* @__PURE__ */ new Map();
|
|
|
75
75
|
function getCachedLink(id) {
|
|
76
76
|
const cached = links.get(id);
|
|
77
77
|
if (cached) return cached;
|
|
78
|
-
const link = require_link_index.getLink(id).then((result) => {
|
|
79
|
-
if (
|
|
80
|
-
|
|
78
|
+
const link = require_link_index.getLink(id).then((result) => result, (e) => {
|
|
79
|
+
if (e instanceof Error) console.error(e.message);
|
|
80
|
+
links.delete(id);
|
|
81
|
+
return null;
|
|
81
82
|
});
|
|
82
83
|
links.set(id, link);
|
|
83
84
|
return link;
|
package/dist/web/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["uuidv4","config","keys","redactUrl","getPageKey","getLink","Bowser","parseCookie"],"sources":["../../src/web/index.ts"],"sourcesContent":["import Bowser from 'bowser';\nimport { parseCookie } from 'cookie';\nimport { v4 as uuidv4 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { type Link, getLink } from '../link/index';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\nimport { redactUrl } from '../utils/redact-url';\nimport { getPageKey } from './page-key';\n\n// lib.dom types `crypto.randomUUID` as always present, but it is missing in insecure contexts\n// and older browsers, so probe it before use.\nfunction randomUUID(): string {\n return (crypto as Partial<Crypto>).randomUUID ? crypto.randomUUID() : uuidv4();\n}\n\nexport function getDeviceId() {\n const cached = config.storage.getItem(keys.device_id);\n if (cached) return cached;\n const id = randomUUID();\n config.storage.setItem(keys.device_id, id);\n return id;\n}\n\n/**\n * The current page load, keyed by the page it was loaded at. A module variable and nothing more\n * persistent: the id must die with the page (a reload is a new page load, and storage would\n * carry it over — or, shared across tabs, let two pages overwrite each other's).\n *\n * Keyed by `getPageKey` because that is what the SDK's own `page_view` fires on (see\n * `useWebAnalytics`): the id exists to link an event to the `page_view` of the page it happened\n * on, so it must rotate exactly when a `page_view` is sent — path or query change, yes; hash\n * change or tracking-parameter cleanup, no.\n *\n * `referrer` is the page's referrer as GA4 reports it in a single page app: `document.referrer`\n * for the document's first page, and the previous page's URL after an in-app navigation. The\n * browser never updates `document.referrer` on a `pushState`, so read alone it would name the\n * site the visit came from on every later page — and a session opened there, after 30 minutes\n * idle, would count that site as a second visit from it. With the previous page as its referrer,\n * that session's referrer is the product's own host: no touch, a direct session, which the\n * attribution view then credits to the touch before it.\n */\nlet pageLoad: { page: string; id: string; href: string; referrer: string | undefined } | undefined;\n\nfunction currentPage() {\n const href = redactUrl(window.location.href);\n const page = getPageKey(window.location.pathname, window.location.search);\n if (pageLoad?.page === page) {\n // The same page, its URL maybe cleaned of tracking parameters since: the next page's\n // referrer is the URL as it last was, as the browser's own would be.\n pageLoad.href = href;\n return pageLoad;\n }\n const referrer = pageLoad ? pageLoad.href : redactUrl(document.referrer) || undefined;\n pageLoad = { page, id: randomUUID(), href, referrer };\n return pageLoad;\n}\n\n/**\n * The current page's URL as reported, without its credential parameters (`redactUrl`), so\n * `page_location` never carries an OAuth code or a checkout session id.\n */\nexport function getPageLocation(): string {\n return redactUrl(window.location.href);\n}\n\n/** The current page's referrer, without its credential parameters: see `pageLoad`. */\nexport function getPageReferrer(): string | undefined {\n return currentPage().referrer;\n}\n\nconst links = new Map<string, Promise<Link | null>>();\n\n/**\n * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the\n * page is open, so an uncached lookup would put an identical request on the wire for every\n * event the page sends.\n */\nfunction getCachedLink(id: string) {\n const cached = links.get(id);\n if (cached) return cached;\n const link = getLink(id).then((result) => {\n // A lookup that came back empty must not stick for the lifetime of the page. `getLink`\n // answers null for a network failure as well as for a link that does not exist, and losing\n // the link's utm params for every later event costs more than repeating a rare request.\n if (!result) links.delete(id);\n return result;\n });\n links.set(id, link);\n return link;\n}\n\n/** The user agent cannot change while the page is open, so it is parsed once. */\nlet parser: ReturnType<typeof Bowser.getParser> | undefined;\n\nexport async function getTags() {\n // Read the page before the first await: `getTags` runs when the event happens, and a single\n // page app can navigate while the link lookup below is still in flight.\n const page_location = redactUrl(window.location.href);\n const { id: page_load_id, referrer: page_referrer } = currentPage();\n const page_title = document.title;\n\n parser ??= Bowser.getParser(window.navigator.userAgent);\n const params = new URLSearchParams(window.location.search);\n const os = parser.getOS();\n const browser = parser.getBrowser();\n const platform = parser.getPlatform();\n const parsed = parseCookie(document.cookie);\n\n const linkId = params.get('s');\n const link = linkId ? await getCachedLink(linkId) : null;\n\n const tags: TrackTags = {\n os: `${os.name} ${os.version}`,\n os_name: os.name,\n os_version: os.version,\n browser: `${browser.name} ${browser.version}`,\n browser_name: browser.name,\n browser_version: browser.version,\n device: platform.model,\n device_id: getDeviceId(),\n device_type: platform.type,\n device_vendor: platform.vendor,\n device_pixel_ratio: window.devicePixelRatio,\n screen_width: window.screen.width,\n screen_height: window.screen.height,\n screen_resolution: `${window.screen.width}x${window.screen.height}`,\n webdriver: navigator.webdriver || undefined,\n release: config.release,\n language: navigator.language,\n time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n page_location,\n page_referrer,\n page_title,\n page_load_id,\n // Ad click ids from the URL, each under its parameter's name: this page's click, which\n // names the visit's channel (`CLICK_ID_CHANNELS`). Never filled from a cookie — a cookie\n // outlives the click; the cookies go below under their own names.\n fbclid: params.get('fbclid') ?? undefined,\n ad_id: params.get('ad_id') ?? undefined,\n ad_name: params.get('ad_name') ?? undefined,\n adset_id: params.get('adset_id') ?? undefined,\n adset_name: params.get('adset_name') ?? undefined,\n campaign_id: params.get('campaign_id') ?? undefined,\n campaign_name: params.get('campaign_name') ?? undefined,\n placement: params.get('placement') ?? undefined,\n gclid: params.get('gclid') ?? undefined,\n gclsrc: params.get('gclsrc') ?? undefined,\n gad_source: params.get('gad_source') ?? undefined,\n gad_campaignid: params.get('gad_campaignid') ?? undefined,\n network: params.get('network') ?? undefined,\n match_type: params.get('match_type') ?? undefined,\n wbraid: params.get('wbraid') ?? undefined,\n gbraid: params.get('gbraid') ?? undefined,\n dclid: params.get('dclid') ?? undefined,\n msclkid: params.get('msclkid') ?? undefined,\n rdt_cid: params.get('rdt_cid') ?? undefined,\n li_fat_id: params.get('li_fat_id') ?? undefined,\n oppref: params.get('oppref') ?? undefined,\n ko_click_id: params.get('ko_click_id') ?? undefined,\n // Snapchat appends `ScCid`, and URL parameters are case-sensitive.\n ScCid: params.get('ScCid') ?? undefined,\n ttclid: params.get('ttclid') ?? undefined,\n twclid: params.get('twclid') ?? undefined,\n yclid: params.get('yclid') ?? undefined,\n epik: params.get('epik') ?? undefined,\n // The ad platforms' first-party cookies, raw and under the cookie's own name, for the\n // conversion senders only: they carry the click to the later pages and visits where the\n // URL no longer does. `_fbc`, `_rdt_cid`, `_gcl_*` and `_uetmsclkid` are kept alive\n // server-side (see @shware/analytics/server resolveClickIdCookies); the rest are the pixels'.\n _fbc: parsed._fbc || undefined,\n _fbp: parsed._fbp || undefined,\n _gcl_aw: parsed._gcl_aw || undefined,\n _gcl_gb: parsed._gcl_gb || undefined,\n _uetmsclkid: parsed._uetmsclkid || undefined,\n _rdt_cid: parsed._rdt_cid || undefined,\n _rdt_uuid: parsed._rdt_uuid || undefined,\n // The Insight Tag's cookie is itself named `li_fat_id`; renamed so it cannot pass for the\n // URL parameter.\n _li_fat_id: parsed.li_fat_id || undefined,\n __oppref: parsed.__oppref || undefined,\n __obref: parsed.__obref || undefined,\n // utm params\n utm_source: link?.utm_source ?? params.get('utm_source') ?? undefined,\n utm_medium: link?.utm_medium ?? params.get('utm_medium') ?? undefined,\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign') ?? undefined,\n utm_term: link?.utm_term ?? params.get('utm_term') ?? undefined,\n utm_content: link?.utm_content ?? params.get('utm_content') ?? undefined,\n utm_id: link?.utm_id ?? params.get('utm_id') ?? undefined,\n utm_source_platform:\n link?.utm_source_platform ?? params.get('utm_source_platform') ?? undefined,\n utm_creative_format:\n link?.utm_creative_format ?? params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic:\n link?.utm_marketing_tactic ?? params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n"],"mappings":";;;;;;;;;;;;AAYA,SAAS,aAAqB;CAC5B,OAAQ,OAA2B,aAAa,OAAO,WAAW,KAAA,GAAIA,KAAAA,GAAAA,CAAO;AAC/E;AAEA,SAAgB,cAAc;CAC5B,MAAM,SAASC,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,SAAS;CACpD,IAAI,QAAQ,OAAO;CACnB,MAAM,KAAK,WAAW;CACtB,oBAAA,OAAO,QAAQ,QAAQA,0BAAAA,KAAK,WAAW,EAAE;CACzC,OAAO;AACT;;;;;;;;;;;;;;;;;;;AAoBA,IAAI;AAEJ,SAAS,cAAc;CACrB,MAAM,OAAOC,yBAAAA,UAAU,OAAO,SAAS,IAAI;CAC3C,MAAM,OAAOC,qBAAAA,WAAW,OAAO,SAAS,UAAU,OAAO,SA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ACxE;CAEA,oBAAA,MAAM,OAAO;CACb,OAAO;AACT;AAEA,MAAM,sBAAM,IAAI,IAAoB;AAEpC,MAAa,UAAmB;CAC9B,UAAU,QAAQ;EAChB,IAAI;GACF,OAAO,aAAa,QAAQ,GAAG;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,OAAO,IAAI,IAAI,GAAG,KAAK;EACzB;CACF;CACA,UAAU,KAAK,UAAU;EACvB,IAAI;GACF,aAAa,QAAQ,KAAK,KAAK;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["uuidv4","config","keys","redactUrl","getPageKey","getLink","Bowser","parseCookie"],"sources":["../../src/web/index.ts"],"sourcesContent":["import Bowser from 'bowser';\nimport { parseCookie } from 'cookie';\nimport { v4 as uuidv4 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { type Link, getLink } from '../link/index';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\nimport { redactUrl } from '../utils/redact-url';\nimport { getPageKey } from './page-key';\n\n// lib.dom types `crypto.randomUUID` as always present, but it is missing in insecure contexts\n// and older browsers, so probe it before use.\nfunction randomUUID(): string {\n return (crypto as Partial<Crypto>).randomUUID ? crypto.randomUUID() : uuidv4();\n}\n\nexport function getDeviceId() {\n const cached = config.storage.getItem(keys.device_id);\n if (cached) return cached;\n const id = randomUUID();\n config.storage.setItem(keys.device_id, id);\n return id;\n}\n\n/**\n * The current page load, keyed by the page it was loaded at. A module variable and nothing more\n * persistent: the id must die with the page (a reload is a new page load, and storage would\n * carry it over — or, shared across tabs, let two pages overwrite each other's).\n *\n * Keyed by `getPageKey` because that is what the SDK's own `page_view` fires on (see\n * `useWebAnalytics`): the id exists to link an event to the `page_view` of the page it happened\n * on, so it must rotate exactly when a `page_view` is sent — path or query change, yes; hash\n * change or tracking-parameter cleanup, no.\n *\n * `referrer` is the page's referrer as GA4 reports it in a single page app: `document.referrer`\n * for the document's first page, and the previous page's URL after an in-app navigation. The\n * browser never updates `document.referrer` on a `pushState`, so read alone it would name the\n * site the visit came from on every later page — and a session opened there, after 30 minutes\n * idle, would count that site as a second visit from it. With the previous page as its referrer,\n * that session's referrer is the product's own host: no touch, a direct session, which the\n * attribution view then credits to the touch before it.\n */\nlet pageLoad: { page: string; id: string; href: string; referrer: string | undefined } | undefined;\n\nfunction currentPage() {\n const href = redactUrl(window.location.href);\n const page = getPageKey(window.location.pathname, window.location.search);\n if (pageLoad?.page === page) {\n // The same page, its URL maybe cleaned of tracking parameters since: the next page's\n // referrer is the URL as it last was, as the browser's own would be.\n pageLoad.href = href;\n return pageLoad;\n }\n const referrer = pageLoad ? pageLoad.href : redactUrl(document.referrer) || undefined;\n pageLoad = { page, id: randomUUID(), href, referrer };\n return pageLoad;\n}\n\n/**\n * The current page's URL as reported, without its credential parameters (`redactUrl`), so\n * `page_location` never carries an OAuth code or a checkout session id.\n */\nexport function getPageLocation(): string {\n return redactUrl(window.location.href);\n}\n\n/** The current page's referrer, without its credential parameters: see `pageLoad`. */\nexport function getPageReferrer(): string | undefined {\n return currentPage().referrer;\n}\n\nconst links = new Map<string, Promise<Link | null>>();\n\n/**\n * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the\n * page is open, so an uncached lookup would put an identical request on the wire for every\n * event the page sends.\n */\nfunction getCachedLink(id: string) {\n const cached = links.get(id);\n if (cached) return cached;\n const link = getLink(id).then(\n // `null` is the server saying the id names no link (a 4xx) and stays cached: an unknown `?s=`\n // would otherwise put a request on the wire for every event of the page.\n (result) => result,\n (e: unknown) => {\n // A 5xx or a network failure says nothing about the link, and losing its utm params for\n // every later event costs more than repeating a rare request: forget it, try again next time.\n if (e instanceof Error) console.error(e.message);\n links.delete(id);\n return null;\n }\n );\n links.set(id, link);\n return link;\n}\n\n/** The user agent cannot change while the page is open, so it is parsed once. */\nlet parser: ReturnType<typeof Bowser.getParser> | undefined;\n\nexport async function getTags() {\n // Read the page before the first await: `getTags` runs when the event happens, and a single\n // page app can navigate while the link lookup below is still in flight.\n const page_location = redactUrl(window.location.href);\n const { id: page_load_id, referrer: page_referrer } = currentPage();\n const page_title = document.title;\n\n parser ??= Bowser.getParser(window.navigator.userAgent);\n const params = new URLSearchParams(window.location.search);\n const os = parser.getOS();\n const browser = parser.getBrowser();\n const platform = parser.getPlatform();\n const parsed = parseCookie(document.cookie);\n\n const linkId = params.get('s');\n const link = linkId ? await getCachedLink(linkId) : null;\n\n const tags: TrackTags = {\n os: `${os.name} ${os.version}`,\n os_name: os.name,\n os_version: os.version,\n browser: `${browser.name} ${browser.version}`,\n browser_name: browser.name,\n browser_version: browser.version,\n device: platform.model,\n device_id: getDeviceId(),\n device_type: platform.type,\n device_vendor: platform.vendor,\n device_pixel_ratio: window.devicePixelRatio,\n screen_width: window.screen.width,\n screen_height: window.screen.height,\n screen_resolution: `${window.screen.width}x${window.screen.height}`,\n webdriver: navigator.webdriver || undefined,\n release: config.release,\n language: navigator.language,\n time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n page_location,\n page_referrer,\n page_title,\n page_load_id,\n // Ad click ids from the URL, each under its parameter's name: this page's click, which\n // names the visit's channel (`CLICK_ID_CHANNELS`). Never filled from a cookie — a cookie\n // outlives the click; the cookies go below under their own names.\n fbclid: params.get('fbclid') ?? undefined,\n ad_id: params.get('ad_id') ?? undefined,\n ad_name: params.get('ad_name') ?? undefined,\n adset_id: params.get('adset_id') ?? undefined,\n adset_name: params.get('adset_name') ?? undefined,\n campaign_id: params.get('campaign_id') ?? undefined,\n campaign_name: params.get('campaign_name') ?? undefined,\n placement: params.get('placement') ?? undefined,\n gclid: params.get('gclid') ?? undefined,\n gclsrc: params.get('gclsrc') ?? undefined,\n gad_source: params.get('gad_source') ?? undefined,\n gad_campaignid: params.get('gad_campaignid') ?? undefined,\n network: params.get('network') ?? undefined,\n match_type: params.get('match_type') ?? undefined,\n wbraid: params.get('wbraid') ?? undefined,\n gbraid: params.get('gbraid') ?? undefined,\n dclid: params.get('dclid') ?? undefined,\n msclkid: params.get('msclkid') ?? undefined,\n rdt_cid: params.get('rdt_cid') ?? undefined,\n li_fat_id: params.get('li_fat_id') ?? undefined,\n oppref: params.get('oppref') ?? undefined,\n ko_click_id: params.get('ko_click_id') ?? undefined,\n // Snapchat appends `ScCid`, and URL parameters are case-sensitive.\n ScCid: params.get('ScCid') ?? undefined,\n ttclid: params.get('ttclid') ?? undefined,\n twclid: params.get('twclid') ?? undefined,\n yclid: params.get('yclid') ?? undefined,\n epik: params.get('epik') ?? undefined,\n // The ad platforms' first-party cookies, raw and under the cookie's own name, for the\n // conversion senders only: they carry the click to the later pages and visits where the\n // URL no longer does. `_fbc`, `_rdt_cid`, `_gcl_*` and `_uetmsclkid` are kept alive\n // server-side (see @shware/analytics/server resolveClickIdCookies); the rest are the pixels'.\n _fbc: parsed._fbc || undefined,\n _fbp: parsed._fbp || undefined,\n _gcl_aw: parsed._gcl_aw || undefined,\n _gcl_gb: parsed._gcl_gb || undefined,\n _uetmsclkid: parsed._uetmsclkid || undefined,\n _rdt_cid: parsed._rdt_cid || undefined,\n _rdt_uuid: parsed._rdt_uuid || undefined,\n // The Insight Tag's cookie is itself named `li_fat_id`; renamed so it cannot pass for the\n // URL parameter.\n _li_fat_id: parsed.li_fat_id || undefined,\n __oppref: parsed.__oppref || undefined,\n __obref: parsed.__obref || undefined,\n // utm params\n utm_source: link?.utm_source ?? params.get('utm_source') ?? undefined,\n utm_medium: link?.utm_medium ?? params.get('utm_medium') ?? undefined,\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign') ?? undefined,\n utm_term: link?.utm_term ?? params.get('utm_term') ?? undefined,\n utm_content: link?.utm_content ?? params.get('utm_content') ?? undefined,\n utm_id: link?.utm_id ?? params.get('utm_id') ?? undefined,\n utm_source_platform:\n link?.utm_source_platform ?? params.get('utm_source_platform') ?? undefined,\n utm_creative_format:\n link?.utm_creative_format ?? params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic:\n link?.utm_marketing_tactic ?? params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n"],"mappings":";;;;;;;;;;;;AAYA,SAAS,aAAqB;CAC5B,OAAQ,OAA2B,aAAa,OAAO,WAAW,KAAA,GAAIA,KAAAA,GAAAA,CAAO;AAC/E;AAEA,SAAgB,cAAc;CAC5B,MAAM,SAASC,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,SAAS;CACpD,IAAI,QAAQ,OAAO;CACnB,MAAM,KAAK,WAAW;CACtB,oBAAA,OAAO,QAAQ,QAAQA,0BAAAA,KAAK,WAAW,EAAE;CACzC,OAAO;AACT;;;;;;;;;;;;;;;;;;;AAoBA,IAAI;AAEJ,SAAS,cAAc;CACrB,MAAM,OAAOC,yBAAAA,UAAU,OAAO,SAAS,IAAI;CAC3C,MAAM,OAAOC,qBAAAA,WAAW,OAAO,SAAS,UAAU,OAAO,SAAS,MAAM;CACxE,IAAI,UAAU,SAAS,MAAM;EAG3B,SAAS,OAAO;EAChB,OAAO;CACT;CACA,MAAM,WAAW,WAAW,SAAS,OAAOD,yBAAAA,UAAU,SAAS,QAAQ,KAAK,KAAA;CAC5E,WAAW;EAAE;EAAM,IAAI,WAAW;EAAG;EAAM;CAAS;CACpD,OAAO;AACT;;;;;AAMA,SAAgB,kBAA0B;CACxC,OAAOA,yBAAAA,UAAU,OAAO,SAAS,IAAI;AACvC;;AAGA,SAAgB,kBAAsC;CACpD,OAAO,YAAY,CAAC,CAAC;AACvB;AAEA,MAAM,wBAAQ,IAAI,IAAkC;;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7C,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF"}
|
package/dist/web/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/web/index.ts"],"mappings":";;;wBAgBgB;;;;;wBA8CA;;wBAKA;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/web/index.ts"],"mappings":";;;wBAgBgB;;;;;wBA8CA;;wBAKA;wBAiCM,WAAO,QAAA;qBA4GhB,SAAS"}
|
package/dist/web/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/web/index.ts"],"mappings":";;;wBAgBgB;;;;;wBA8CA;;wBAKA;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/web/index.ts"],"mappings":";;;wBAgBgB;;;;;wBA8CA;;wBAKA;wBAiCM,WAAO,QAAA;qBA4GhB,SAAS"}
|
package/dist/web/index.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import { __toESM } from "../_virtual/_rolldown/runtime.mjs";
|
|
|
2
2
|
import { cache, config } from "../setup/index.mjs";
|
|
3
3
|
import { keys } from "../constants/storage.mjs";
|
|
4
4
|
import { getLink } from "../link/index.mjs";
|
|
5
|
-
import { require_es5 } from "../node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.mjs";
|
|
6
5
|
import { redactUrl } from "../utils/redact-url.mjs";
|
|
6
|
+
import { require_es5 } from "../node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.mjs";
|
|
7
7
|
import { getPageKey } from "./page-key.mjs";
|
|
8
8
|
import { v4 } from "uuid";
|
|
9
9
|
import { parseCookie } from "cookie";
|
|
@@ -74,9 +74,10 @@ const links = /* @__PURE__ */ new Map();
|
|
|
74
74
|
function getCachedLink(id) {
|
|
75
75
|
const cached = links.get(id);
|
|
76
76
|
if (cached) return cached;
|
|
77
|
-
const link = getLink(id).then((result) => {
|
|
78
|
-
if (
|
|
79
|
-
|
|
77
|
+
const link = getLink(id).then((result) => result, (e) => {
|
|
78
|
+
if (e instanceof Error) console.error(e.message);
|
|
79
|
+
links.delete(id);
|
|
80
|
+
return null;
|
|
80
81
|
});
|
|
81
82
|
links.set(id, link);
|
|
82
83
|
return link;
|
package/dist/web/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["uuidv4","Bowser"],"sources":["../../src/web/index.ts"],"sourcesContent":["import Bowser from 'bowser';\nimport { parseCookie } from 'cookie';\nimport { v4 as uuidv4 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { type Link, getLink } from '../link/index';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\nimport { redactUrl } from '../utils/redact-url';\nimport { getPageKey } from './page-key';\n\n// lib.dom types `crypto.randomUUID` as always present, but it is missing in insecure contexts\n// and older browsers, so probe it before use.\nfunction randomUUID(): string {\n return (crypto as Partial<Crypto>).randomUUID ? crypto.randomUUID() : uuidv4();\n}\n\nexport function getDeviceId() {\n const cached = config.storage.getItem(keys.device_id);\n if (cached) return cached;\n const id = randomUUID();\n config.storage.setItem(keys.device_id, id);\n return id;\n}\n\n/**\n * The current page load, keyed by the page it was loaded at. A module variable and nothing more\n * persistent: the id must die with the page (a reload is a new page load, and storage would\n * carry it over — or, shared across tabs, let two pages overwrite each other's).\n *\n * Keyed by `getPageKey` because that is what the SDK's own `page_view` fires on (see\n * `useWebAnalytics`): the id exists to link an event to the `page_view` of the page it happened\n * on, so it must rotate exactly when a `page_view` is sent — path or query change, yes; hash\n * change or tracking-parameter cleanup, no.\n *\n * `referrer` is the page's referrer as GA4 reports it in a single page app: `document.referrer`\n * for the document's first page, and the previous page's URL after an in-app navigation. The\n * browser never updates `document.referrer` on a `pushState`, so read alone it would name the\n * site the visit came from on every later page — and a session opened there, after 30 minutes\n * idle, would count that site as a second visit from it. With the previous page as its referrer,\n * that session's referrer is the product's own host: no touch, a direct session, which the\n * attribution view then credits to the touch before it.\n */\nlet pageLoad: { page: string; id: string; href: string; referrer: string | undefined } | undefined;\n\nfunction currentPage() {\n const href = redactUrl(window.location.href);\n const page = getPageKey(window.location.pathname, window.location.search);\n if (pageLoad?.page === page) {\n // The same page, its URL maybe cleaned of tracking parameters since: the next page's\n // referrer is the URL as it last was, as the browser's own would be.\n pageLoad.href = href;\n return pageLoad;\n }\n const referrer = pageLoad ? pageLoad.href : redactUrl(document.referrer) || undefined;\n pageLoad = { page, id: randomUUID(), href, referrer };\n return pageLoad;\n}\n\n/**\n * The current page's URL as reported, without its credential parameters (`redactUrl`), so\n * `page_location` never carries an OAuth code or a checkout session id.\n */\nexport function getPageLocation(): string {\n return redactUrl(window.location.href);\n}\n\n/** The current page's referrer, without its credential parameters: see `pageLoad`. */\nexport function getPageReferrer(): string | undefined {\n return currentPage().referrer;\n}\n\nconst links = new Map<string, Promise<Link | null>>();\n\n/**\n * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the\n * page is open, so an uncached lookup would put an identical request on the wire for every\n * event the page sends.\n */\nfunction getCachedLink(id: string) {\n const cached = links.get(id);\n if (cached) return cached;\n const link = getLink(id).then((result) => {\n // A lookup that came back empty must not stick for the lifetime of the page. `getLink`\n // answers null for a network failure as well as for a link that does not exist, and losing\n // the link's utm params for every later event costs more than repeating a rare request.\n if (!result) links.delete(id);\n return result;\n });\n links.set(id, link);\n return link;\n}\n\n/** The user agent cannot change while the page is open, so it is parsed once. */\nlet parser: ReturnType<typeof Bowser.getParser> | undefined;\n\nexport async function getTags() {\n // Read the page before the first await: `getTags` runs when the event happens, and a single\n // page app can navigate while the link lookup below is still in flight.\n const page_location = redactUrl(window.location.href);\n const { id: page_load_id, referrer: page_referrer } = currentPage();\n const page_title = document.title;\n\n parser ??= Bowser.getParser(window.navigator.userAgent);\n const params = new URLSearchParams(window.location.search);\n const os = parser.getOS();\n const browser = parser.getBrowser();\n const platform = parser.getPlatform();\n const parsed = parseCookie(document.cookie);\n\n const linkId = params.get('s');\n const link = linkId ? await getCachedLink(linkId) : null;\n\n const tags: TrackTags = {\n os: `${os.name} ${os.version}`,\n os_name: os.name,\n os_version: os.version,\n browser: `${browser.name} ${browser.version}`,\n browser_name: browser.name,\n browser_version: browser.version,\n device: platform.model,\n device_id: getDeviceId(),\n device_type: platform.type,\n device_vendor: platform.vendor,\n device_pixel_ratio: window.devicePixelRatio,\n screen_width: window.screen.width,\n screen_height: window.screen.height,\n screen_resolution: `${window.screen.width}x${window.screen.height}`,\n webdriver: navigator.webdriver || undefined,\n release: config.release,\n language: navigator.language,\n time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n page_location,\n page_referrer,\n page_title,\n page_load_id,\n // Ad click ids from the URL, each under its parameter's name: this page's click, which\n // names the visit's channel (`CLICK_ID_CHANNELS`). Never filled from a cookie — a cookie\n // outlives the click; the cookies go below under their own names.\n fbclid: params.get('fbclid') ?? undefined,\n ad_id: params.get('ad_id') ?? undefined,\n ad_name: params.get('ad_name') ?? undefined,\n adset_id: params.get('adset_id') ?? undefined,\n adset_name: params.get('adset_name') ?? undefined,\n campaign_id: params.get('campaign_id') ?? undefined,\n campaign_name: params.get('campaign_name') ?? undefined,\n placement: params.get('placement') ?? undefined,\n gclid: params.get('gclid') ?? undefined,\n gclsrc: params.get('gclsrc') ?? undefined,\n gad_source: params.get('gad_source') ?? undefined,\n gad_campaignid: params.get('gad_campaignid') ?? undefined,\n network: params.get('network') ?? undefined,\n match_type: params.get('match_type') ?? undefined,\n wbraid: params.get('wbraid') ?? undefined,\n gbraid: params.get('gbraid') ?? undefined,\n dclid: params.get('dclid') ?? undefined,\n msclkid: params.get('msclkid') ?? undefined,\n rdt_cid: params.get('rdt_cid') ?? undefined,\n li_fat_id: params.get('li_fat_id') ?? undefined,\n oppref: params.get('oppref') ?? undefined,\n ko_click_id: params.get('ko_click_id') ?? undefined,\n // Snapchat appends `ScCid`, and URL parameters are case-sensitive.\n ScCid: params.get('ScCid') ?? undefined,\n ttclid: params.get('ttclid') ?? undefined,\n twclid: params.get('twclid') ?? undefined,\n yclid: params.get('yclid') ?? undefined,\n epik: params.get('epik') ?? undefined,\n // The ad platforms' first-party cookies, raw and under the cookie's own name, for the\n // conversion senders only: they carry the click to the later pages and visits where the\n // URL no longer does. `_fbc`, `_rdt_cid`, `_gcl_*` and `_uetmsclkid` are kept alive\n // server-side (see @shware/analytics/server resolveClickIdCookies); the rest are the pixels'.\n _fbc: parsed._fbc || undefined,\n _fbp: parsed._fbp || undefined,\n _gcl_aw: parsed._gcl_aw || undefined,\n _gcl_gb: parsed._gcl_gb || undefined,\n _uetmsclkid: parsed._uetmsclkid || undefined,\n _rdt_cid: parsed._rdt_cid || undefined,\n _rdt_uuid: parsed._rdt_uuid || undefined,\n // The Insight Tag's cookie is itself named `li_fat_id`; renamed so it cannot pass for the\n // URL parameter.\n _li_fat_id: parsed.li_fat_id || undefined,\n __oppref: parsed.__oppref || undefined,\n __obref: parsed.__obref || undefined,\n // utm params\n utm_source: link?.utm_source ?? params.get('utm_source') ?? undefined,\n utm_medium: link?.utm_medium ?? params.get('utm_medium') ?? undefined,\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign') ?? undefined,\n utm_term: link?.utm_term ?? params.get('utm_term') ?? undefined,\n utm_content: link?.utm_content ?? params.get('utm_content') ?? undefined,\n utm_id: link?.utm_id ?? params.get('utm_id') ?? undefined,\n utm_source_platform:\n link?.utm_source_platform ?? params.get('utm_source_platform') ?? undefined,\n utm_creative_format:\n link?.utm_creative_format ?? params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic:\n link?.utm_marketing_tactic ?? params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n local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,IAAI,YAAY,KAAK,KAAA;EAC5D,cAAc,MAAM,gBAAgB,OAAO,IAAI,cAAc,KAAK,KAAA;EAClE,UAAU,MAAM,YAAY,OAAO,IAAI,UAAU,KAAK,KAAA;EACtD,aAAa,MAAM,eAAe,OAAO,IAAI,aAAa,KAAK,KAAA;EAC/D,QAAQ,MAAM,UAAU,OAAO,IAAI,QAAQ,KAAK,KAAA;EAChD,qBACE,MAAM,uBAAuB,OAAO,IAAI,qBAAqB,KAAK,KAAA;EACpE,qBACE,MAAM,uBAAuB,OAAO,IAAI,qBAAqB,KAAK,KAAA;EACpE,sBACE,MAAM,wBAAwB,OAAO,IAAI,sBAAsB,KAAK,KAAA;CACxE;CAEA,MAAM,OAAO;CACb,OAAO;AACT;AAEA,MAAM,sBAAM,IAAI,IAAoB;AAEpC,MAAa,UAAmB;CAC9B,UAAU,QAAQ;EAChB,IAAI;GACF,OAAO,aAAa,QAAQ,GAAG;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,OAAO,IAAI,IAAI,GAAG,KAAK;EACzB;CACF;CACA,UAAU,KAAK,UAAU;EACvB,IAAI;GACF,aAAa,QAAQ,KAAK,KAAK;EACjC,QAAQ;GACN,QAAQ,MAAM,+BAA+B;GAC7C,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["uuidv4","Bowser"],"sources":["../../src/web/index.ts"],"sourcesContent":["import Bowser from 'bowser';\nimport { parseCookie } from 'cookie';\nimport { v4 as uuidv4 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { type Link, getLink } from '../link/index';\nimport { type Storage, cache, config } from '../setup/index';\nimport type { TrackTags } from '../track/types';\nimport { redactUrl } from '../utils/redact-url';\nimport { getPageKey } from './page-key';\n\n// lib.dom types `crypto.randomUUID` as always present, but it is missing in insecure contexts\n// and older browsers, so probe it before use.\nfunction randomUUID(): string {\n return (crypto as Partial<Crypto>).randomUUID ? crypto.randomUUID() : uuidv4();\n}\n\nexport function getDeviceId() {\n const cached = config.storage.getItem(keys.device_id);\n if (cached) return cached;\n const id = randomUUID();\n config.storage.setItem(keys.device_id, id);\n return id;\n}\n\n/**\n * The current page load, keyed by the page it was loaded at. A module variable and nothing more\n * persistent: the id must die with the page (a reload is a new page load, and storage would\n * carry it over — or, shared across tabs, let two pages overwrite each other's).\n *\n * Keyed by `getPageKey` because that is what the SDK's own `page_view` fires on (see\n * `useWebAnalytics`): the id exists to link an event to the `page_view` of the page it happened\n * on, so it must rotate exactly when a `page_view` is sent — path or query change, yes; hash\n * change or tracking-parameter cleanup, no.\n *\n * `referrer` is the page's referrer as GA4 reports it in a single page app: `document.referrer`\n * for the document's first page, and the previous page's URL after an in-app navigation. The\n * browser never updates `document.referrer` on a `pushState`, so read alone it would name the\n * site the visit came from on every later page — and a session opened there, after 30 minutes\n * idle, would count that site as a second visit from it. With the previous page as its referrer,\n * that session's referrer is the product's own host: no touch, a direct session, which the\n * attribution view then credits to the touch before it.\n */\nlet pageLoad: { page: string; id: string; href: string; referrer: string | undefined } | undefined;\n\nfunction currentPage() {\n const href = redactUrl(window.location.href);\n const page = getPageKey(window.location.pathname, window.location.search);\n if (pageLoad?.page === page) {\n // The same page, its URL maybe cleaned of tracking parameters since: the next page's\n // referrer is the URL as it last was, as the browser's own would be.\n pageLoad.href = href;\n return pageLoad;\n }\n const referrer = pageLoad ? pageLoad.href : redactUrl(document.referrer) || undefined;\n pageLoad = { page, id: randomUUID(), href, referrer };\n return pageLoad;\n}\n\n/**\n * The current page's URL as reported, without its credential parameters (`redactUrl`), so\n * `page_location` never carries an OAuth code or a checkout session id.\n */\nexport function getPageLocation(): string {\n return redactUrl(window.location.href);\n}\n\n/** The current page's referrer, without its credential parameters: see `pageLoad`. */\nexport function getPageReferrer(): string | undefined {\n return currentPage().referrer;\n}\n\nconst links = new Map<string, Promise<Link | null>>();\n\n/**\n * `getTags` runs once per event now, and the link a `?s=` id points at cannot change while the\n * page is open, so an uncached lookup would put an identical request on the wire for every\n * event the page sends.\n */\nfunction getCachedLink(id: string) {\n const cached = links.get(id);\n if (cached) return cached;\n const link = getLink(id).then(\n // `null` is the server saying the id names no link (a 4xx) and stays cached: an unknown `?s=`\n // would otherwise put a request on the wire for every event of the page.\n (result) => result,\n (e: unknown) => {\n // A 5xx or a network failure says nothing about the link, and losing its utm params for\n // every later event costs more than repeating a rare request: forget it, try again next time.\n if (e instanceof Error) console.error(e.message);\n links.delete(id);\n return null;\n }\n );\n links.set(id, link);\n return link;\n}\n\n/** The user agent cannot change while the page is open, so it is parsed once. */\nlet parser: ReturnType<typeof Bowser.getParser> | undefined;\n\nexport async function getTags() {\n // Read the page before the first await: `getTags` runs when the event happens, and a single\n // page app can navigate while the link lookup below is still in flight.\n const page_location = redactUrl(window.location.href);\n const { id: page_load_id, referrer: page_referrer } = currentPage();\n const page_title = document.title;\n\n parser ??= Bowser.getParser(window.navigator.userAgent);\n const params = new URLSearchParams(window.location.search);\n const os = parser.getOS();\n const browser = parser.getBrowser();\n const platform = parser.getPlatform();\n const parsed = parseCookie(document.cookie);\n\n const linkId = params.get('s');\n const link = linkId ? await getCachedLink(linkId) : null;\n\n const tags: TrackTags = {\n os: `${os.name} ${os.version}`,\n os_name: os.name,\n os_version: os.version,\n browser: `${browser.name} ${browser.version}`,\n browser_name: browser.name,\n browser_version: browser.version,\n device: platform.model,\n device_id: getDeviceId(),\n device_type: platform.type,\n device_vendor: platform.vendor,\n device_pixel_ratio: window.devicePixelRatio,\n screen_width: window.screen.width,\n screen_height: window.screen.height,\n screen_resolution: `${window.screen.width}x${window.screen.height}`,\n webdriver: navigator.webdriver || undefined,\n release: config.release,\n language: navigator.language,\n time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n page_location,\n page_referrer,\n page_title,\n page_load_id,\n // Ad click ids from the URL, each under its parameter's name: this page's click, which\n // names the visit's channel (`CLICK_ID_CHANNELS`). Never filled from a cookie — a cookie\n // outlives the click; the cookies go below under their own names.\n fbclid: params.get('fbclid') ?? undefined,\n ad_id: params.get('ad_id') ?? undefined,\n ad_name: params.get('ad_name') ?? undefined,\n adset_id: params.get('adset_id') ?? undefined,\n adset_name: params.get('adset_name') ?? undefined,\n campaign_id: params.get('campaign_id') ?? undefined,\n campaign_name: params.get('campaign_name') ?? undefined,\n placement: params.get('placement') ?? undefined,\n gclid: params.get('gclid') ?? undefined,\n gclsrc: params.get('gclsrc') ?? undefined,\n gad_source: params.get('gad_source') ?? undefined,\n gad_campaignid: params.get('gad_campaignid') ?? undefined,\n network: params.get('network') ?? undefined,\n match_type: params.get('match_type') ?? undefined,\n wbraid: params.get('wbraid') ?? undefined,\n gbraid: params.get('gbraid') ?? undefined,\n dclid: params.get('dclid') ?? undefined,\n msclkid: params.get('msclkid') ?? undefined,\n rdt_cid: params.get('rdt_cid') ?? undefined,\n li_fat_id: params.get('li_fat_id') ?? undefined,\n oppref: params.get('oppref') ?? undefined,\n ko_click_id: params.get('ko_click_id') ?? undefined,\n // Snapchat appends `ScCid`, and URL parameters are case-sensitive.\n ScCid: params.get('ScCid') ?? undefined,\n ttclid: params.get('ttclid') ?? undefined,\n twclid: params.get('twclid') ?? undefined,\n yclid: params.get('yclid') ?? undefined,\n epik: params.get('epik') ?? undefined,\n // The ad platforms' first-party cookies, raw and under the cookie's own name, for the\n // conversion senders only: they carry the click to the later pages and visits where the\n // URL no longer does. `_fbc`, `_rdt_cid`, `_gcl_*` and `_uetmsclkid` are kept alive\n // server-side (see @shware/analytics/server resolveClickIdCookies); the rest are the pixels'.\n _fbc: parsed._fbc || undefined,\n _fbp: parsed._fbp || undefined,\n _gcl_aw: parsed._gcl_aw || undefined,\n _gcl_gb: parsed._gcl_gb || undefined,\n _uetmsclkid: parsed._uetmsclkid || undefined,\n _rdt_cid: parsed._rdt_cid || undefined,\n _rdt_uuid: parsed._rdt_uuid || undefined,\n // The Insight Tag's cookie is itself named `li_fat_id`; renamed so it cannot pass for the\n // URL parameter.\n _li_fat_id: parsed.li_fat_id || undefined,\n __oppref: parsed.__oppref || undefined,\n __obref: parsed.__obref || undefined,\n // utm params\n utm_source: link?.utm_source ?? params.get('utm_source') ?? undefined,\n utm_medium: link?.utm_medium ?? params.get('utm_medium') ?? undefined,\n utm_campaign: link?.utm_campaign ?? params.get('utm_campaign') ?? undefined,\n utm_term: link?.utm_term ?? params.get('utm_term') ?? undefined,\n utm_content: link?.utm_content ?? params.get('utm_content') ?? undefined,\n utm_id: link?.utm_id ?? params.get('utm_id') ?? undefined,\n utm_source_platform:\n link?.utm_source_platform ?? params.get('utm_source_platform') ?? undefined,\n utm_creative_format:\n link?.utm_creative_format ?? params.get('utm_creative_format') ?? undefined,\n utm_marketing_tactic:\n link?.utm_marketing_tactic ?? params.get('utm_marketing_tactic') ?? undefined,\n };\n\n cache.tags = tags;\n return tags;\n}\n\nconst map = new Map<string, string>();\n\nexport const storage: Storage = {\n getItem: (key) => {\n try {\n return localStorage.getItem(key);\n } catch {\n console.error('localStorage is not available');\n return map.get(key) ?? null;\n }\n },\n setItem: (key, value) => {\n try {\n localStorage.setItem(key, value);\n } catch {\n console.error('localStorage is not available');\n map.set(key, value);\n }\n },\n};\n"],"mappings":";;;;;;;;;;;AAYA,SAAS,aAAqB;CAC5B,OAAQ,OAA2B,aAAa,OAAO,WAAW,IAAIA,GAAO;AAC/E;AAEA,SAAgB,cAAc;CAC5B,MAAM,SAAS,OAAO,QAAQ,QAAQ,KAAK,SAAS;CACpD,IAAI,QAAQ,OAAO;CACnB,MAAM,KAAK,WAAW;CACtB,OAAO,QAAQ,QAAQ,KAAK,WAAW,EAAE;CACzC,OAAO;AACT;;;;;;;;;;;;;;;;;;;AAoBA,IAAI;AAEJ,SAAS,cAAc;CACrB,MAAM,OAAO,UAAU,OAAO,SAAS,IAAI;CAC3C,MAAM,OAAO,WAAW,OAAO,SAAS,UAAU,OAAO,SAAS,MAAM;CACxE,IAAI,UAAU,SAAS,MAAM;EAG3B,SAAS,OAAO;EAChB,OAAO;CACT;CACA,M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