@shware/analytics 16.5.0 → 16.5.2
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/dist/_virtual/_rolldown/runtime.cjs +0 -2
- package/dist/ads/google.d.cts +13 -0
- package/dist/ads/google.d.cts.map +1 -1
- package/dist/ads/google.d.mts +13 -0
- package/dist/ads/google.d.mts.map +1 -1
- package/dist/ads/index.cjs +1 -1
- package/dist/ads/index.d.cts +1 -1
- package/dist/ads/index.d.mts +1 -1
- package/dist/ads/index.mjs +1 -1
- package/dist/ads/meta.cjs.map +1 -1
- package/dist/ads/meta.mjs.map +1 -1
- package/dist/ads/types.d.cts +1 -0
- package/dist/ads/types.d.cts.map +1 -1
- package/dist/attribution/index.cjs +1 -1
- package/dist/attribution/index.d.cts +1 -1
- package/dist/attribution/index.d.mts +1 -1
- package/dist/attribution/index.mjs +1 -1
- package/dist/click-id/index.cjs.map +1 -1
- package/dist/hooks/use-app-analytics.cjs +1 -1
- package/dist/hooks/use-app-analytics.cjs.map +1 -1
- package/dist/hooks/use-app-analytics.mjs +1 -1
- package/dist/hooks/use-outbound-click-analytics.cjs.map +1 -1
- package/dist/hooks/use-report-web-vitals.cjs.map +1 -1
- package/dist/hooks/use-track-impression.cjs.map +1 -1
- package/dist/hooks/use-uet-id-sync.cjs.map +1 -1
- package/dist/hooks/use-uet-id-sync.mjs.map +1 -1
- package/dist/hooks/use-web-analytics.cjs +2 -2
- package/dist/hooks/use-web-analytics.cjs.map +1 -1
- package/dist/hooks/use-web-analytics.mjs +2 -2
- package/dist/index.d.cts +7 -7
- package/dist/index.d.mts +7 -7
- package/dist/link/index.cjs.map +1 -1
- package/dist/link/index.d.cts +12 -1
- package/dist/link/index.d.cts.map +1 -1
- package/dist/link/index.d.mts +12 -1
- package/dist/link/index.d.mts.map +1 -1
- package/dist/link/index.mjs.map +1 -1
- package/dist/native/deep-link.cjs.map +1 -1
- package/dist/native/fbsdk.cjs +1 -1
- package/dist/native/fbsdk.cjs.map +1 -1
- package/dist/native/fbsdk.d.cts +1 -1
- package/dist/native/fbsdk.d.mts +1 -1
- package/dist/native/fbsdk.mjs +1 -1
- package/dist/native/firebase.cjs.map +1 -1
- package/dist/native/firebase.d.cts +1 -1
- package/dist/native/firebase.d.mts +1 -1
- package/dist/native/index.cjs +2 -2
- package/dist/native/index.d.cts +2 -2
- package/dist/native/index.d.mts +2 -2
- package/dist/native/index.mjs +2 -2
- package/dist/native/setup.cjs +1 -1
- package/dist/native/setup.cjs.map +1 -1
- package/dist/native/setup.d.cts +1 -2
- package/dist/native/setup.d.cts.map +1 -1
- package/dist/native/setup.d.mts +1 -1
- package/dist/native/setup.mjs +1 -1
- package/dist/next/index.cjs +2 -2
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.mjs +2 -2
- package/dist/node_modules/.pnpm/bowser@2.15.0/node_modules/bowser/bowser.cjs +2157 -0
- package/dist/node_modules/.pnpm/bowser@2.15.0/node_modules/bowser/bowser.cjs.map +1 -0
- package/dist/node_modules/.pnpm/bowser@2.15.0/node_modules/bowser/bowser.mjs +2152 -0
- package/dist/node_modules/.pnpm/bowser@2.15.0/node_modules/bowser/bowser.mjs.map +1 -0
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.mjs +2 -2
- package/dist/react/posthog-error-boundary.cjs.map +1 -1
- package/dist/react/posthog-error-boundary.mjs.map +1 -1
- package/dist/server/conversions-api-error.cjs.map +1 -1
- package/dist/server/conversions-api-error.mjs.map +1 -1
- package/dist/server/index.cjs +4 -4
- package/dist/server/index.d.cts +6 -6
- package/dist/server/index.d.mts +6 -6
- package/dist/server/index.mjs +4 -4
- package/dist/server/linkedin-conversions-api.d.cts +1 -1
- package/dist/server/linkedin-conversions-api.d.mts +1 -1
- package/dist/server/meta-capi.cjs +1 -1
- package/dist/server/meta-capi.d.cts +1 -1
- package/dist/server/meta-capi.d.mts +1 -1
- package/dist/server/meta-capi.mjs +1 -1
- package/dist/server/microsoft-conversions-api.cjs +3 -3
- package/dist/server/microsoft-conversions-api.d.cts +1 -1
- package/dist/server/microsoft-conversions-api.d.mts +1 -1
- package/dist/server/microsoft-conversions-api.mjs +3 -3
- package/dist/server/openai-conversions-api.cjs +2 -2
- package/dist/server/openai-conversions-api.d.cts +2 -2
- package/dist/server/openai-conversions-api.d.mts +2 -2
- package/dist/server/openai-conversions-api.mjs +2 -2
- package/dist/server/reddit-conversions-api.cjs +3 -3
- package/dist/server/reddit-conversions-api.d.cts +2 -2
- package/dist/server/reddit-conversions-api.d.mts +2 -2
- package/dist/server/reddit-conversions-api.mjs +3 -3
- package/dist/setup/index.d.cts +1 -1
- package/dist/setup/index.d.mts +1 -1
- package/dist/setup/session.cjs +1 -1
- package/dist/setup/session.cjs.map +1 -1
- package/dist/setup/session.mjs +1 -1
- package/dist/test/setup.cjs +1 -1
- package/dist/test/setup.cjs.map +1 -1
- package/dist/test/setup.mjs +1 -1
- package/dist/test/setup.mjs.map +1 -1
- package/dist/third-parties/google-analytics.d.cts +1 -1
- package/dist/third-parties/google-analytics.d.mts +1 -1
- package/dist/third-parties/index.cjs +3 -3
- package/dist/third-parties/index.d.cts +5 -5
- package/dist/third-parties/index.d.mts +5 -5
- package/dist/third-parties/index.mjs +3 -3
- package/dist/third-parties/linkedin-insight-tag.d.cts +2 -2
- package/dist/third-parties/linkedin-insight-tag.d.mts +2 -2
- package/dist/third-parties/meta-pixel.cjs +1 -1
- package/dist/third-parties/meta-pixel.d.cts +2 -2
- package/dist/third-parties/meta-pixel.d.mts +2 -2
- package/dist/third-parties/meta-pixel.mjs +1 -1
- package/dist/third-parties/microsoft-uet.cjs +1 -1
- package/dist/third-parties/microsoft-uet.cjs.map +1 -1
- package/dist/third-parties/microsoft-uet.d.cts +2 -2
- package/dist/third-parties/microsoft-uet.d.mts +2 -2
- package/dist/third-parties/microsoft-uet.mjs +1 -1
- package/dist/third-parties/microsoft-uet.mjs.map +1 -1
- package/dist/third-parties/openai-pixel.cjs +1 -1
- package/dist/third-parties/openai-pixel.d.cts +2 -2
- package/dist/third-parties/openai-pixel.d.mts +2 -2
- package/dist/third-parties/openai-pixel.mjs +1 -1
- package/dist/third-parties/posthog.d.cts +1 -1
- package/dist/third-parties/posthog.d.mts +1 -1
- package/dist/third-parties/reddit-pixel.cjs +1 -1
- package/dist/third-parties/reddit-pixel.d.cts +2 -2
- package/dist/third-parties/reddit-pixel.d.mts +2 -2
- package/dist/third-parties/reddit-pixel.mjs +1 -1
- package/dist/track/index.cjs.map +1 -1
- package/dist/track/index.mjs.map +1 -1
- package/dist/track/once.cjs.map +1 -1
- package/dist/track/once.d.cts +1 -1
- package/dist/track/once.d.mts +1 -1
- package/dist/visitor/id.cjs +1 -1
- package/dist/visitor/id.cjs.map +1 -1
- package/dist/visitor/id.mjs +1 -1
- package/dist/visitor/index.cjs +2 -2
- package/dist/visitor/index.cjs.map +1 -1
- package/dist/visitor/index.mjs +2 -2
- package/dist/web/index.cjs +3 -5
- package/dist/web/index.cjs.map +1 -1
- package/dist/web/index.d.cts +1 -1
- package/dist/web/index.d.mts +1 -1
- package/dist/web/index.mjs +3 -5
- package/dist/web/index.mjs.map +1 -1
- package/package.json +11 -11
- package/dist/_virtual/_rolldown/runtime.mjs +0 -23
- package/dist/node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.cjs +0 -1724
- package/dist/node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.cjs.map +0 -1
- package/dist/node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.mjs +0 -1721
- package/dist/node_modules/.pnpm/bowser@2.14.1/node_modules/bowser/es5.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { MicrosoftAdsOptions } from "../third-parties/microsoft-uet.cjs";
|
|
1
2
|
import { TrackEvent, UserProvidedData } from "../track/types.cjs";
|
|
2
3
|
import { ConversionDestination } from "./setup-conversions.cjs";
|
|
3
|
-
import { MicrosoftAdsOptions } from "../third-parties/microsoft-uet.cjs";
|
|
4
4
|
/**
|
|
5
5
|
* Microsoft's email normalization: trim, drop the dots and any `+alias` from the user part —
|
|
6
6
|
* for EVERY domain, unlike Google's gmail-only rule — lowercase, SHA-256. A value that is
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { MicrosoftAdsOptions } from "../third-parties/microsoft-uet.mjs";
|
|
1
2
|
import { TrackEvent, UserProvidedData } from "../track/types.mjs";
|
|
2
3
|
import { ConversionDestination } from "./setup-conversions.mjs";
|
|
3
|
-
import { MicrosoftAdsOptions } from "../third-parties/microsoft-uet.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* Microsoft's email normalization: trim, drop the dots and any `+alias` from the user part —
|
|
6
6
|
* for EVERY domain, unlike Google's gmail-only rule — lowercase, SHA-256. A value that is
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { IGNORED_EVENTS } from "../third-parties/ignored-events.mjs";
|
|
2
1
|
import { formatMsclkid } from "../click-id/index.mjs";
|
|
3
|
-
import {
|
|
2
|
+
import { IGNORED_EVENTS } from "../third-parties/ignored-events.mjs";
|
|
4
3
|
import { uetEvents } from "../third-parties/microsoft-uet.mjs";
|
|
4
|
+
import { mapUETEvent } from "../track/uetq.mjs";
|
|
5
5
|
import { microsoftMsclkid } from "./click-ids.mjs";
|
|
6
6
|
import { ConversionsApiError } from "./conversions-api-error.mjs";
|
|
7
7
|
import { eventTimeMs } from "./event-time.mjs";
|
|
8
|
-
import { conversionDestination } from "./setup-conversions.mjs";
|
|
9
8
|
import { pageLocation } from "./page-location.mjs";
|
|
9
|
+
import { conversionDestination } from "./setup-conversions.mjs";
|
|
10
10
|
import { chunk, fetch } from "@shware/utils";
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
12
|
// src/server/microsoft-conversions-api.ts
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_third_parties_ignored_events = require("../third-parties/ignored-events.cjs");
|
|
3
3
|
const require_third_parties_integration = require("../third-parties/integration.cjs");
|
|
4
|
+
const require_track_oaiq = require("../track/oaiq.cjs");
|
|
4
5
|
const require_server_action_source = require("./action-source.cjs");
|
|
5
6
|
const require_server_click_ids = require("./click-ids.cjs");
|
|
6
7
|
const require_server_conversions_api_error = require("./conversions-api-error.cjs");
|
|
7
|
-
const require_server_setup_conversions = require("./setup-conversions.cjs");
|
|
8
8
|
const require_server_page_location = require("./page-location.cjs");
|
|
9
|
-
const
|
|
9
|
+
const require_server_setup_conversions = require("./setup-conversions.cjs");
|
|
10
10
|
let _shware_utils = require("@shware/utils");
|
|
11
11
|
let node_crypto = require("node:crypto");
|
|
12
12
|
// src/server/openai-conversions-api.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { OpenAIAdsOptions } from "../third-parties/openai-pixel.cjs";
|
|
2
|
+
import { EventData } from "../track/oaiq.cjs";
|
|
1
3
|
import { TrackEvent, UserProvidedData } from "../track/types.cjs";
|
|
2
4
|
import { EventActionSource } from "./action-source.cjs";
|
|
3
5
|
import { ConversionDestination } from "./setup-conversions.cjs";
|
|
4
|
-
import { EventData } from "../track/oaiq.cjs";
|
|
5
|
-
import { OpenAIAdsOptions } from "../third-parties/openai-pixel.cjs";
|
|
6
6
|
type ActionSource = 'web' | 'mobile_app' | 'offline' | 'physical_store' | 'phone_call' | 'email' | 'other';
|
|
7
7
|
/**
|
|
8
8
|
* Conversion-matching fields, all optional. Identifiers are normalized, then sent as lowercase
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { OpenAIAdsOptions } from "../third-parties/openai-pixel.mjs";
|
|
2
|
+
import { EventData } from "../track/oaiq.mjs";
|
|
1
3
|
import { TrackEvent, UserProvidedData } from "../track/types.mjs";
|
|
2
4
|
import { EventActionSource } from "./action-source.mjs";
|
|
3
5
|
import { ConversionDestination } from "./setup-conversions.mjs";
|
|
4
|
-
import { EventData } from "../track/oaiq.mjs";
|
|
5
|
-
import { OpenAIAdsOptions } from "../third-parties/openai-pixel.mjs";
|
|
6
6
|
type ActionSource = 'web' | 'mobile_app' | 'offline' | 'physical_store' | 'phone_call' | 'email' | 'other';
|
|
7
7
|
/**
|
|
8
8
|
* Conversion-matching fields, all optional. Identifiers are normalized, then sent as lowercase
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { IGNORED_EVENTS } from "../third-parties/ignored-events.mjs";
|
|
2
2
|
import { adEvents } from "../third-parties/integration.mjs";
|
|
3
|
+
import { APP_EVENTS, NON_AD_EVENTS, isStandardOAIEvent, mapOAIEvent, normalizeOAIName, normalizeOAIPhone, oaiCustomEventName } from "../track/oaiq.mjs";
|
|
3
4
|
import { resolveActionSource } from "./action-source.mjs";
|
|
4
5
|
import { openaiOppref } from "./click-ids.mjs";
|
|
5
6
|
import { ConversionsApiError } from "./conversions-api-error.mjs";
|
|
6
|
-
import { conversionDestination } from "./setup-conversions.mjs";
|
|
7
7
|
import { pageLocation } from "./page-location.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { conversionDestination } from "./setup-conversions.mjs";
|
|
9
9
|
import { fetch } from "@shware/utils";
|
|
10
10
|
import { createHash } from "node:crypto";
|
|
11
11
|
// src/server/openai-conversions-api.ts
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_third_parties_ignored_events = require("../third-parties/ignored-events.cjs");
|
|
3
|
-
const require_utils_field = require("../utils/field.cjs");
|
|
4
3
|
const require_third_parties_integration = require("../third-parties/integration.cjs");
|
|
4
|
+
const require_track_rdt = require("../track/rdt.cjs");
|
|
5
|
+
const require_utils_field = require("../utils/field.cjs");
|
|
5
6
|
const require_server_action_source = require("./action-source.cjs");
|
|
6
7
|
const require_server_click_ids = require("./click-ids.cjs");
|
|
7
8
|
const require_server_conversions_api_error = require("./conversions-api-error.cjs");
|
|
8
9
|
const require_server_event_time = require("./event-time.cjs");
|
|
9
|
-
const require_server_setup_conversions = require("./setup-conversions.cjs");
|
|
10
10
|
const require_server_page_location = require("./page-location.cjs");
|
|
11
|
-
const
|
|
11
|
+
const require_server_setup_conversions = require("./setup-conversions.cjs");
|
|
12
12
|
let _shware_utils = require("@shware/utils");
|
|
13
13
|
// src/server/reddit-conversions-api.ts
|
|
14
14
|
function getServerEvent(event, data, actionSource) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { RedditAdsOptions } from "../third-parties/reddit-pixel.cjs";
|
|
2
|
+
import { ServerStandardEvent } from "../track/rdt.cjs";
|
|
1
3
|
import { TrackEvent, UserProvidedData } from "../track/types.cjs";
|
|
2
4
|
import { EventActionSource } from "./action-source.cjs";
|
|
3
5
|
import { ConversionDestination } from "./setup-conversions.cjs";
|
|
4
|
-
import { ServerStandardEvent } from "../track/rdt.cjs";
|
|
5
|
-
import { RedditAdsOptions } from "../third-parties/reddit-pixel.cjs";
|
|
6
6
|
/**
|
|
7
7
|
* https://ads-api.reddit.com/docs/v3/operations/Post%20Conversion%20Events
|
|
8
8
|
* https://business.reddithelp.com/s/article/map-a-catalog-to-a-signal-source
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { RedditAdsOptions } from "../third-parties/reddit-pixel.mjs";
|
|
2
|
+
import { ServerStandardEvent } from "../track/rdt.mjs";
|
|
1
3
|
import { TrackEvent, UserProvidedData } from "../track/types.mjs";
|
|
2
4
|
import { EventActionSource } from "./action-source.mjs";
|
|
3
5
|
import { ConversionDestination } from "./setup-conversions.mjs";
|
|
4
|
-
import { ServerStandardEvent } from "../track/rdt.mjs";
|
|
5
|
-
import { RedditAdsOptions } from "../third-parties/reddit-pixel.mjs";
|
|
6
6
|
/**
|
|
7
7
|
* https://ads-api.reddit.com/docs/v3/operations/Post%20Conversion%20Events
|
|
8
8
|
* https://business.reddithelp.com/s/article/map-a-catalog-to-a-signal-source
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IGNORED_EVENTS } from "../third-parties/ignored-events.mjs";
|
|
2
|
-
import { getFirst } from "../utils/field.mjs";
|
|
3
2
|
import { adEvents } from "../third-parties/integration.mjs";
|
|
3
|
+
import { isStandardRDTEvent, mapRDTEvent, mapServerStandardEvent } from "../track/rdt.mjs";
|
|
4
|
+
import { getFirst } from "../utils/field.mjs";
|
|
4
5
|
import { resolveActionSource } from "./action-source.mjs";
|
|
5
6
|
import { redditClickId, redditUuid } from "./click-ids.mjs";
|
|
6
7
|
import { ConversionsApiError } from "./conversions-api-error.mjs";
|
|
7
8
|
import { eventTimeMs } from "./event-time.mjs";
|
|
8
|
-
import { conversionDestination } from "./setup-conversions.mjs";
|
|
9
9
|
import { pageLocation } from "./page-location.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { conversionDestination } from "./setup-conversions.mjs";
|
|
11
11
|
import { fetch } from "@shware/utils";
|
|
12
12
|
// src/server/reddit-conversions-api.ts
|
|
13
13
|
function getServerEvent(event, data, actionSource) {
|
package/dist/setup/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Environment, EventName, Platform, TrackTags } from "../track/types.cjs";
|
|
2
1
|
import { Integration } from "../third-parties/integration.cjs";
|
|
2
|
+
import { Environment, EventName, Platform, TrackTags } from "../track/types.cjs";
|
|
3
3
|
export interface Storage {
|
|
4
4
|
getItem: (key: string) => string | null;
|
|
5
5
|
setItem: (key: string, value: string) => void;
|
package/dist/setup/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Environment, EventName, Platform, TrackTags } from "../track/types.mjs";
|
|
2
1
|
import { Integration } from "../third-parties/integration.mjs";
|
|
2
|
+
import { Environment, EventName, Platform, TrackTags } from "../track/types.mjs";
|
|
3
3
|
export interface Storage {
|
|
4
4
|
getItem: (key: string) => string | null;
|
|
5
5
|
setItem: (key: string, value: string) => void;
|
package/dist/setup/session.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_setup_index = require("./index.cjs");
|
|
3
2
|
const require_constants_storage = require("../constants/storage.cjs");
|
|
3
|
+
const require_setup_index = require("./index.cjs");
|
|
4
4
|
let uuid = require("uuid");
|
|
5
5
|
// src/setup/session.ts
|
|
6
6
|
const SESSION_TIMEOUT = 18e5;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.cjs","names":["config","keys","uuidv7"],"sources":["../../src/setup/session.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { config } from './index';\n\nexport const SESSION_TIMEOUT = 30 * 60 * 1000;\n\n/**\n * The part of a session that outlives the page: its identity, and the clock the timeout is\n * measured against. GA4 keeps these in its `_ga_<container>` cookie — alongside the engaged flag,\n * which arrives with `session_engaged` later — and rereads them for every event, which is what\n * makes a session survive a reload, span a whole multipage visit, and stay shared between two\n * tabs of the same site. Holding them in memory instead, as this did, starts a new session on\n * every full navigation and gives every tab one of its own.\n */\ninterface StoredSession {\n id: string;\n /** When the last event was sent. The timeout is measured from here, and only from here. */\n lastEventTime: number;\n}\n\n/** The session an event belongs to, and whether that event is the one that started it. */\ninterface SessionForEvent {\n id: string;\n started: boolean;\n}\n\n/**\n * `<version>.<id>.<lastEventTime>`, compact and cookie-safe rather than JSON: `{`, `\"`\n * and `,` all have to be percent-encoded in a cookie, and a host that wants one session across\n * its subdomains will hand `setupAnalytics` a cookie-backed `storage`, where this has to survive\n * unchanged. A uuidv7 contains no dots, so the record splits cleanly.\n *\n * The version guards a change the parser could not otherwise survive. A field appended to the end\n * does not need one — a short record simply leaves it undefined.\n */\nconst VERSION = '1';\n\nfunction readSession(): StoredSession | undefined {\n const raw = config.storage.getItem(keys.session);\n if (!raw) return undefined;\n\n const [version, id, lastEventTime] = raw.split('.');\n if (version !== VERSION || !id) return undefined;\n\n const parsed = { id, lastEventTime: Number(lastEventTime) };\n if (!Number.isFinite(parsed.lastEventTime)) return undefined;\n return parsed;\n}\n\nfunction writeSession({ id, lastEventTime }: StoredSession) {\n config.storage.setItem(keys.session, `${VERSION}.${id}.${lastEventTime}`);\n}\n\nclass Session {\n /**\n * Engagement is deliberately not stored: it is the time this page has accrued and not yet\n * reported, so it belongs to the page, not to the session. GA4 draws the same line — its cookie\n * carries the session, while the engagement timer lives and dies with the document.\n *\n * `lastTickTime` is where the accumulator last settled up, rewritten on every tick — it is not\n * when the session began, and nothing here needs to know that.\n */\n private lastTickTime: number;\n private accumulatedTime: number;\n\n private active: boolean;\n private visible: boolean;\n private focused: boolean;\n\n constructor() {\n this.lastTickTime = Date.now();\n this.accumulatedTime = 0;\n\n this.active = true;\n this.visible = typeof document !== 'undefined' ? document.visibilityState === 'visible' : true;\n this.focused = typeof document !== 'undefined' ? document.hasFocus() : true;\n }\n\n /**\n * The session a batch of events belongs to: read the stored one, start a new one if it has\n * timed out or there is none, stamp it with when those events happened and write it back. Every\n * event goes through here, exactly as GA4 rereads and rewrites its cookie per event — caching\n * the session in memory would put the tabs back out of step with each other.\n */\n touch = (eventTime: number, lastEventTime = eventTime): SessionForEvent => {\n const stored = readSession();\n\n if (stored && eventTime - stored.lastEventTime <= SESSION_TIMEOUT) {\n // `Math.max`, because a batch that waited in a frozen tab can be older than what another\n // tab has since written, and a session must never be shortened by a late arrival.\n writeSession({ ...stored, lastEventTime: Math.max(stored.lastEventTime, lastEventTime) });\n return { id: stored.id, started: false };\n }\n\n // Engagement the previous session accrued but never reported dies with it rather than being\n // handed to its successor. GA4 does the same on `session_start`.\n this.accumulatedTime = 0;\n // Wall clock, not `eventTime`: this anchors the engagement timer for the page in front of the\n // visitor now, which a batch describing something that happened an hour ago says nothing about.\n this.lastTickTime = Date.now();\n\n const session: StoredSession = { id: uuidv7(), lastEventTime };\n writeSession(session);\n return { id: session.id, started: true };\n };\n\n /**\n * The id for an event that must not start a session — the engagement beacon, which reports what\n * the session accrued. A live session is extended, as any event extends it; one already past its\n * timeout still owns that engagement, so its id comes back without being revived into a session\n * no `session_start` ever announced. With nothing stored, no event was ever queued here, so\n * there is no session to report for, and none is started: it would never be announced.\n */\n extend = (): string | undefined => {\n const stored = readSession();\n if (!stored) return undefined;\n\n const now = Date.now();\n if (now - stored.lastEventTime <= SESSION_TIMEOUT) {\n writeSession({ ...stored, lastEventTime: now });\n }\n return stored.id;\n };\n\n /**\n * Ends the stored session for `reset()`, so the next event starts a new one and announces it.\n * Returns the session's id and the engagement it accrued and has not reported, for the caller\n * to report; one past its timeout still owns that engagement, as in `extend`, and is not\n * revived. The storage has no `removeItem`: an empty record reads as none.\n */\n end = (): { id: string | undefined; engagement_time_msec: number } => {\n const engagement_time_msec = this.flush();\n const id = readSession()?.id;\n config.storage.setItem(keys.session, '');\n return { id, engagement_time_msec };\n };\n\n isActive = () => this.active;\n\n updateActive = (active: boolean) => {\n this.active = active;\n };\n\n updateAccumulator = () => {\n const now = Date.now();\n if (this.focused && this.visible && this.active) {\n const delta = now - this.lastTickTime;\n if (delta > 0 && delta < SESSION_TIMEOUT) {\n this.accumulatedTime += delta;\n }\n }\n this.lastTickTime = now;\n };\n\n focus = () => {\n this.updateAccumulator();\n this.focused = true;\n };\n\n blur = () => {\n this.updateAccumulator();\n this.focused = false;\n };\n\n pageshow = () => {\n this.updateAccumulator();\n this.active = true;\n };\n\n pagehide = () => {\n this.updateAccumulator();\n this.active = false;\n };\n\n visibilitychange = (state: DocumentVisibilityState) => {\n this.updateAccumulator();\n this.visible = state === 'visible';\n };\n\n flush = () => {\n this.updateAccumulator();\n const engagementTime = this.accumulatedTime;\n this.accumulatedTime = 0;\n return engagementTime;\n };\n}\n\nlet session: Session | undefined;\n\n/**\n * The session, built the first time something asks for it.\n *\n * Deliberately not a module-scope `new Session()`. The constructor calls\n * `uuidv7()`, `uuid` draws its bytes from `crypto.getRandomValues`, and\n * Cloudflare Workers reject that outside a request handler:\n *\n * Disallowed operation called within global scope. Asynchronous I/O\n * (ex: fetch() or connect()), setting a timeout, and generating random\n * values are not allowed within global scope.\n *\n * Module scope in a Worker is evaluated once when the isolate boots and is\n * then shared by every request that isolate serves, so a random value drawn\n * there would be the same for all of them — which is why the runtime refuses\n * to produce one. A host that server-renders on Workers reaches this module\n * through `track()` on the server as well, and the throw happened as the\n * isolate booted, taking down every route before a component rendered.\n *\n * Everything here is per-visitor browser or app state, so deferring the\n * construction costs nothing and lets the server bundle be evaluated. It does\n * not make any of it safe to use there: this instance, `cache` and `config` are\n * module singletons, so calling `track()` on a server shares one session and one\n * visitor across every request the isolate serves. Import it there; do not track.\n */\nexport function getSession() {\n return (session ??= new Session());\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"session.cjs","names":["config","keys","uuidv7"],"sources":["../../src/setup/session.ts"],"sourcesContent":["import { v7 as uuidv7 } from 'uuid';\nimport { keys } from '../constants/storage';\nimport { config } from './index';\n\nexport const SESSION_TIMEOUT = 30 * 60 * 1000;\n\n/**\n * The part of a session that outlives the page: its identity, and the clock the timeout is\n * measured against. GA4 keeps these in its `_ga_<container>` cookie — alongside the engaged flag,\n * which arrives with `session_engaged` later — and rereads them for every event, which is what\n * makes a session survive a reload, span a whole multipage visit, and stay shared between two\n * tabs of the same site. Holding them in memory instead, as this did, starts a new session on\n * every full navigation and gives every tab one of its own.\n */\ninterface StoredSession {\n id: string;\n /** When the last event was sent. The timeout is measured from here, and only from here. */\n lastEventTime: number;\n}\n\n/** The session an event belongs to, and whether that event is the one that started it. */\ninterface SessionForEvent {\n id: string;\n started: boolean;\n}\n\n/**\n * `<version>.<id>.<lastEventTime>`, compact and cookie-safe rather than JSON: `{`, `\"`\n * and `,` all have to be percent-encoded in a cookie, and a host that wants one session across\n * its subdomains will hand `setupAnalytics` a cookie-backed `storage`, where this has to survive\n * unchanged. A uuidv7 contains no dots, so the record splits cleanly.\n *\n * The version guards a change the parser could not otherwise survive. A field appended to the end\n * does not need one — a short record simply leaves it undefined.\n */\nconst VERSION = '1';\n\nfunction readSession(): StoredSession | undefined {\n const raw = config.storage.getItem(keys.session);\n if (!raw) return undefined;\n\n const [version, id, lastEventTime] = raw.split('.');\n if (version !== VERSION || !id) return undefined;\n\n const parsed = { id, lastEventTime: Number(lastEventTime) };\n if (!Number.isFinite(parsed.lastEventTime)) return undefined;\n return parsed;\n}\n\nfunction writeSession({ id, lastEventTime }: StoredSession) {\n config.storage.setItem(keys.session, `${VERSION}.${id}.${lastEventTime}`);\n}\n\nclass Session {\n /**\n * Engagement is deliberately not stored: it is the time this page has accrued and not yet\n * reported, so it belongs to the page, not to the session. GA4 draws the same line — its cookie\n * carries the session, while the engagement timer lives and dies with the document.\n *\n * `lastTickTime` is where the accumulator last settled up, rewritten on every tick — it is not\n * when the session began, and nothing here needs to know that.\n */\n private lastTickTime: number;\n private accumulatedTime: number;\n\n private active: boolean;\n private visible: boolean;\n private focused: boolean;\n\n constructor() {\n this.lastTickTime = Date.now();\n this.accumulatedTime = 0;\n\n this.active = true;\n this.visible = typeof document !== 'undefined' ? document.visibilityState === 'visible' : true;\n this.focused = typeof document !== 'undefined' ? document.hasFocus() : true;\n }\n\n /**\n * The session a batch of events belongs to: read the stored one, start a new one if it has\n * timed out or there is none, stamp it with when those events happened and write it back. Every\n * event goes through here, exactly as GA4 rereads and rewrites its cookie per event — caching\n * the session in memory would put the tabs back out of step with each other.\n */\n touch = (eventTime: number, lastEventTime = eventTime): SessionForEvent => {\n const stored = readSession();\n\n if (stored && eventTime - stored.lastEventTime <= SESSION_TIMEOUT) {\n // `Math.max`, because a batch that waited in a frozen tab can be older than what another\n // tab has since written, and a session must never be shortened by a late arrival.\n writeSession({ ...stored, lastEventTime: Math.max(stored.lastEventTime, lastEventTime) });\n return { id: stored.id, started: false };\n }\n\n // Engagement the previous session accrued but never reported dies with it rather than being\n // handed to its successor. GA4 does the same on `session_start`.\n this.accumulatedTime = 0;\n // Wall clock, not `eventTime`: this anchors the engagement timer for the page in front of the\n // visitor now, which a batch describing something that happened an hour ago says nothing about.\n this.lastTickTime = Date.now();\n\n const session: StoredSession = { id: uuidv7(), lastEventTime };\n writeSession(session);\n return { id: session.id, started: true };\n };\n\n /**\n * The id for an event that must not start a session — the engagement beacon, which reports what\n * the session accrued. A live session is extended, as any event extends it; one already past its\n * timeout still owns that engagement, so its id comes back without being revived into a session\n * no `session_start` ever announced. With nothing stored, no event was ever queued here, so\n * there is no session to report for, and none is started: it would never be announced.\n */\n extend = (): string | undefined => {\n const stored = readSession();\n if (!stored) return undefined;\n\n const now = Date.now();\n if (now - stored.lastEventTime <= SESSION_TIMEOUT) {\n writeSession({ ...stored, lastEventTime: now });\n }\n return stored.id;\n };\n\n /**\n * Ends the stored session for `reset()`, so the next event starts a new one and announces it.\n * Returns the session's id and the engagement it accrued and has not reported, for the caller\n * to report; one past its timeout still owns that engagement, as in `extend`, and is not\n * revived. The storage has no `removeItem`: an empty record reads as none.\n */\n end = (): { id: string | undefined; engagement_time_msec: number } => {\n const engagement_time_msec = this.flush();\n const id = readSession()?.id;\n config.storage.setItem(keys.session, '');\n return { id, engagement_time_msec };\n };\n\n isActive = () => this.active;\n\n updateActive = (active: boolean) => {\n this.active = active;\n };\n\n updateAccumulator = () => {\n const now = Date.now();\n if (this.focused && this.visible && this.active) {\n const delta = now - this.lastTickTime;\n if (delta > 0 && delta < SESSION_TIMEOUT) {\n this.accumulatedTime += delta;\n }\n }\n this.lastTickTime = now;\n };\n\n focus = () => {\n this.updateAccumulator();\n this.focused = true;\n };\n\n blur = () => {\n this.updateAccumulator();\n this.focused = false;\n };\n\n pageshow = () => {\n this.updateAccumulator();\n this.active = true;\n };\n\n pagehide = () => {\n this.updateAccumulator();\n this.active = false;\n };\n\n visibilitychange = (state: DocumentVisibilityState) => {\n this.updateAccumulator();\n this.visible = state === 'visible';\n };\n\n flush = () => {\n this.updateAccumulator();\n const engagementTime = this.accumulatedTime;\n this.accumulatedTime = 0;\n return engagementTime;\n };\n}\n\nlet session: Session | undefined;\n\n/**\n * The session, built the first time something asks for it.\n *\n * Deliberately not a module-scope `new Session()`. The constructor calls\n * `uuidv7()`, `uuid` draws its bytes from `crypto.getRandomValues`, and\n * Cloudflare Workers reject that outside a request handler:\n *\n * Disallowed operation called within global scope. Asynchronous I/O\n * (ex: fetch() or connect()), setting a timeout, and generating random\n * values are not allowed within global scope.\n *\n * Module scope in a Worker is evaluated once when the isolate boots and is\n * then shared by every request that isolate serves, so a random value drawn\n * there would be the same for all of them — which is why the runtime refuses\n * to produce one. A host that server-renders on Workers reaches this module\n * through `track()` on the server as well, and the throw happened as the\n * isolate booted, taking down every route before a component rendered.\n *\n * Everything here is per-visitor browser or app state, so deferring the\n * construction costs nothing and lets the server bundle be evaluated. It does\n * not make any of it safe to use there: this instance, `cache` and `config` are\n * module singletons, so calling `track()` on a server shares one session and one\n * visitor across every request the isolate serves. Import it there; do not track.\n */\nexport function getSession() {\n return (session ??= new Session());\n}\n"],"mappings":";;;;;AAIA,MAAa,kBAAkB;;;;;;;;;;AA+B/B,MAAM,UAAU;AAEhB,SAAS,cAAyC;CAChD,MAAM,MAAMA,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,OAAO;CAC/C,IAAI,CAAC,KAAK,OAAO,KAAA;CAEjB,MAAM,CAAC,SAAS,IAAI,iBAAiB,IAAI,MAAM,GAAG;CAClD,IAAI,YAAY,WAAW,CAAC,IAAI,OAAO,KAAA;CAEvC,MAAM,SAAS;EAAE;EAAI,eAAe,OAAO,aAAa;CAAE;CAC1D,IAAI,CAAC,OAAO,SAAS,OAAO,aAAa,GAAG,OAAO,KAAA;CACnD,OAAO;AACT;AAEA,SAAS,aAAa,EAAE,IAAI,iBAAgC;CAC1DD,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,SAAS,GAAG,QAAQ,GAAG,GAAG,GAAG,eAAe;AAC1E;AAEA,IAAM,UAAN,MAAc;CAgBZ,cAAc;EAeL,KAAA,SAAA,WAAmB,gBAAgB,cAA+B;GACzE,MAAM,SAAS,YAAY;GAE3B,IAAI,UAAU,YAAY,OAAO,iBAAA,MAAkC;IAGjE,aAAa;KAAE,GAAG;KAAQ,eAAe,KAAK,IAAI,OAAO,eAAe,aAAa;IAAE,CAAC;IACxF,OAAO;KAAE,IAAI,OAAO;KAAI,SAAS;IAAM;GACzC;GAIA,KAAK,kBAAkB;GAGvB,KAAK,eAAe,KAAK,IAAI;GAE7B,MAAM,UAAyB;IAAE,KAAA,GAAIC,KAAAA,GAAAA,CAAO;IAAG;GAAc;GAC7D,aAAa,OAAO;GACpB,OAAO;IAAE,IAAI,QAAQ;IAAI,SAAS;GAAK;EACzC;EASmC,KAAA,eAAA;GACjC,MAAM,SAAS,YAAY;GAC3B,IAAI,CAAC,QAAQ,OAAO,KAAA;GAEpB,MAAM,MAAM,KAAK,IAAI;GACrB,IAAI,MAAM,OAAO,iBAAA,MACf,aAAa;IAAE,GAAG;IAAQ,eAAe;GAAI,CAAC;GAEhD,OAAO,OAAO;EAChB;EAQsE,KAAA,YAAA;GACpE,MAAM,uBAAuB,KAAK,MAAM;GACxC,MAAM,KAAK,YAAY,CAAC,EAAE;GAC1BF,oBAAAA,OAAO,QAAQ,QAAQC,0BAAAA,KAAK,SAAS,EAAE;GACvC,OAAO;IAAE;IAAI;GAAqB;EACpC;EAEiB,KAAA,iBAAA,KAAK;EAEN,KAAA,gBAAA,WAAoB;GAClC,KAAK,SAAS;EAChB;EAE0B,KAAA,0BAAA;GACxB,MAAM,MAAM,KAAK,IAAI;GACrB,IAAI,KAAK,WAAW,KAAK,WAAW,KAAK,QAAQ;IAC/C,MAAM,QAAQ,MAAM,KAAK;IACzB,IAAI,QAAQ,KAAK,QAAA,MACf,KAAK,mBAAmB;GAE5B;GACA,KAAK,eAAe;EACtB;EAEc,KAAA,cAAA;GACZ,KAAK,kBAAkB;GACvB,KAAK,UAAU;EACjB;EAEa,KAAA,aAAA;GACX,KAAK,kBAAkB;GACvB,KAAK,UAAU;EACjB;EAEiB,KAAA,iBAAA;GACf,KAAK,kBAAkB;GACvB,KAAK,SAAS;EAChB;EAEiB,KAAA,iBAAA;GACf,KAAK,kBAAkB;GACvB,KAAK,SAAS;EAChB;EAEoB,KAAA,oBAAA,UAAmC;GACrD,KAAK,kBAAkB;GACvB,KAAK,UAAU,UAAU;EAC3B;EAEc,KAAA,cAAA;GACZ,KAAK,kBAAkB;GACvB,MAAM,iBAAiB,KAAK;GAC5B,KAAK,kBAAkB;GACvB,OAAO;EACT;EAlHE,KAAK,eAAe,KAAK,IAAI;EAC7B,KAAK,kBAAkB;EAEvB,KAAK,SAAS;EACd,KAAK,UAAU,OAAO,aAAa,cAAc,SAAS,oBAAoB,YAAY;EAC1F,KAAK,UAAU,OAAO,aAAa,cAAc,SAAS,SAAS,IAAI;CACzE;AA6GF;AAEA,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;AA0BJ,SAAgB,aAAa;CAC3B,OAAQ,YAAY,IAAI,QAAQ;AAClC"}
|
package/dist/setup/session.mjs
CHANGED
package/dist/test/setup.cjs
CHANGED
|
@@ -41,7 +41,7 @@ function requestUrl(input) {
|
|
|
41
41
|
}
|
|
42
42
|
/** These transports serialize JSON to a text body; an absent or binary body is a test failure. */
|
|
43
43
|
function textRequestBody(init) {
|
|
44
|
-
if (typeof init?.body !== "string") throw new
|
|
44
|
+
if (typeof init?.body !== "string") throw new TypeError("Expected a text request body");
|
|
45
45
|
return init.body;
|
|
46
46
|
}
|
|
47
47
|
exports.baseOptions = baseOptions;
|
package/dist/test/setup.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.cjs","names":[],"sources":["../../src/test/setup.ts"],"sourcesContent":["import type { Options } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\n/**\n * The SDK's state — `config`, `cache`, the session singleton, the track queue — lives in module\n * scope, exactly as it does in a browser. Tests therefore load the modules fresh per test with\n * `vi.resetModules()` and dynamic imports; this file only provides the pieces every test hands to\n * `setupAnalytics`, and is itself imported dynamically so it joins the same module graph.\n */\nexport function memoryStorage(seed: Record<string, string> = {}) {\n const map = new Map(Object.entries(seed));\n return {\n map,\n getItem: (key: string) => map.get(key) ?? null,\n setItem: (key: string, value: string) => {\n map.set(key, value);\n },\n };\n}\n\nexport function baseOptions(overrides: Partial<Options> = {}): Options {\n return {\n release: '1.0.0',\n storage: memoryStorage(),\n endpoint: 'https://api.test',\n platform: 'web',\n environment: 'production',\n getTags: (): TrackTags => ({}),\n getDeviceId: () => 'device-1',\n ...overrides,\n };\n}\n\n/** A minimal ok Response whose json body is `data`. */\nexport function jsonResponse(data: unknown, status = 200) {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n });\n}\n\n/** Read the URL passed to the real Fetch API, including Request inputs. */\nexport function requestUrl(input: Parameters<typeof globalThis.fetch>[0]): string {\n return input instanceof Request ? input.url : input.toString();\n}\n\n/** These transports serialize JSON to a text body; an absent or binary body is a test failure. */\nexport function textRequestBody(init: RequestInit | undefined): string {\n if (typeof init?.body !== 'string') throw new
|
|
1
|
+
{"version":3,"file":"setup.cjs","names":[],"sources":["../../src/test/setup.ts"],"sourcesContent":["import type { Options } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\n/**\n * The SDK's state — `config`, `cache`, the session singleton, the track queue — lives in module\n * scope, exactly as it does in a browser. Tests therefore load the modules fresh per test with\n * `vi.resetModules()` and dynamic imports; this file only provides the pieces every test hands to\n * `setupAnalytics`, and is itself imported dynamically so it joins the same module graph.\n */\nexport function memoryStorage(seed: Record<string, string> = {}) {\n const map = new Map(Object.entries(seed));\n return {\n map,\n getItem: (key: string) => map.get(key) ?? null,\n setItem: (key: string, value: string) => {\n map.set(key, value);\n },\n };\n}\n\nexport function baseOptions(overrides: Partial<Options> = {}): Options {\n return {\n release: '1.0.0',\n storage: memoryStorage(),\n endpoint: 'https://api.test',\n platform: 'web',\n environment: 'production',\n getTags: (): TrackTags => ({}),\n getDeviceId: () => 'device-1',\n ...overrides,\n };\n}\n\n/** A minimal ok Response whose json body is `data`. */\nexport function jsonResponse(data: unknown, status = 200) {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n });\n}\n\n/** Read the URL passed to the real Fetch API, including Request inputs. */\nexport function requestUrl(input: Parameters<typeof globalThis.fetch>[0]): string {\n return input instanceof Request ? input.url : input.toString();\n}\n\n/** These transports serialize JSON to a text body; an absent or binary body is a test failure. */\nexport function textRequestBody(init: RequestInit | undefined): string {\n if (typeof init?.body !== 'string') throw new TypeError('Expected a text request body');\n return init.body;\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,cAAc,OAA+B,CAAC,GAAG;CAC/D,MAAM,MAAM,IAAI,IAAI,OAAO,QAAQ,IAAI,CAAC;CACxC,OAAO;EACL;EACA,UAAU,QAAgB,IAAI,IAAI,GAAG,KAAK;EAC1C,UAAU,KAAa,UAAkB;GACvC,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF;AAEA,SAAgB,YAAY,YAA8B,CAAC,GAAY;CACrE,OAAO;EACL,SAAS;EACT,SAAS,cAAc;EACvB,UAAU;EACV,UAAU;EACV,aAAa;EACb,gBAA2B,CAAC;EAC5B,mBAAmB;EACnB,GAAG;CACL;AACF;;AAGA,SAAgB,aAAa,MAAe,SAAS,KAAK;CACxD,OAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;EACxC;EACA,SAAS,EAAE,gBAAgB,mBAAmB;CAChD,CAAC;AACH;;AAGA,SAAgB,WAAW,OAAuD;CAChF,OAAO,iBAAiB,UAAU,MAAM,MAAM,MAAM,SAAS;AAC/D;;AAGA,SAAgB,gBAAgB,MAAuC;CACrE,IAAI,OAAO,MAAM,SAAS,UAAU,MAAM,IAAI,UAAU,8BAA8B;CACtF,OAAO,KAAK;AACd"}
|
package/dist/test/setup.mjs
CHANGED
|
@@ -40,7 +40,7 @@ function requestUrl(input) {
|
|
|
40
40
|
}
|
|
41
41
|
/** These transports serialize JSON to a text body; an absent or binary body is a test failure. */
|
|
42
42
|
function textRequestBody(init) {
|
|
43
|
-
if (typeof init?.body !== "string") throw new
|
|
43
|
+
if (typeof init?.body !== "string") throw new TypeError("Expected a text request body");
|
|
44
44
|
return init.body;
|
|
45
45
|
}
|
|
46
46
|
export { baseOptions, jsonResponse, memoryStorage, requestUrl, textRequestBody };
|
package/dist/test/setup.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.mjs","names":[],"sources":["../../src/test/setup.ts"],"sourcesContent":["import type { Options } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\n/**\n * The SDK's state — `config`, `cache`, the session singleton, the track queue — lives in module\n * scope, exactly as it does in a browser. Tests therefore load the modules fresh per test with\n * `vi.resetModules()` and dynamic imports; this file only provides the pieces every test hands to\n * `setupAnalytics`, and is itself imported dynamically so it joins the same module graph.\n */\nexport function memoryStorage(seed: Record<string, string> = {}) {\n const map = new Map(Object.entries(seed));\n return {\n map,\n getItem: (key: string) => map.get(key) ?? null,\n setItem: (key: string, value: string) => {\n map.set(key, value);\n },\n };\n}\n\nexport function baseOptions(overrides: Partial<Options> = {}): Options {\n return {\n release: '1.0.0',\n storage: memoryStorage(),\n endpoint: 'https://api.test',\n platform: 'web',\n environment: 'production',\n getTags: (): TrackTags => ({}),\n getDeviceId: () => 'device-1',\n ...overrides,\n };\n}\n\n/** A minimal ok Response whose json body is `data`. */\nexport function jsonResponse(data: unknown, status = 200) {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n });\n}\n\n/** Read the URL passed to the real Fetch API, including Request inputs. */\nexport function requestUrl(input: Parameters<typeof globalThis.fetch>[0]): string {\n return input instanceof Request ? input.url : input.toString();\n}\n\n/** These transports serialize JSON to a text body; an absent or binary body is a test failure. */\nexport function textRequestBody(init: RequestInit | undefined): string {\n if (typeof init?.body !== 'string') throw new
|
|
1
|
+
{"version":3,"file":"setup.mjs","names":[],"sources":["../../src/test/setup.ts"],"sourcesContent":["import type { Options } from '../setup/index';\nimport type { TrackTags } from '../track/types';\n\n/**\n * The SDK's state — `config`, `cache`, the session singleton, the track queue — lives in module\n * scope, exactly as it does in a browser. Tests therefore load the modules fresh per test with\n * `vi.resetModules()` and dynamic imports; this file only provides the pieces every test hands to\n * `setupAnalytics`, and is itself imported dynamically so it joins the same module graph.\n */\nexport function memoryStorage(seed: Record<string, string> = {}) {\n const map = new Map(Object.entries(seed));\n return {\n map,\n getItem: (key: string) => map.get(key) ?? null,\n setItem: (key: string, value: string) => {\n map.set(key, value);\n },\n };\n}\n\nexport function baseOptions(overrides: Partial<Options> = {}): Options {\n return {\n release: '1.0.0',\n storage: memoryStorage(),\n endpoint: 'https://api.test',\n platform: 'web',\n environment: 'production',\n getTags: (): TrackTags => ({}),\n getDeviceId: () => 'device-1',\n ...overrides,\n };\n}\n\n/** A minimal ok Response whose json body is `data`. */\nexport function jsonResponse(data: unknown, status = 200) {\n return new Response(JSON.stringify(data), {\n status,\n headers: { 'Content-Type': 'application/json' },\n });\n}\n\n/** Read the URL passed to the real Fetch API, including Request inputs. */\nexport function requestUrl(input: Parameters<typeof globalThis.fetch>[0]): string {\n return input instanceof Request ? input.url : input.toString();\n}\n\n/** These transports serialize JSON to a text body; an absent or binary body is a test failure. */\nexport function textRequestBody(init: RequestInit | undefined): string {\n if (typeof init?.body !== 'string') throw new TypeError('Expected a text request body');\n return init.body;\n}\n"],"mappings":";;;;;;;AASA,SAAgB,cAAc,OAA+B,CAAC,GAAG;CAC/D,MAAM,MAAM,IAAI,IAAI,OAAO,QAAQ,IAAI,CAAC;CACxC,OAAO;EACL;EACA,UAAU,QAAgB,IAAI,IAAI,GAAG,KAAK;EAC1C,UAAU,KAAa,UAAkB;GACvC,IAAI,IAAI,KAAK,KAAK;EACpB;CACF;AACF;AAEA,SAAgB,YAAY,YAA8B,CAAC,GAAY;CACrE,OAAO;EACL,SAAS;EACT,SAAS,cAAc;EACvB,UAAU;EACV,UAAU;EACV,aAAa;EACb,gBAA2B,CAAC;EAC5B,mBAAmB;EACnB,GAAG;CACL;AACF;;AAGA,SAAgB,aAAa,MAAe,SAAS,KAAK;CACxD,OAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;EACxC;EACA,SAAS,EAAE,gBAAgB,mBAAmB;CAChD,CAAC;AACH;;AAGA,SAAgB,WAAW,OAAuD;CAChF,OAAO,iBAAiB,UAAU,MAAM,MAAM,MAAM,SAAS;AAC/D;;AAGA,SAAgB,gBAAgB,MAAuC;CACrE,IAAI,OAAO,MAAM,SAAS,UAAU,MAAM,IAAI,UAAU,8BAA8B;CACtF,OAAO,KAAK;AACd"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { UpdateVisitorDTO } from "../schema/index.cjs";
|
|
1
2
|
import { GaId, Gtag } from "../track/gtag.cjs";
|
|
2
3
|
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
3
|
-
import { UpdateVisitorDTO } from "../schema/index.cjs";
|
|
4
4
|
import { Integration } from "./integration.cjs";
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { UpdateVisitorDTO } from "../schema/index.mjs";
|
|
1
2
|
import { GaId, Gtag } from "../track/gtag.mjs";
|
|
2
3
|
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
3
|
-
import { UpdateVisitorDTO } from "../schema/index.mjs";
|
|
4
4
|
import { Integration } from "./integration.mjs";
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_third_parties_integration = require("./integration.cjs");
|
|
3
|
-
const require_third_parties_microsoft_uet = require("./microsoft-uet.cjs");
|
|
4
|
-
const require_third_parties_posthog = require("./posthog.cjs");
|
|
5
2
|
const require_third_parties_google_analytics = require("./google-analytics.cjs");
|
|
6
3
|
const require_third_parties_meta_pixel = require("./meta-pixel.cjs");
|
|
7
4
|
const require_third_parties_linkedin_insight_tag = require("./linkedin-insight-tag.cjs");
|
|
5
|
+
const require_third_parties_posthog = require("./posthog.cjs");
|
|
8
6
|
const require_third_parties_openai_pixel = require("./openai-pixel.cjs");
|
|
9
7
|
const require_third_parties_reddit_pixel = require("./reddit-pixel.cjs");
|
|
8
|
+
const require_third_parties_microsoft_uet = require("./microsoft-uet.cjs");
|
|
9
|
+
const require_third_parties_integration = require("./integration.cjs");
|
|
10
10
|
exports.CONVERSION_EVENTS = require_third_parties_integration.CONVERSION_EVENTS;
|
|
11
11
|
exports.capturePosthogException = require_third_parties_posthog.capturePosthogException;
|
|
12
12
|
exports.configureUET = require_third_parties_microsoft_uet.configureUET;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { googleAnalytics, sendGAEvent, setGAUser } from "./google-analytics.cjs";
|
|
2
2
|
import { metaAds, sendFBEvent, setFBUser } from "./meta-pixel.cjs";
|
|
3
|
-
import { redditAds, sendRedditEvent, setRedditUser } from "./reddit-pixel.cjs";
|
|
4
3
|
import { LinkedinConversionConfig, linkedInAds, sendLinkedinEvent, setLinkedinUser } from "./linkedin-insight-tag.cjs";
|
|
4
|
+
import { ErrorPattern, PostHog, PostHogConfig, PosthogErrorTrackingOptions, capturePosthogException, getLoadedPosthog, getPosthog, posthogAnalytics, posthogFlagsReady, sendPosthogEvent, setPosthogUser } from "./posthog.cjs";
|
|
5
5
|
import { openaiAds, sendOpenAIEvent, setOpenAIUser } from "./openai-pixel.cjs";
|
|
6
|
-
import {
|
|
6
|
+
import { redditAds, sendRedditEvent, setRedditUser } from "./reddit-pixel.cjs";
|
|
7
7
|
import { MicrosoftAdsIntegration, configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf } from "./microsoft-uet.cjs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { AdsOptions, CONVERSION_EVENTS, Integration, IntegrationScript, isLocalHost } from "./integration.cjs";
|
|
9
|
+
import { UETConsent, UETEventParams, UETItem, UETPageType, UETPid } from "../track/uetq.cjs";
|
|
10
10
|
export { type AdsOptions, CONVERSION_EVENTS, type ErrorPattern, type Integration, type IntegrationScript, type LinkedinConversionConfig, type MicrosoftAdsIntegration, type PostHog, type PostHogConfig, type PosthogErrorTrackingOptions, type UETConsent, type UETEventParams, type UETItem, type UETPageType, type UETPid, capturePosthogException, configureUET, getLoadedPosthog, getPosthog, googleAnalytics, isLocalHost, linkedInAds, metaAds, microsoftAds, openaiAds, posthogAnalytics, posthogFlagsReady, redditAds, sendFBEvent, sendGAEvent, sendLinkedinEvent, sendOpenAIEvent, sendPosthogEvent, sendRedditEvent, sendUETEvent, sendUETIdSync, setFBUser, setGAUser, setLinkedinUser, setOpenAIUser, setPosthogUser, setRedditUser, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { googleAnalytics, sendGAEvent, setGAUser } from "./google-analytics.mjs";
|
|
2
2
|
import { metaAds, sendFBEvent, setFBUser } from "./meta-pixel.mjs";
|
|
3
|
-
import { redditAds, sendRedditEvent, setRedditUser } from "./reddit-pixel.mjs";
|
|
4
3
|
import { LinkedinConversionConfig, linkedInAds, sendLinkedinEvent, setLinkedinUser } from "./linkedin-insight-tag.mjs";
|
|
4
|
+
import { ErrorPattern, PostHog, PostHogConfig, PosthogErrorTrackingOptions, capturePosthogException, getLoadedPosthog, getPosthog, posthogAnalytics, posthogFlagsReady, sendPosthogEvent, setPosthogUser } from "./posthog.mjs";
|
|
5
5
|
import { openaiAds, sendOpenAIEvent, setOpenAIUser } from "./openai-pixel.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { redditAds, sendRedditEvent, setRedditUser } from "./reddit-pixel.mjs";
|
|
7
7
|
import { MicrosoftAdsIntegration, configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf } from "./microsoft-uet.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { AdsOptions, CONVERSION_EVENTS, Integration, IntegrationScript, isLocalHost } from "./integration.mjs";
|
|
9
|
+
import { UETConsent, UETEventParams, UETItem, UETPageType, UETPid } from "../track/uetq.mjs";
|
|
10
10
|
export { type AdsOptions, CONVERSION_EVENTS, type ErrorPattern, type Integration, type IntegrationScript, type LinkedinConversionConfig, type MicrosoftAdsIntegration, type PostHog, type PostHogConfig, type PosthogErrorTrackingOptions, type UETConsent, type UETEventParams, type UETItem, type UETPageType, type UETPid, capturePosthogException, configureUET, getLoadedPosthog, getPosthog, googleAnalytics, isLocalHost, linkedInAds, metaAds, microsoftAds, openaiAds, posthogAnalytics, posthogFlagsReady, redditAds, sendFBEvent, sendGAEvent, sendLinkedinEvent, sendOpenAIEvent, sendPosthogEvent, sendRedditEvent, sendUETEvent, sendUETIdSync, setFBUser, setGAUser, setLinkedinUser, setOpenAIUser, setPosthogUser, setRedditUser, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CONVERSION_EVENTS, isLocalHost } from "./integration.mjs";
|
|
2
|
-
import { configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf } from "./microsoft-uet.mjs";
|
|
3
|
-
import { capturePosthogException, getLoadedPosthog, getPosthog, posthogAnalytics, posthogFlagsReady, sendPosthogEvent, setPosthogUser } from "./posthog.mjs";
|
|
4
1
|
import { googleAnalytics, sendGAEvent, setGAUser } from "./google-analytics.mjs";
|
|
5
2
|
import { metaAds, sendFBEvent, setFBUser } from "./meta-pixel.mjs";
|
|
6
3
|
import { linkedInAds, sendLinkedinEvent, setLinkedinUser } from "./linkedin-insight-tag.mjs";
|
|
4
|
+
import { capturePosthogException, getLoadedPosthog, getPosthog, posthogAnalytics, posthogFlagsReady, sendPosthogEvent, setPosthogUser } from "./posthog.mjs";
|
|
7
5
|
import { openaiAds, sendOpenAIEvent, setOpenAIUser } from "./openai-pixel.mjs";
|
|
8
6
|
import { redditAds, sendRedditEvent, setRedditUser } from "./reddit-pixel.mjs";
|
|
7
|
+
import { configureUET, microsoftAds, sendUETEvent, sendUETIdSync, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf } from "./microsoft-uet.mjs";
|
|
8
|
+
import { CONVERSION_EVENTS, isLocalHost } from "./integration.mjs";
|
|
9
9
|
export { CONVERSION_EVENTS, capturePosthogException, configureUET, getLoadedPosthog, getPosthog, googleAnalytics, isLocalHost, linkedInAds, metaAds, microsoftAds, openaiAds, posthogAnalytics, posthogFlagsReady, redditAds, sendFBEvent, sendGAEvent, sendLinkedinEvent, sendOpenAIEvent, sendPosthogEvent, sendRedditEvent, sendUETEvent, sendUETIdSync, setFBUser, setGAUser, setLinkedinUser, setOpenAIUser, setPosthogUser, setRedditUser, setUETConsent, setUETUser, syncUETVisitor, uetCustomerIdOf };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
2
1
|
import { UpdateVisitorDTO } from "../schema/index.cjs";
|
|
3
|
-
import { Integration } from "./integration.cjs";
|
|
4
2
|
import { Lintrk } from "../track/lintrk.cjs";
|
|
3
|
+
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
4
|
+
import { Integration } from "./integration.cjs";
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
7
7
|
/** Undefined until the LinkedIn Insight Tag script has loaded. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
2
1
|
import { UpdateVisitorDTO } from "../schema/index.mjs";
|
|
3
|
-
import { Integration } from "./integration.mjs";
|
|
4
2
|
import { Lintrk } from "../track/lintrk.mjs";
|
|
3
|
+
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
4
|
+
import { Integration } from "./integration.mjs";
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
7
7
|
/** Undefined until the LinkedIn Insight Tag script has loaded. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_track_fbq = require("../track/fbq.cjs");
|
|
2
3
|
const require_utils_field = require("../utils/field.cjs");
|
|
3
4
|
const require_third_parties_integration = require("./integration.cjs");
|
|
4
|
-
const require_track_fbq = require("../track/fbq.cjs");
|
|
5
5
|
// src/third-parties/meta-pixel.ts
|
|
6
6
|
const metrics = [
|
|
7
7
|
"CLS",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
2
1
|
import { UpdateVisitorDTO } from "../schema/index.cjs";
|
|
3
|
-
import { AdsOptions, Integration } from "./integration.cjs";
|
|
4
2
|
import { FBQ, PixelId } from "../track/fbq.cjs";
|
|
3
|
+
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
4
|
+
import { AdsOptions, Integration } from "./integration.cjs";
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
7
7
|
/** Undefined until the Meta Pixel script has loaded. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
2
1
|
import { UpdateVisitorDTO } from "../schema/index.mjs";
|
|
3
|
-
import { AdsOptions, Integration } from "./integration.mjs";
|
|
4
2
|
import { FBQ, PixelId } from "../track/fbq.mjs";
|
|
3
|
+
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
4
|
+
import { AdsOptions, Integration } from "./integration.mjs";
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
7
7
|
/** Undefined until the Meta Pixel script has loaded. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { isStandardFBEvent, mapFBEvent } from "../track/fbq.mjs";
|
|
1
2
|
import { getFirst } from "../utils/field.mjs";
|
|
2
3
|
import { adEvents, adsTracker, isLocalHost } from "./integration.mjs";
|
|
3
|
-
import { isStandardFBEvent, mapFBEvent } from "../track/fbq.mjs";
|
|
4
4
|
// src/third-parties/meta-pixel.ts
|
|
5
5
|
const metrics = [
|
|
6
6
|
"CLS",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_visitor_id = require("../visitor/id.cjs");
|
|
3
2
|
const require_track_uetq = require("../track/uetq.cjs");
|
|
4
3
|
const require_utils_field = require("../utils/field.cjs");
|
|
5
4
|
const require_utils_sha256 = require("../utils/sha256.cjs");
|
|
5
|
+
const require_visitor_id = require("../visitor/id.cjs");
|
|
6
6
|
const require_third_parties_integration = require("./integration.cjs");
|
|
7
7
|
// src/third-parties/microsoft-uet.ts
|
|
8
8
|
const metrics = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"microsoft-uet.cjs","names":["isLocalHost","mapUETEvent","getFirst","visitorId","CONVERSION_EVENTS","adEvents","adsTracker"],"sources":["../../src/third-parties/microsoft-uet.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { type UETConsent, type UETQ, mapUETEvent } from '../track/uetq';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { visitorId } from '../visitor/id';\nimport {\n type AdsOptions,\n CONVERSION_EVENTS,\n type Integration,\n adEvents,\n adsTracker,\n isLocalHost,\n} from './integration';\n\ndeclare global {\n interface Window {\n /**\n * Defined by the UET snippet before `bat.js` loads (as a plain array), so pushes made early\n * are queued rather than lost. Undefined only where the snippet was never installed.\n */\n uetq?: UETQ;\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\n/** Drop `undefined` fields: bat.js validates every key it receives, and `undefined` is a value. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\n/**\n * Forward an internal track event to the Microsoft Advertising UET tag.\n *\n * `eventId` is reused as UET's `event_id` so the browser event deduplicates against the same\n * conversion sent through the Conversions API (`sendMicrosoftEvents`). The action name is the\n * internal name on both channels — see `mapUETEvent`.\n *\n * `page_view` is not forwarded: bat.js turns that action into its page-load beacon, which the\n * snippet already fires on load and, with `enableAutoSpaTracking: true` (the setting in\n * Microsoft's generated snippet), on every history change — forwarding the SDK's own page views\n * would report each page twice. The tag owns page loads; this tracker owns everything else.\n */\nexport function sendUETEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return false;\n }\n if (metrics.includes(name) || name === 'page_view') return;\n if (isLocalHost()) return;\n\n const [action, params] = mapUETEvent(name, properties, eventId);\n window.uetq.push('event', action, clean(params));\n}\n\n/**\n * Enhanced conversions: hand the tag the visitor's email and phone so Microsoft can match a\n * conversion to an ad click without a third-party cookie. A `set` applies to every event fired\n * from the page afterwards, `pageLoad` included, and the tag fires a `pid` beacon on its own\n * when the page load already went out. Values are sent raw — the tag normalizes and SHA-256\n * hashes them in the browser (bat.js `validatePid`) before anything leaves the page.\n *\n * A setter itself, like `setGAUser`, rather than a factory like `setFBUser(pixelId)`: UET is\n * bound to its tag by the snippet and `set` addresses whichever tag drains `uetq`, so there is\n * nothing to bind first.\n */\nexport function setUETUser({ user_id, user_data }: UpdateVisitorDTO) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return;\n }\n\n // A signed-in user is also the moment the ID Sync pixel can carry a `UID` — see `syncUETVisitor`.\n if (user_id) void syncUETVisitor(user_id);\n\n const em = getFirst(user_data?.email);\n const ph = getFirst(user_data?.phone_number);\n if (!em && !ph) return;\n\n window.uetq.push('set', { pid: clean({ em, ph }) });\n}\n\n/**\n * UET consent mode. Push `default` before the tag loads (the tag processes `consent` early, ahead\n * of the queued events) and `update` when the visitor decides. With `ad_storage: 'denied'` the\n * tag neither writes its cookies nor reads the `msclkid` from the URL.\n * https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\nexport function setUETConsent(mode: 'default' | 'update', consent: UETConsent) {\n if (typeof window === 'undefined') return;\n window.uetq ??= [] as unknown as UETQ;\n window.uetq.push('consent', mode, consent);\n}\n\n/**\n * The Conversions API's client-side ID Sync pixel: ties the visitor id sent server-side as\n * `anonymousId` to Microsoft's own identifier, so server events can be attributed across\n * contexts (view-through, audiences). Microsoft requires it for remarketing built from CAPI\n * events and recommends it for measurement quality; fire it at least once per session, ideally\n * on the first page view. A pixel rather than a fetch on purpose: Microsoft must observe the\n * browser context of the sync, which a server-side call cannot carry.\n *\n * `customerId` is the Microsoft Advertising customer id (`cid` in the UI's URLs) — not the UET\n * tag id. `visitorId` is the SDK visitor id (`visitorId()`), which is what\n * `sendMicrosoftEvents` sends as `anonymousId`; Microsoft requires the two to be equal.\n * `userId` is the raw signed-in user id: it is SHA-256 hashed here, exactly as the server sender\n * hashes it into `externalId`, so the pair matches as well. Hashing is asynchronous, so the\n * pixel fires once the digest resolves; where SubtleCrypto is unavailable (an insecure context)\n * the pixel goes out without `UID` rather than with a raw id.\n * https://learn.microsoft.com/en-us/advertising/guides/uet-conversion-api-integration#id-sync-and-why-it-matters\n */\n/**\n * The Microsoft Advertising customer id the ID Sync pixel reports to, set once by the framework\n * `Analytics` component's `uetCustomerId` prop (or `configureUET`). Unset, nothing syncs.\n */\nlet uetCustomerId: string | undefined;\n\nexport function configureUET(options: { customerId?: string | number }) {\n uetCustomerId = options.customerId === undefined ? undefined : String(options.customerId);\n}\n\n/**\n * Sync the SDK visitor — the `anonymousId` of the events the server sends to the Conversions\n * API — with Microsoft, plus the user's `UID` when one is known. The `Analytics` components run\n * it on mount so every visit syncs at least once, anonymous visitors included (they are who\n * remarketing audiences are built from), and `setUETUser` runs it again on sign-in.\n */\nexport async function syncUETVisitor(userId?: string): Promise<void> {\n if (!uetCustomerId) return;\n sendUETIdSync({ customerId: uetCustomerId, visitorId: visitorId(), userId });\n}\n\nexport function sendUETIdSync(options: {\n customerId: string | number;\n visitorId: string;\n /** The signed-in user's id, raw; hashed before it leaves the page. */\n userId?: string;\n}) {\n if (typeof window === 'undefined' || typeof Image === 'undefined') return;\n if (isLocalHost()) return;\n\n const fire = (uid?: string) => {\n const params = new URLSearchParams({\n Red3: `BACID_${options.customerId}`,\n VID: options.visitorId,\n });\n if (uid) params.set('UID', uid);\n new Image().src = `https://c.bing.com/c.gif?${params.toString()}`;\n };\n\n if (!options.userId) {\n fire();\n return;\n }\n sha256(options.userId).then(fire, () => fire());\n}\n\n/** What `microsoftAds` returns: an integration that also names the customer id for ID Sync. */\nexport type MicrosoftAdsIntegration = Integration & { readonly uetCustomerId?: `${number}` };\n\n/** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */\nexport function uetCustomerIdOf(integrations: readonly Integration[] = []) {\n return integrations.find(\n (integration): integration is MicrosoftAdsIntegration => 'uetCustomerId' in integration\n )?.uetCustomerId;\n}\n\n/**\n * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined\n * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events\n * by default (`CONVERSION_EVENTS`), plus `customEvents`.\n *\n * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page\n * loads itself), the consent mode default pushed inside it so bat.js reads it before the first\n * page load.\n */\n/** The events UET receives: `events` (the GA4 conversion events by default) and `customEvents`. */\nexport function uetEvents(options: Pick<MicrosoftAdsOptions, 'events' | 'customEvents'>) {\n const events: readonly string[] = options.events ?? CONVERSION_EVENTS;\n return adEvents((name) => events.includes(name), options.customEvents);\n}\n\n/**\n * Microsoft's configuration, shared by `microsoftAds` and `microsoftConversions` on the server.\n */\nexport interface MicrosoftAdsOptions extends AdsOptions {\n tagId: `${number}`;\n /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */\n customerId?: `${number}`;\n /**\n * The UET consent mode default, `ad_storage: granted` unless given: how the tag behaves\n * without a signal, so Microsoft stops flagging EEA/UK/CH events as missing consent. Sites\n * with a consent banner pass `{ ad_storage: 'denied' }` and send `update` with\n * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\n consent?: UETConsent | false;\n /** The events UET receives, `CONVERSION_EVENTS` by default; names `track` accepts. */\n events?: readonly TrackName[];\n}\n\nexport function microsoftAds(options: MicrosoftAdsOptions): MicrosoftAdsIntegration {\n const consent = options.consent ?? { ad_storage: 'granted' };\n const defaults = consent ? `w[u].push(\"consent\", \"default\", ${JSON.stringify(consent)});` : '';\n return {\n type: 'ads',\n track: adsTracker(sendUETEvent, uetEvents(options)),\n setUser: setUETUser,\n script: {\n id: 'uet-tag',\n inline: `\n (function (w, d, t, u, o) {\n w[u] = w[u] || [], o.ts = (new Date).getTime();\n ${defaults}\n var n = d.createElement(t);\n n.src = \"https://bat.bing.net/bat.js?ti=\" + o.ti + (\"uetq\" != u ? \"&q=\" + u : \"\"),\n n.async = 1, n.onload = n.onreadystatechange = function() {\n var s = this.readyState;\n s && \"loaded\" !== s && \"complete\" !== s ||\n (o.q = w[u], w[u] = new UET(o), w[u].push(\"pageLoad\"),\n n.onload = n.onreadystatechange = null)\n };\n var i = d.getElementsByTagName(t)[0];\n i.parentNode.insertBefore(n, i);\n })(window, document, \"script\", \"uetq\", {\n ti: ${JSON.stringify(options.tagId)},\n enableAutoSpaTracking: true\n });\n `,\n },\n uetCustomerId: options.customerId,\n };\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"microsoft-uet.cjs","names":["isLocalHost","mapUETEvent","getFirst","visitorId","sha256","CONVERSION_EVENTS","adEvents","adsTracker"],"sources":["../../src/third-parties/microsoft-uet.ts"],"sourcesContent":["import type { UpdateVisitorDTO } from '../schema/index';\nimport type { EventName, TrackName, TrackProperties } from '../track/types';\nimport { type UETConsent, type UETQ, mapUETEvent } from '../track/uetq';\nimport { getFirst } from '../utils/field';\nimport { sha256 } from '../utils/sha256';\nimport { visitorId } from '../visitor/id';\nimport {\n type AdsOptions,\n CONVERSION_EVENTS,\n type Integration,\n adEvents,\n adsTracker,\n isLocalHost,\n} from './integration';\n\ndeclare global {\n interface Window {\n /**\n * Defined by the UET snippet before `bat.js` loads (as a plain array), so pushes made early\n * are queued rather than lost. Undefined only where the snippet was never installed.\n */\n uetq?: UETQ;\n }\n}\n\nconst metrics = ['CLS', 'FCP', 'FID', 'INP', 'LCP', 'TTFB'];\n\n/** Drop `undefined` fields: bat.js validates every key it receives, and `undefined` is a value. */\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\nfunction clean(value: unknown): any {\n return JSON.parse(JSON.stringify(value));\n}\n\n/**\n * Forward an internal track event to the Microsoft Advertising UET tag.\n *\n * `eventId` is reused as UET's `event_id` so the browser event deduplicates against the same\n * conversion sent through the Conversions API (`sendMicrosoftEvents`). The action name is the\n * internal name on both channels — see `mapUETEvent`.\n *\n * `page_view` is not forwarded: bat.js turns that action into its page-load beacon, which the\n * snippet already fires on load and, with `enableAutoSpaTracking: true` (the setting in\n * Microsoft's generated snippet), on every history change — forwarding the SDK's own page views\n * would report each page twice. The tag owns page loads; this tracker owns everything else.\n */\nexport function sendUETEvent<T extends EventName>(\n name: TrackName<T>,\n properties?: TrackProperties<T>,\n eventId?: string\n) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return false;\n }\n if (metrics.includes(name) || name === 'page_view') return;\n if (isLocalHost()) return;\n\n const [action, params] = mapUETEvent(name, properties, eventId);\n window.uetq.push('event', action, clean(params));\n}\n\n/**\n * Enhanced conversions: hand the tag the visitor's email and phone so Microsoft can match a\n * conversion to an ad click without a third-party cookie. A `set` applies to every event fired\n * from the page afterwards, `pageLoad` included, and the tag fires a `pid` beacon on its own\n * when the page load already went out. Values are sent raw — the tag normalizes and SHA-256\n * hashes them in the browser (bat.js `validatePid`) before anything leaves the page.\n *\n * A setter itself, like `setGAUser`, rather than a factory like `setFBUser(pixelId)`: UET is\n * bound to its tag by the snippet and `set` addresses whichever tag drains `uetq`, so there is\n * nothing to bind first.\n */\nexport function setUETUser({ user_id, user_data }: UpdateVisitorDTO) {\n if (typeof window === 'undefined' || !window.uetq) {\n console.warn('uetq has not been initialized');\n return;\n }\n\n // A signed-in user is also the moment the ID Sync pixel can carry a `UID` — see `syncUETVisitor`.\n if (user_id) void syncUETVisitor(user_id);\n\n const em = getFirst(user_data?.email);\n const ph = getFirst(user_data?.phone_number);\n if (!em && !ph) return;\n\n window.uetq.push('set', { pid: clean({ em, ph }) });\n}\n\n/**\n * UET consent mode. Push `default` before the tag loads (the tag processes `consent` early, ahead\n * of the queued events) and `update` when the visitor decides. With `ad_storage: 'denied'` the\n * tag neither writes its cookies nor reads the `msclkid` from the URL.\n * https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\nexport function setUETConsent(mode: 'default' | 'update', consent: UETConsent) {\n if (typeof window === 'undefined') return;\n window.uetq ??= [] as unknown as UETQ;\n window.uetq.push('consent', mode, consent);\n}\n\n/**\n * The Conversions API's client-side ID Sync pixel: ties the visitor id sent server-side as\n * `anonymousId` to Microsoft's own identifier, so server events can be attributed across\n * contexts (view-through, audiences). Microsoft requires it for remarketing built from CAPI\n * events and recommends it for measurement quality; fire it at least once per session, ideally\n * on the first page view. A pixel rather than a fetch on purpose: Microsoft must observe the\n * browser context of the sync, which a server-side call cannot carry.\n *\n * `customerId` is the Microsoft Advertising customer id (`cid` in the UI's URLs) — not the UET\n * tag id. `visitorId` is the SDK visitor id (`visitorId()`), which is what\n * `sendMicrosoftEvents` sends as `anonymousId`; Microsoft requires the two to be equal.\n * `userId` is the raw signed-in user id: it is SHA-256 hashed here, exactly as the server sender\n * hashes it into `externalId`, so the pair matches as well. Hashing is asynchronous, so the\n * pixel fires once the digest resolves; where SubtleCrypto is unavailable (an insecure context)\n * the pixel goes out without `UID` rather than with a raw id.\n * https://learn.microsoft.com/en-us/advertising/guides/uet-conversion-api-integration#id-sync-and-why-it-matters\n */\n/**\n * The Microsoft Advertising customer id the ID Sync pixel reports to, set once by the framework\n * `Analytics` component's `uetCustomerId` prop (or `configureUET`). Unset, nothing syncs.\n */\nlet uetCustomerId: string | undefined;\n\nexport function configureUET(options: { customerId?: string | number }) {\n uetCustomerId = options.customerId === undefined ? undefined : String(options.customerId);\n}\n\n/**\n * Sync the SDK visitor — the `anonymousId` of the events the server sends to the Conversions\n * API — with Microsoft, plus the user's `UID` when one is known. The `Analytics` components run\n * it on mount so every visit syncs at least once, anonymous visitors included (they are who\n * remarketing audiences are built from), and `setUETUser` runs it again on sign-in.\n */\nexport async function syncUETVisitor(userId?: string): Promise<void> {\n if (!uetCustomerId) return;\n sendUETIdSync({ customerId: uetCustomerId, visitorId: visitorId(), userId });\n}\n\nexport function sendUETIdSync(options: {\n customerId: string | number;\n visitorId: string;\n /** The signed-in user's id, raw; hashed before it leaves the page. */\n userId?: string;\n}) {\n if (typeof window === 'undefined' || typeof Image === 'undefined') return;\n if (isLocalHost()) return;\n\n const fire = (uid?: string) => {\n const params = new URLSearchParams({\n Red3: `BACID_${options.customerId}`,\n VID: options.visitorId,\n });\n if (uid) params.set('UID', uid);\n new Image().src = `https://c.bing.com/c.gif?${params.toString()}`;\n };\n\n if (!options.userId) {\n fire();\n return;\n }\n sha256(options.userId).then(fire, () => fire());\n}\n\n/** What `microsoftAds` returns: an integration that also names the customer id for ID Sync. */\nexport type MicrosoftAdsIntegration = Integration & { readonly uetCustomerId?: `${number}` };\n\n/** The customer id of the `microsoftAds` integration among these, for `useUETIdSync`. */\nexport function uetCustomerIdOf(integrations: readonly Integration[] = []) {\n return integrations.find(\n (integration): integration is MicrosoftAdsIntegration => 'uetCustomerId' in integration\n )?.uetCustomerId;\n}\n\n/**\n * Microsoft Advertising UET. UET has no standard events to map to — a conversion goal is defined\n * on an action name in the ads UI — so it receives an explicit list, the GA4 conversion events\n * by default (`CONVERSION_EVENTS`), plus `customEvents`.\n *\n * Its script is Microsoft's UET snippet with `enableAutoSpaTracking: true` (the tag reports page\n * loads itself), the consent mode default pushed inside it so bat.js reads it before the first\n * page load.\n */\n/** The events UET receives: `events` (the GA4 conversion events by default) and `customEvents`. */\nexport function uetEvents(options: Pick<MicrosoftAdsOptions, 'events' | 'customEvents'>) {\n const events: readonly string[] = options.events ?? CONVERSION_EVENTS;\n return adEvents((name) => events.includes(name), options.customEvents);\n}\n\n/**\n * Microsoft's configuration, shared by `microsoftAds` and `microsoftConversions` on the server.\n */\nexport interface MicrosoftAdsOptions extends AdsOptions {\n tagId: `${number}`;\n /** Microsoft Advertising customer id (`cid` in the ads UI's URLs): enables the ID Sync pixel. */\n customerId?: `${number}`;\n /**\n * The UET consent mode default, `ad_storage: granted` unless given: how the tag behaves\n * without a signal, so Microsoft stops flagging EEA/UK/CH events as missing consent. Sites\n * with a consent banner pass `{ ad_storage: 'denied' }` and send `update` with\n * `setUETConsent`; `false` pushes no default. https://help.ads.microsoft.com/#apex/ads/en/60119/1\n */\n consent?: UETConsent | false;\n /** The events UET receives, `CONVERSION_EVENTS` by default; names `track` accepts. */\n events?: readonly TrackName[];\n}\n\nexport function microsoftAds(options: MicrosoftAdsOptions): MicrosoftAdsIntegration {\n const consent = options.consent ?? { ad_storage: 'granted' };\n const defaults = consent ? `w[u].push(\"consent\", \"default\", ${JSON.stringify(consent)});` : '';\n return {\n type: 'ads',\n track: adsTracker(sendUETEvent, uetEvents(options)),\n setUser: setUETUser,\n script: {\n id: 'uet-tag',\n inline: `\n (function (w, d, t, u, o) {\n w[u] = w[u] || [], o.ts = (new Date).getTime();\n ${defaults}\n var n = d.createElement(t);\n n.src = \"https://bat.bing.net/bat.js?ti=\" + o.ti + (\"uetq\" != u ? \"&q=\" + u : \"\"),\n n.async = 1, n.onload = n.onreadystatechange = function() {\n var s = this.readyState;\n s && \"loaded\" !== s && \"complete\" !== s ||\n (o.q = w[u], w[u] = new UET(o), w[u].push(\"pageLoad\"),\n n.onload = n.onreadystatechange = null)\n };\n var i = d.getElementsByTagName(t)[0];\n i.parentNode.insertBefore(n, i);\n })(window, document, \"script\", \"uetq\", {\n ti: ${JSON.stringify(options.tagId)},\n enableAutoSpaTracking: true\n });\n `,\n },\n uetCustomerId: options.customerId,\n };\n}\n"],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
2
1
|
import { UpdateVisitorDTO } from "../schema/index.cjs";
|
|
3
|
-
import {
|
|
2
|
+
import { EventName, TrackName, TrackProperties } from "../track/types.cjs";
|
|
4
3
|
import { UETConsent, UETQ } from "../track/uetq.cjs";
|
|
4
|
+
import { AdsOptions, Integration } from "./integration.cjs";
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
2
1
|
import { UpdateVisitorDTO } from "../schema/index.mjs";
|
|
3
|
-
import {
|
|
2
|
+
import { EventName, TrackName, TrackProperties } from "../track/types.mjs";
|
|
4
3
|
import { UETConsent, UETQ } from "../track/uetq.mjs";
|
|
4
|
+
import { AdsOptions, Integration } from "./integration.mjs";
|
|
5
5
|
declare global {
|
|
6
6
|
interface Window {
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { visitorId } from "../visitor/id.mjs";
|
|
2
1
|
import { mapUETEvent } from "../track/uetq.mjs";
|
|
3
2
|
import { getFirst } from "../utils/field.mjs";
|
|
4
3
|
import { sha256 } from "../utils/sha256.mjs";
|
|
4
|
+
import { visitorId } from "../visitor/id.mjs";
|
|
5
5
|
import { CONVERSION_EVENTS, adEvents, adsTracker, isLocalHost } from "./integration.mjs";
|
|
6
6
|
// src/third-parties/microsoft-uet.ts
|
|
7
7
|
const metrics = [
|