@shware/analytics 16.4.0 → 16.5.1
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 +10 -4
- 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/server/setup-conversions.cjs +1 -1
- package/dist/server/setup-conversions.cjs.map +1 -1
- package/dist/server/setup-conversions.d.cts +19 -3
- package/dist/server/setup-conversions.d.cts.map +1 -1
- package/dist/server/setup-conversions.d.mts +19 -3
- package/dist/server/setup-conversions.d.mts.map +1 -1
- package/dist/server/setup-conversions.mjs +1 -1
- package/dist/server/setup-conversions.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -315,7 +315,7 @@ export const conversions = setupConversions({
|
|
|
315
315
|
],
|
|
316
316
|
// Only for conversions.track(), which is returned only with it; forward needs none of it.
|
|
317
317
|
track: {
|
|
318
|
-
resolveUser: async (userId) => latestSessionOf(userId),
|
|
318
|
+
resolveUser: async (userId, event) => latestSessionOf(userId, event.platform),
|
|
319
319
|
store: async (event) => (await insertEvents([event])).length > 0,
|
|
320
320
|
},
|
|
321
321
|
});
|
|
@@ -331,13 +331,17 @@ ctx.waitUntil(
|
|
|
331
331
|
userId,
|
|
332
332
|
properties: { transaction_id: invoice.id, value: 9.99, currency: 'usd', items: [] },
|
|
333
333
|
createdAt: new Date(invoice.created * 1000).toISOString(),
|
|
334
|
+
platform: 'web', // a Stripe payment; optional, read by resolveUser
|
|
335
|
+
environment: invoice.livemode ? 'production' : 'development',
|
|
334
336
|
})
|
|
335
337
|
);
|
|
336
338
|
```
|
|
337
339
|
|
|
338
340
|
- `forward(events, data)`: the events a client sent, as stored, to every destination at once.
|
|
339
341
|
- `track(event)`: an event the server reports on its own — a webhook's purchase, renewal or
|
|
340
|
-
refund — with `id` the transaction id
|
|
342
|
+
refund — with `id` the transaction id, and optionally the `platform` and `environment` the server
|
|
343
|
+
knows from the payment itself, for `resolveUser` to read. `track.resolveUser(userId, event)`
|
|
344
|
+
returns what a client event
|
|
341
345
|
would have carried, from the host's records: the user's latest session's `tags` (cookies, page,
|
|
342
346
|
user agent) with the click ids of the touch the conversion is credited to, that session's
|
|
343
347
|
`visitor_id`, `session_id`, `platform` (which decides website or app) and `environment`, and the
|
|
@@ -345,8 +349,10 @@ ctx.waitUntil(
|
|
|
345
349
|
server's conversions count wherever the client's do — and says whether it was new: only a new
|
|
346
350
|
one is sent, so a webhook delivered again is not reported twice. That matters: the platforms
|
|
347
351
|
document deduplicating a server event against a browser one, and only Microsoft (on `eventId`)
|
|
348
|
-
and Google Ads (on `transaction_id`) a server event sent twice.
|
|
349
|
-
|
|
352
|
+
and Google Ads (on `transaction_id`) a server event sent twice. `resolveUser` answering
|
|
353
|
+
`undefined` skips the event; a user with no session at all (their browser blocked the analytics
|
|
354
|
+
requests) can instead be answered with empty `tags`, ids of the host's own and `data` from the
|
|
355
|
+
account, since the platforms also match on a hashed email.
|
|
350
356
|
|
|
351
357
|
Neither throws, so reporting a conversion cannot fail the request it runs in — least of all a
|
|
352
358
|
payment webhook, which its provider would deliver again and again. A failure is logged with the
|
package/dist/link/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["fetch","config"],"sources":["../../src/link/index.ts"],"sourcesContent":["import { fetch } from '@shware/utils';\nimport type { CreateLinkDTO } from '../schema/index';\nimport { config } from '../setup/index';\n\nexport interface Link
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["fetch","config"],"sources":["../../src/link/index.ts"],"sourcesContent":["import { fetch } from '@shware/utils';\nimport type { CreateLinkDTO } from '../schema/index';\nimport { config } from '../setup/index';\n\n/** A stored link as the server answers it: a tag the link was created without comes back `null`. */\nexport interface Link {\n id: string;\n created_at: string;\n url: string;\n utm_source: string;\n utm_medium: string;\n utm_campaign: string;\n utm_id?: string | null;\n utm_term?: string | null;\n utm_content?: string | null;\n utm_source_platform?: string | null;\n utm_creative_format?: string | null;\n utm_marketing_tactic?: string | null;\n}\n\nexport async function createLink(dto: CreateLinkDTO) {\n const response = await fetch(`${config.endpoint}/links`, {\n method: 'POST',\n credentials: 'include',\n headers: await config.getHeaders(),\n body: JSON.stringify(dto),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create link: ${response.status} ${await response.text()}`);\n }\n return response.json() as Promise<Link>;\n}\n\n/**\n * The link a `?s=` id names. `null` when the server says there is none (a 4xx: a mistyped or\n * expired id, or a `?s=` that was never a link id): that answer will not change while the page is\n * open, so callers cache it. A 5xx or a network failure, once the retrying `fetch` gives up, is\n * thrown instead — the link may well exist, so a caller should look it up again later rather than\n * remember \"no link\".\n */\nexport async function getLink(id: string): Promise<Link | null> {\n const response = await fetch(`${config.endpoint}/links/${id}`, {\n method: 'GET',\n credentials: 'include',\n headers: await config.getHeaders(),\n });\n if (response.ok) return (await response.json()) as Link;\n const detail = `${response.status} ${await response.text()}`;\n if (response.status >= 400 && response.status < 500) {\n console.error(`No link(${id}): ${detail}`);\n return null;\n }\n throw new Error(`Failed to get link(${id}): ${detail}`);\n}\n"],"mappings":";;;;AAoBA,eAAsB,WAAW,KAAoB;CACnD,MAAM,WAAW,OAAA,GAAMA,cAAAA,MAAAA,CAAM,GAAGC,oBAAAA,OAAO,SAAS,SAAS;EACvD,QAAQ;EACR,aAAa;EACb,SAAS,MAAMA,oBAAAA,OAAO,WAAW;EACjC,MAAM,KAAK,UAAU,GAAG;CAC1B,CAAC;CAED,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,0BAA0B,SAAS,OAAO,GAAG,MAAM,SAAS,KAAK,GAAG;CAEtF,OAAO,SAAS,KAAK;AACvB;;;;;;;;AASA,eAAsB,QAAQ,IAAkC;CAC9D,MAAM,WAAW,OAAA,GAAMD,cAAAA,MAAAA,CAAM,GAAGC,oBAAAA,OAAO,SAAS,SAAS,MAAM;EAC7D,QAAQ;EACR,aAAa;EACb,SAAS,MAAMA,oBAAAA,OAAO,WAAW;CACnC,CAAC;CACD,IAAI,SAAS,IAAI,OAAQ,MAAM,SAAS,KAAK;CAC7C,MAAM,SAAS,GAAG,SAAS,OAAO,GAAG,MAAM,SAAS,KAAK;CACzD,IAAI,SAAS,UAAU,OAAO,SAAS,SAAS,KAAK;EACnD,QAAQ,MAAM,WAAW,GAAG,KAAK,QAAQ;EACzC,OAAO;CACT;CACA,MAAM,IAAI,MAAM,sBAAsB,GAAG,KAAK,QAAQ;AACxD"}
|
package/dist/link/index.d.cts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { CreateLinkDTO } from "../schema/index.cjs";
|
|
2
|
-
|
|
2
|
+
/** A stored link as the server answers it: a tag the link was created without comes back `null`. */
|
|
3
|
+
export interface Link {
|
|
3
4
|
id: string;
|
|
4
5
|
created_at: string;
|
|
6
|
+
url: string;
|
|
7
|
+
utm_source: string;
|
|
8
|
+
utm_medium: string;
|
|
9
|
+
utm_campaign: string;
|
|
10
|
+
utm_id?: string | null;
|
|
11
|
+
utm_term?: string | null;
|
|
12
|
+
utm_content?: string | null;
|
|
13
|
+
utm_source_platform?: string | null;
|
|
14
|
+
utm_creative_format?: string | null;
|
|
15
|
+
utm_marketing_tactic?: string | null;
|
|
5
16
|
}
|
|
6
17
|
export declare function createLink(dto: CreateLinkDTO): Promise<Link>;
|
|
7
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/link/index.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/link/index.ts"],"mappings":";;iBAKiB;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;wBAGoB,WAAW,KAAK,gBAAa,QAAA;;;;;;;;wBAqB7B,QAAQ,aAAa,QAAQ"}
|
package/dist/link/index.d.mts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { CreateLinkDTO } from "../schema/index.mjs";
|
|
2
|
-
|
|
2
|
+
/** A stored link as the server answers it: a tag the link was created without comes back `null`. */
|
|
3
|
+
export interface Link {
|
|
3
4
|
id: string;
|
|
4
5
|
created_at: string;
|
|
6
|
+
url: string;
|
|
7
|
+
utm_source: string;
|
|
8
|
+
utm_medium: string;
|
|
9
|
+
utm_campaign: string;
|
|
10
|
+
utm_id?: string | null;
|
|
11
|
+
utm_term?: string | null;
|
|
12
|
+
utm_content?: string | null;
|
|
13
|
+
utm_source_platform?: string | null;
|
|
14
|
+
utm_creative_format?: string | null;
|
|
15
|
+
utm_marketing_tactic?: string | null;
|
|
5
16
|
}
|
|
6
17
|
export declare function createLink(dto: CreateLinkDTO): Promise<Link>;
|
|
7
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/link/index.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/link/index.ts"],"mappings":";;iBAKiB;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;wBAGoB,WAAW,KAAK,gBAAa,QAAA;;;;;;;;wBAqB7B,QAAQ,aAAa,QAAQ"}
|
package/dist/link/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/link/index.ts"],"sourcesContent":["import { fetch } from '@shware/utils';\nimport type { CreateLinkDTO } from '../schema/index';\nimport { config } from '../setup/index';\n\nexport interface Link
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/link/index.ts"],"sourcesContent":["import { fetch } from '@shware/utils';\nimport type { CreateLinkDTO } from '../schema/index';\nimport { config } from '../setup/index';\n\n/** A stored link as the server answers it: a tag the link was created without comes back `null`. */\nexport interface Link {\n id: string;\n created_at: string;\n url: string;\n utm_source: string;\n utm_medium: string;\n utm_campaign: string;\n utm_id?: string | null;\n utm_term?: string | null;\n utm_content?: string | null;\n utm_source_platform?: string | null;\n utm_creative_format?: string | null;\n utm_marketing_tactic?: string | null;\n}\n\nexport async function createLink(dto: CreateLinkDTO) {\n const response = await fetch(`${config.endpoint}/links`, {\n method: 'POST',\n credentials: 'include',\n headers: await config.getHeaders(),\n body: JSON.stringify(dto),\n });\n\n if (!response.ok) {\n throw new Error(`Failed to create link: ${response.status} ${await response.text()}`);\n }\n return response.json() as Promise<Link>;\n}\n\n/**\n * The link a `?s=` id names. `null` when the server says there is none (a 4xx: a mistyped or\n * expired id, or a `?s=` that was never a link id): that answer will not change while the page is\n * open, so callers cache it. A 5xx or a network failure, once the retrying `fetch` gives up, is\n * thrown instead — the link may well exist, so a caller should look it up again later rather than\n * remember \"no link\".\n */\nexport async function getLink(id: string): Promise<Link | null> {\n const response = await fetch(`${config.endpoint}/links/${id}`, {\n method: 'GET',\n credentials: 'include',\n headers: await config.getHeaders(),\n });\n if (response.ok) return (await response.json()) as Link;\n const detail = `${response.status} ${await response.text()}`;\n if (response.status >= 400 && response.status < 500) {\n console.error(`No link(${id}): ${detail}`);\n return null;\n }\n throw new Error(`Failed to get link(${id}): ${detail}`);\n}\n"],"mappings":";;;AAoBA,eAAsB,WAAW,KAAoB;CACnD,MAAM,WAAW,MAAM,MAAM,GAAG,OAAO,SAAS,SAAS;EACvD,QAAQ;EACR,aAAa;EACb,SAAS,MAAM,OAAO,WAAW;EACjC,MAAM,KAAK,UAAU,GAAG;CAC1B,CAAC;CAED,IAAI,CAAC,SAAS,IACZ,MAAM,IAAI,MAAM,0BAA0B,SAAS,OAAO,GAAG,MAAM,SAAS,KAAK,GAAG;CAEtF,OAAO,SAAS,KAAK;AACvB;;;;;;;;AASA,eAAsB,QAAQ,IAAkC;CAC9D,MAAM,WAAW,MAAM,MAAM,GAAG,OAAO,SAAS,SAAS,MAAM;EAC7D,QAAQ;EACR,aAAa;EACb,SAAS,MAAM,OAAO,WAAW;CACnC,CAAC;CACD,IAAI,SAAS,IAAI,OAAQ,MAAM,SAAS,KAAK;CAC7C,MAAM,SAAS,GAAG,SAAS,OAAO,GAAG,MAAM,SAAS,KAAK;CACzD,IAAI,SAAS,UAAU,OAAO,SAAS,SAAS,KAAK;EACnD,QAAQ,MAAM,WAAW,GAAG,KAAK,QAAQ;EACzC,OAAO;CACT;CACA,MAAM,IAAI,MAAM,sBAAsB,GAAG,KAAK,QAAQ;AACxD"}
|
|
@@ -26,7 +26,7 @@ function setupConversions(options) {
|
|
|
26
26
|
*/
|
|
27
27
|
async function track({ resolveUser, store }, input) {
|
|
28
28
|
try {
|
|
29
|
-
const user = await resolveUser(input.userId);
|
|
29
|
+
const user = await resolveUser(input.userId, input);
|
|
30
30
|
if (!user) {
|
|
31
31
|
console.warn(`Conversion not reported, event: ${input.id}: no session for ${input.userId}`);
|
|
32
32
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-conversions.cjs","names":[],"sources":["../../src/server/setup-conversions.ts"],"sourcesContent":["import type {\n Environment,\n EventName,\n Platform,\n TrackEvent,\n TrackName,\n TrackProperties,\n TrackTags,\n UserProvidedData,\n} from '../track/types';\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyTrackEvent = TrackEvent<any>;\n\n/**\n * Where `setupConversions` sends events: an ad platform's conversions API, from its factory\n * (`metaConversions`, … next to each sender), or anything else the host forwards events to (a\n * CRM, its own workflows).\n *\n * `send` rejects when it fails, as the SDK's senders do: `setupConversions` logs the failure,\n * with the events' ids, and still sends to the others.\n */\nexport interface ConversionDestination {\n readonly send: (events: AnyTrackEvent[], data: UserProvidedData) => Promise<unknown>;\n}\n\n/**\n * A destination that sends only the events `accepts` lets through, and makes no request when none\n * is left: what each conversions API's factory (`metaConversions`, …) is built on.\n */\nexport function conversionDestination(\n accepts: (name: string) => boolean,\n send: (events: AnyTrackEvent[], data: UserProvidedData) => Promise<unknown>\n): ConversionDestination {\n return {\n send: async (events, data) => {\n const accepted = events.filter((event) => accepts(event.name));\n if (accepted.length > 0) await send(accepted, data);\n },\n };\n}\n\n/**\n * Who a server-only event is from, as the host knows them: what the ad platforms match a client\n * event on, read from the host's own records.\n *\n * - `tags`: the user's latest session's tags (their cookies — `_fbp`, `_rdt_uuid`, … — page\n * and user agent), with the click ids of the touch the conversion is attributed to over them.\n * - `visitor_id`, `session_id`, `platform`, `environment`: from that session. `platform` decides\n * each platform's action source (website or app), as for a client event.\n * - `data`: the user's identity (`email`, `user_id`, …), hashed by each sender.\n */\nexport interface ConversionUser {\n tags: TrackTags;\n visitor_id: string;\n session_id: string;\n platform: Platform;\n environment: Environment;\n data: UserProvidedData;\n}\n\n/**\n * An event the server reports on its own, with no client behind it: a webhook's purchase,\n * renewal or refund. `id` is the transaction id: `track.store` keeps a redelivered webhook from\n * being reported twice, and the platforms pair it with a browser event under the same id.\n */\nexport interface ServerEvent<T extends EventName = EventName> {\n id: string;\n name: TrackName<T>;\n /** The user it belongs to, handed to `track.resolveUser`. */\n userId: string;\n properties?: TrackProperties<T>;\n /** When it happened, as an ISO 8601 string. */\n createdAt: string;\n}\n\nexport interface ConversionsOptions {\n destinations: readonly ConversionDestination[];\n /**\n * How `track` completes and stores a server-only event. Without it `setupConversions` returns\n * only `forward`, for a host that only forwards client events.\n */\n track?: {\n /**\n * The user behind the event, read from the host's records (see `ConversionUser`)
|
|
1
|
+
{"version":3,"file":"setup-conversions.cjs","names":[],"sources":["../../src/server/setup-conversions.ts"],"sourcesContent":["import type {\n Environment,\n EventName,\n Platform,\n TrackEvent,\n TrackName,\n TrackProperties,\n TrackTags,\n UserProvidedData,\n} from '../track/types';\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyTrackEvent = TrackEvent<any>;\n\n/**\n * Where `setupConversions` sends events: an ad platform's conversions API, from its factory\n * (`metaConversions`, … next to each sender), or anything else the host forwards events to (a\n * CRM, its own workflows).\n *\n * `send` rejects when it fails, as the SDK's senders do: `setupConversions` logs the failure,\n * with the events' ids, and still sends to the others.\n */\nexport interface ConversionDestination {\n readonly send: (events: AnyTrackEvent[], data: UserProvidedData) => Promise<unknown>;\n}\n\n/**\n * A destination that sends only the events `accepts` lets through, and makes no request when none\n * is left: what each conversions API's factory (`metaConversions`, …) is built on.\n */\nexport function conversionDestination(\n accepts: (name: string) => boolean,\n send: (events: AnyTrackEvent[], data: UserProvidedData) => Promise<unknown>\n): ConversionDestination {\n return {\n send: async (events, data) => {\n const accepted = events.filter((event) => accepts(event.name));\n if (accepted.length > 0) await send(accepted, data);\n },\n };\n}\n\n/**\n * Who a server-only event is from, as the host knows them: what the ad platforms match a client\n * event on, read from the host's own records.\n *\n * - `tags`: the user's latest session's tags (their cookies — `_fbp`, `_rdt_uuid`, … — page\n * and user agent), with the click ids of the touch the conversion is attributed to over them.\n * - `visitor_id`, `session_id`, `platform`, `environment`: from that session. `platform` decides\n * each platform's action source (website or app), as for a client event.\n * - `data`: the user's identity (`email`, `user_id`, …), hashed by each sender.\n */\nexport interface ConversionUser {\n tags: TrackTags;\n visitor_id: string;\n session_id: string;\n platform: Platform;\n environment: Environment;\n data: UserProvidedData;\n}\n\n/**\n * An event the server reports on its own, with no client behind it: a webhook's purchase,\n * renewal or refund. `id` is the transaction id: `track.store` keeps a redelivered webhook from\n * being reported twice, and the platforms pair it with a browser event under the same id.\n */\nexport interface ServerEvent<T extends EventName = EventName> {\n id: string;\n name: TrackName<T>;\n /** The user it belongs to, handed to `track.resolveUser`. */\n userId: string;\n properties?: TrackProperties<T>;\n /** When it happened, as an ISO 8601 string. */\n createdAt: string;\n /**\n * Where it happened, when the server knows better than any session: a Stripe payment is `web`,\n * an App Store one `ios`. Read by `resolveUser`, which answers the event's `platform` (it\n * decides each platform's action source): a session of this platform when the user has one,\n * or something else for a user with no session at all, such as `unknown` when there is no user\n * agent to send with a website event.\n */\n platform?: Platform;\n /**\n * Whether it was real, when the server knows: a store's sandbox purchase is `development` even\n * in a production deployment. Read by `resolveUser`, which answers the event's `environment`.\n */\n environment?: Environment;\n}\n\nexport interface ConversionsOptions {\n destinations: readonly ConversionDestination[];\n /**\n * How `track` completes and stores a server-only event. Without it `setupConversions` returns\n * only `forward`, for a host that only forwards client events.\n */\n track?: {\n /**\n * The user behind the event, read from the host's records (see `ConversionUser`), given the\n * event so a session of its `platform` can be preferred and its `platform` / `environment`\n * answered; what it returns is what the event is sent with. `undefined` drops the event. A user\n * with no session at all can still be matched by the platforms on `data` alone (a hashed\n * email), so a host may answer with empty `tags` and ids of its own rather than drop it.\n */\n resolveUser: (userId: string, event: ServerEvent) => Promise<ConversionUser | undefined>;\n /**\n * Stores the event, e.g. in the events table, returning whether it was new: `track` sends\n * only an event it stored, so a webhook delivered again (its handler failed on something\n * else) is not reported twice — not every platform deduplicates a server event sent twice.\n */\n store: (event: AnyTrackEvent) => Promise<boolean>;\n };\n}\n\n/**\n * The server's counterpart of `setupAnalytics({ integrations })`: every destination configured\n * once, with the same per-platform options as the browser integrations, so the conversions API\n * and the tag report the same events.\n *\n * - `forward(events, data)`: the events a client sent, as stored, on to every destination.\n * - `track(event)`: an event the server reports on its own (a webhook's), completed by\n * `track.resolveUser`, stored with `track.store`, then forwarded.\n *\n * Neither throws, so reporting a conversion can never fail the request it runs in — a payment\n * webhook least of all, which its provider would then deliver again and again. A failure is\n * logged with the ids of the events it lost, for them to be found and sent later: a missed\n * conversion costs less than a duplicate one, or a webhook that keeps failing.\n */\nexport function setupConversions(\n options: ConversionsOptions & { track: NonNullable<ConversionsOptions['track']> }\n): {\n forward: Forward;\n track: Track;\n};\nexport function setupConversions(options: ConversionsOptions): { forward: Forward };\nexport function setupConversions(options: ConversionsOptions) {\n const { destinations, track: trackOptions } = options;\n\n async function forward(events: AnyTrackEvent[], data: UserProvidedData = {}) {\n if (events.length === 0) return;\n // Called inside a promise: a `send` that throws synchronously rejects there instead of\n // stopping the destinations after it.\n const settled = await Promise.allSettled(\n destinations.map((d) => Promise.resolve().then(() => d.send(events, data)))\n );\n const ids = events.map((event) => event.id).join(', ');\n settled.forEach((outcome) => {\n if (outcome.status === 'rejected') {\n console.error(`Conversions not sent, events: ${ids}`, outcome.reason);\n }\n });\n }\n\n /**\n * Reports a server-only event; resolves with it as sent, or `undefined` when it was not: a\n * user with no session, an event `store` had already stored, or a failure, which is logged.\n */\n async function track<T extends EventName>(\n { resolveUser, store }: NonNullable<ConversionsOptions['track']>,\n input: ServerEvent<T>\n ): Promise<TrackEvent<T> | undefined> {\n try {\n const user = await resolveUser(input.userId, input);\n if (!user) {\n console.warn(`Conversion not reported, event: ${input.id}: no session for ${input.userId}`);\n return undefined;\n }\n const event: TrackEvent<T> = {\n id: input.id,\n name: input.name,\n properties: input.properties,\n tags: user.tags,\n visitor_id: user.visitor_id,\n session_id: user.session_id,\n platform: user.platform,\n environment: user.environment,\n created_at: input.createdAt,\n };\n if (!(await store(event))) return undefined;\n await forward([event], user.data);\n return event;\n } catch (e: unknown) {\n console.error(`Conversion not reported, event: ${input.id}`, e);\n return undefined;\n }\n }\n\n if (!trackOptions) return { forward };\n return { forward, track: (input: ServerEvent) => track(trackOptions, input) };\n}\n\ntype Forward = (events: AnyTrackEvent[], data?: UserProvidedData) => Promise<void>;\ntype Track = <T extends EventName>(input: ServerEvent<T>) => Promise<TrackEvent<T> | undefined>;\n"],"mappings":";;;;;;AA8BA,SAAgB,sBACd,SACA,MACuB;CACvB,OAAO,EACL,MAAM,OAAO,QAAQ,SAAS;EAC5B,MAAM,WAAW,OAAO,QAAQ,UAAU,QAAQ,MAAM,IAAI,CAAC;EAC7D,IAAI,SAAS,SAAS,GAAG,MAAM,KAAK,UAAU,IAAI;CACpD,EACF;AACF;AA8FA,SAAgB,iBAAiB,SAA6B;CAC5D,MAAM,EAAE,cAAc,OAAO,iBAAiB;CAE9C,eAAe,QAAQ,QAAyB,OAAyB,CAAC,GAAG;EAC3E,IAAI,OAAO,WAAW,GAAG;EAGzB,MAAM,UAAU,MAAM,QAAQ,WAC5B,aAAa,KAAK,MAAM,QAAQ,QAAQ,CAAC,CAAC,WAAW,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,CAC5E;EACA,MAAM,MAAM,OAAO,KAAK,UAAU,MAAM,EAAE,CAAC,CAAC,KAAK,IAAI;EACrD,QAAQ,SAAS,YAAY;GAC3B,IAAI,QAAQ,WAAW,YACrB,QAAQ,MAAM,iCAAiC,OAAO,QAAQ,MAAM;EAExE,CAAC;CACH;;;;;CAMA,eAAe,MACb,EAAE,aAAa,SACf,OACoC;EACpC,IAAI;GACF,MAAM,OAAO,MAAM,YAAY,MAAM,QAAQ,KAAK;GAClD,IAAI,CAAC,MAAM;IACT,QAAQ,KAAK,mCAAmC,MAAM,GAAG,mBAAmB,MAAM,QAAQ;IAC1F;GACF;GACA,MAAM,QAAuB;IAC3B,IAAI,MAAM;IACV,MAAM,MAAM;IACZ,YAAY,MAAM;IAClB,MAAM,KAAK;IACX,YAAY,KAAK;IACjB,YAAY,KAAK;IACjB,UAAU,KAAK;IACf,aAAa,KAAK;IAClB,YAAY,MAAM;GACpB;GACA,IAAI,CAAE,MAAM,MAAM,KAAK,GAAI,OAAO,KAAA;GAClC,MAAM,QAAQ,CAAC,KAAK,GAAG,KAAK,IAAI;GAChC,OAAO;EACT,SAAS,GAAY;GACnB,QAAQ,MAAM,mCAAmC,MAAM,MAAM,CAAC;GAC9D;EACF;CACF;CAEA,IAAI,CAAC,cAAc,OAAO,EAAE,QAAQ;CACpC,OAAO;EAAE;EAAS,QAAQ,UAAuB,MAAM,cAAc,KAAK;CAAE;AAC9E"}
|
|
@@ -47,6 +47,19 @@ export interface ServerEvent<T extends EventName = EventName> {
|
|
|
47
47
|
properties?: TrackProperties<T>;
|
|
48
48
|
/** When it happened, as an ISO 8601 string. */
|
|
49
49
|
createdAt: string;
|
|
50
|
+
/**
|
|
51
|
+
* Where it happened, when the server knows better than any session: a Stripe payment is `web`,
|
|
52
|
+
* an App Store one `ios`. Read by `resolveUser`, which answers the event's `platform` (it
|
|
53
|
+
* decides each platform's action source): a session of this platform when the user has one,
|
|
54
|
+
* or something else for a user with no session at all, such as `unknown` when there is no user
|
|
55
|
+
* agent to send with a website event.
|
|
56
|
+
*/
|
|
57
|
+
platform?: Platform;
|
|
58
|
+
/**
|
|
59
|
+
* Whether it was real, when the server knows: a store's sandbox purchase is `development` even
|
|
60
|
+
* in a production deployment. Read by `resolveUser`, which answers the event's `environment`.
|
|
61
|
+
*/
|
|
62
|
+
environment?: Environment;
|
|
50
63
|
}
|
|
51
64
|
export interface ConversionsOptions {
|
|
52
65
|
destinations: readonly ConversionDestination[];
|
|
@@ -56,10 +69,13 @@ export interface ConversionsOptions {
|
|
|
56
69
|
*/
|
|
57
70
|
track?: {
|
|
58
71
|
/**
|
|
59
|
-
* The user behind the event, read from the host's records (see `ConversionUser`)
|
|
60
|
-
*
|
|
72
|
+
* The user behind the event, read from the host's records (see `ConversionUser`), given the
|
|
73
|
+
* event so a session of its `platform` can be preferred and its `platform` / `environment`
|
|
74
|
+
* answered; what it returns is what the event is sent with. `undefined` drops the event. A user
|
|
75
|
+
* with no session at all can still be matched by the platforms on `data` alone (a hashed
|
|
76
|
+
* email), so a host may answer with empty `tags` and ids of its own rather than drop it.
|
|
61
77
|
*/
|
|
62
|
-
resolveUser: (userId: string) => Promise<ConversionUser | undefined>;
|
|
78
|
+
resolveUser: (userId: string, event: ServerEvent) => Promise<ConversionUser | undefined>;
|
|
63
79
|
/**
|
|
64
80
|
* Stores the event, e.g. in the events table, returning whether it was new: `track` sends
|
|
65
81
|
* only an event it stored, so a webhook delivered again (its handler failed on something
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-conversions.d.cts","names":[],"sources":["../../src/server/setup-conversions.ts"],"mappings":";KAYK,gBAAgB;;;;;;;;;iBAUJ;WACN,OAAO,QAAQ,iBAAiB,MAAM,qBAAqB;;;;;;wBAOtD,sBACd,UAAU,0BACV,OAAO,QAAQ,iBAAiB,MAAM,qBAAqB,mBAC1D;;;;;;;;;;;iBAmBc;EACf,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,MAAM;;;;;;;iBAQS,YAAY,UAAU,YAAY;EACjD;EACA,MAAM,UAAU;;EAEhB;EACA,aAAa,gBAAgB;;EAE7B;;
|
|
1
|
+
{"version":3,"file":"setup-conversions.d.cts","names":[],"sources":["../../src/server/setup-conversions.ts"],"mappings":";KAYK,gBAAgB;;;;;;;;;iBAUJ;WACN,OAAO,QAAQ,iBAAiB,MAAM,qBAAqB;;;;;;wBAOtD,sBACd,UAAU,0BACV,OAAO,QAAQ,iBAAiB,MAAM,qBAAqB,mBAC1D;;;;;;;;;;;iBAmBc;EACf,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,MAAM;;;;;;;iBAQS,YAAY,UAAU,YAAY;EACjD;EACA,MAAM,UAAU;;EAEhB;EACA,aAAa,gBAAgB;;EAE7B;;;;;;;;EAQA,WAAW;;;;;EAKX,cAAc;;iBAGC;EACf,uBAAuB;;;;;EAKvB;;;;;;;;IAQE,cAAc,gBAAgB,OAAO,gBAAgB,QAAQ;;;;;;IAM7D,QAAQ,OAAO,kBAAkB;;;;;;;;;;;;;;;;;wBAkBrB,iBACd,SAAS;EAAuB,OAAO,YAAY;;EAEnD,SAAS;EACT,OAAO;;wBAEO,iBAAiB,SAAS;EAAuB,SAAS;;KAyDrE,WAAW,QAAQ,iBAAiB,OAAO,qBAAqB;KAChE,SAAS,UAAU,WAAW,OAAO,YAAY,OAAO,QAAQ,WAAW"}
|
|
@@ -47,6 +47,19 @@ export interface ServerEvent<T extends EventName = EventName> {
|
|
|
47
47
|
properties?: TrackProperties<T>;
|
|
48
48
|
/** When it happened, as an ISO 8601 string. */
|
|
49
49
|
createdAt: string;
|
|
50
|
+
/**
|
|
51
|
+
* Where it happened, when the server knows better than any session: a Stripe payment is `web`,
|
|
52
|
+
* an App Store one `ios`. Read by `resolveUser`, which answers the event's `platform` (it
|
|
53
|
+
* decides each platform's action source): a session of this platform when the user has one,
|
|
54
|
+
* or something else for a user with no session at all, such as `unknown` when there is no user
|
|
55
|
+
* agent to send with a website event.
|
|
56
|
+
*/
|
|
57
|
+
platform?: Platform;
|
|
58
|
+
/**
|
|
59
|
+
* Whether it was real, when the server knows: a store's sandbox purchase is `development` even
|
|
60
|
+
* in a production deployment. Read by `resolveUser`, which answers the event's `environment`.
|
|
61
|
+
*/
|
|
62
|
+
environment?: Environment;
|
|
50
63
|
}
|
|
51
64
|
export interface ConversionsOptions {
|
|
52
65
|
destinations: readonly ConversionDestination[];
|
|
@@ -56,10 +69,13 @@ export interface ConversionsOptions {
|
|
|
56
69
|
*/
|
|
57
70
|
track?: {
|
|
58
71
|
/**
|
|
59
|
-
* The user behind the event, read from the host's records (see `ConversionUser`)
|
|
60
|
-
*
|
|
72
|
+
* The user behind the event, read from the host's records (see `ConversionUser`), given the
|
|
73
|
+
* event so a session of its `platform` can be preferred and its `platform` / `environment`
|
|
74
|
+
* answered; what it returns is what the event is sent with. `undefined` drops the event. A user
|
|
75
|
+
* with no session at all can still be matched by the platforms on `data` alone (a hashed
|
|
76
|
+
* email), so a host may answer with empty `tags` and ids of its own rather than drop it.
|
|
61
77
|
*/
|
|
62
|
-
resolveUser: (userId: string) => Promise<ConversionUser | undefined>;
|
|
78
|
+
resolveUser: (userId: string, event: ServerEvent) => Promise<ConversionUser | undefined>;
|
|
63
79
|
/**
|
|
64
80
|
* Stores the event, e.g. in the events table, returning whether it was new: `track` sends
|
|
65
81
|
* only an event it stored, so a webhook delivered again (its handler failed on something
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-conversions.d.mts","names":[],"sources":["../../src/server/setup-conversions.ts"],"mappings":";KAYK,gBAAgB;;;;;;;;;iBAUJ;WACN,OAAO,QAAQ,iBAAiB,MAAM,qBAAqB;;;;;;wBAOtD,sBACd,UAAU,0BACV,OAAO,QAAQ,iBAAiB,MAAM,qBAAqB,mBAC1D;;;;;;;;;;;iBAmBc;EACf,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,MAAM;;;;;;;iBAQS,YAAY,UAAU,YAAY;EACjD;EACA,MAAM,UAAU;;EAEhB;EACA,aAAa,gBAAgB;;EAE7B;;
|
|
1
|
+
{"version":3,"file":"setup-conversions.d.mts","names":[],"sources":["../../src/server/setup-conversions.ts"],"mappings":";KAYK,gBAAgB;;;;;;;;;iBAUJ;WACN,OAAO,QAAQ,iBAAiB,MAAM,qBAAqB;;;;;;wBAOtD,sBACd,UAAU,0BACV,OAAO,QAAQ,iBAAiB,MAAM,qBAAqB,mBAC1D;;;;;;;;;;;iBAmBc;EACf,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,MAAM;;;;;;;iBAQS,YAAY,UAAU,YAAY;EACjD;EACA,MAAM,UAAU;;EAEhB;EACA,aAAa,gBAAgB;;EAE7B;;;;;;;;EAQA,WAAW;;;;;EAKX,cAAc;;iBAGC;EACf,uBAAuB;;;;;EAKvB;;;;;;;;IAQE,cAAc,gBAAgB,OAAO,gBAAgB,QAAQ;;;;;;IAM7D,QAAQ,OAAO,kBAAkB;;;;;;;;;;;;;;;;;wBAkBrB,iBACd,SAAS;EAAuB,OAAO,YAAY;;EAEnD,SAAS;EACT,OAAO;;wBAEO,iBAAiB,SAAS;EAAuB,SAAS;;KAyDrE,WAAW,QAAQ,iBAAiB,OAAO,qBAAqB;KAChE,SAAS,UAAU,WAAW,OAAO,YAAY,OAAO,QAAQ,WAAW"}
|
|
@@ -25,7 +25,7 @@ function setupConversions(options) {
|
|
|
25
25
|
*/
|
|
26
26
|
async function track({ resolveUser, store }, input) {
|
|
27
27
|
try {
|
|
28
|
-
const user = await resolveUser(input.userId);
|
|
28
|
+
const user = await resolveUser(input.userId, input);
|
|
29
29
|
if (!user) {
|
|
30
30
|
console.warn(`Conversion not reported, event: ${input.id}: no session for ${input.userId}`);
|
|
31
31
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-conversions.mjs","names":[],"sources":["../../src/server/setup-conversions.ts"],"sourcesContent":["import type {\n Environment,\n EventName,\n Platform,\n TrackEvent,\n TrackName,\n TrackProperties,\n TrackTags,\n UserProvidedData,\n} from '../track/types';\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyTrackEvent = TrackEvent<any>;\n\n/**\n * Where `setupConversions` sends events: an ad platform's conversions API, from its factory\n * (`metaConversions`, … next to each sender), or anything else the host forwards events to (a\n * CRM, its own workflows).\n *\n * `send` rejects when it fails, as the SDK's senders do: `setupConversions` logs the failure,\n * with the events' ids, and still sends to the others.\n */\nexport interface ConversionDestination {\n readonly send: (events: AnyTrackEvent[], data: UserProvidedData) => Promise<unknown>;\n}\n\n/**\n * A destination that sends only the events `accepts` lets through, and makes no request when none\n * is left: what each conversions API's factory (`metaConversions`, …) is built on.\n */\nexport function conversionDestination(\n accepts: (name: string) => boolean,\n send: (events: AnyTrackEvent[], data: UserProvidedData) => Promise<unknown>\n): ConversionDestination {\n return {\n send: async (events, data) => {\n const accepted = events.filter((event) => accepts(event.name));\n if (accepted.length > 0) await send(accepted, data);\n },\n };\n}\n\n/**\n * Who a server-only event is from, as the host knows them: what the ad platforms match a client\n * event on, read from the host's own records.\n *\n * - `tags`: the user's latest session's tags (their cookies — `_fbp`, `_rdt_uuid`, … — page\n * and user agent), with the click ids of the touch the conversion is attributed to over them.\n * - `visitor_id`, `session_id`, `platform`, `environment`: from that session. `platform` decides\n * each platform's action source (website or app), as for a client event.\n * - `data`: the user's identity (`email`, `user_id`, …), hashed by each sender.\n */\nexport interface ConversionUser {\n tags: TrackTags;\n visitor_id: string;\n session_id: string;\n platform: Platform;\n environment: Environment;\n data: UserProvidedData;\n}\n\n/**\n * An event the server reports on its own, with no client behind it: a webhook's purchase,\n * renewal or refund. `id` is the transaction id: `track.store` keeps a redelivered webhook from\n * being reported twice, and the platforms pair it with a browser event under the same id.\n */\nexport interface ServerEvent<T extends EventName = EventName> {\n id: string;\n name: TrackName<T>;\n /** The user it belongs to, handed to `track.resolveUser`. */\n userId: string;\n properties?: TrackProperties<T>;\n /** When it happened, as an ISO 8601 string. */\n createdAt: string;\n}\n\nexport interface ConversionsOptions {\n destinations: readonly ConversionDestination[];\n /**\n * How `track` completes and stores a server-only event. Without it `setupConversions` returns\n * only `forward`, for a host that only forwards client events.\n */\n track?: {\n /**\n * The user behind the event, read from the host's records (see `ConversionUser`)
|
|
1
|
+
{"version":3,"file":"setup-conversions.mjs","names":[],"sources":["../../src/server/setup-conversions.ts"],"sourcesContent":["import type {\n Environment,\n EventName,\n Platform,\n TrackEvent,\n TrackName,\n TrackProperties,\n TrackTags,\n UserProvidedData,\n} from '../track/types';\n\n// oxlint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyTrackEvent = TrackEvent<any>;\n\n/**\n * Where `setupConversions` sends events: an ad platform's conversions API, from its factory\n * (`metaConversions`, … next to each sender), or anything else the host forwards events to (a\n * CRM, its own workflows).\n *\n * `send` rejects when it fails, as the SDK's senders do: `setupConversions` logs the failure,\n * with the events' ids, and still sends to the others.\n */\nexport interface ConversionDestination {\n readonly send: (events: AnyTrackEvent[], data: UserProvidedData) => Promise<unknown>;\n}\n\n/**\n * A destination that sends only the events `accepts` lets through, and makes no request when none\n * is left: what each conversions API's factory (`metaConversions`, …) is built on.\n */\nexport function conversionDestination(\n accepts: (name: string) => boolean,\n send: (events: AnyTrackEvent[], data: UserProvidedData) => Promise<unknown>\n): ConversionDestination {\n return {\n send: async (events, data) => {\n const accepted = events.filter((event) => accepts(event.name));\n if (accepted.length > 0) await send(accepted, data);\n },\n };\n}\n\n/**\n * Who a server-only event is from, as the host knows them: what the ad platforms match a client\n * event on, read from the host's own records.\n *\n * - `tags`: the user's latest session's tags (their cookies — `_fbp`, `_rdt_uuid`, … — page\n * and user agent), with the click ids of the touch the conversion is attributed to over them.\n * - `visitor_id`, `session_id`, `platform`, `environment`: from that session. `platform` decides\n * each platform's action source (website or app), as for a client event.\n * - `data`: the user's identity (`email`, `user_id`, …), hashed by each sender.\n */\nexport interface ConversionUser {\n tags: TrackTags;\n visitor_id: string;\n session_id: string;\n platform: Platform;\n environment: Environment;\n data: UserProvidedData;\n}\n\n/**\n * An event the server reports on its own, with no client behind it: a webhook's purchase,\n * renewal or refund. `id` is the transaction id: `track.store` keeps a redelivered webhook from\n * being reported twice, and the platforms pair it with a browser event under the same id.\n */\nexport interface ServerEvent<T extends EventName = EventName> {\n id: string;\n name: TrackName<T>;\n /** The user it belongs to, handed to `track.resolveUser`. */\n userId: string;\n properties?: TrackProperties<T>;\n /** When it happened, as an ISO 8601 string. */\n createdAt: string;\n /**\n * Where it happened, when the server knows better than any session: a Stripe payment is `web`,\n * an App Store one `ios`. Read by `resolveUser`, which answers the event's `platform` (it\n * decides each platform's action source): a session of this platform when the user has one,\n * or something else for a user with no session at all, such as `unknown` when there is no user\n * agent to send with a website event.\n */\n platform?: Platform;\n /**\n * Whether it was real, when the server knows: a store's sandbox purchase is `development` even\n * in a production deployment. Read by `resolveUser`, which answers the event's `environment`.\n */\n environment?: Environment;\n}\n\nexport interface ConversionsOptions {\n destinations: readonly ConversionDestination[];\n /**\n * How `track` completes and stores a server-only event. Without it `setupConversions` returns\n * only `forward`, for a host that only forwards client events.\n */\n track?: {\n /**\n * The user behind the event, read from the host's records (see `ConversionUser`), given the\n * event so a session of its `platform` can be preferred and its `platform` / `environment`\n * answered; what it returns is what the event is sent with. `undefined` drops the event. A user\n * with no session at all can still be matched by the platforms on `data` alone (a hashed\n * email), so a host may answer with empty `tags` and ids of its own rather than drop it.\n */\n resolveUser: (userId: string, event: ServerEvent) => Promise<ConversionUser | undefined>;\n /**\n * Stores the event, e.g. in the events table, returning whether it was new: `track` sends\n * only an event it stored, so a webhook delivered again (its handler failed on something\n * else) is not reported twice — not every platform deduplicates a server event sent twice.\n */\n store: (event: AnyTrackEvent) => Promise<boolean>;\n };\n}\n\n/**\n * The server's counterpart of `setupAnalytics({ integrations })`: every destination configured\n * once, with the same per-platform options as the browser integrations, so the conversions API\n * and the tag report the same events.\n *\n * - `forward(events, data)`: the events a client sent, as stored, on to every destination.\n * - `track(event)`: an event the server reports on its own (a webhook's), completed by\n * `track.resolveUser`, stored with `track.store`, then forwarded.\n *\n * Neither throws, so reporting a conversion can never fail the request it runs in — a payment\n * webhook least of all, which its provider would then deliver again and again. A failure is\n * logged with the ids of the events it lost, for them to be found and sent later: a missed\n * conversion costs less than a duplicate one, or a webhook that keeps failing.\n */\nexport function setupConversions(\n options: ConversionsOptions & { track: NonNullable<ConversionsOptions['track']> }\n): {\n forward: Forward;\n track: Track;\n};\nexport function setupConversions(options: ConversionsOptions): { forward: Forward };\nexport function setupConversions(options: ConversionsOptions) {\n const { destinations, track: trackOptions } = options;\n\n async function forward(events: AnyTrackEvent[], data: UserProvidedData = {}) {\n if (events.length === 0) return;\n // Called inside a promise: a `send` that throws synchronously rejects there instead of\n // stopping the destinations after it.\n const settled = await Promise.allSettled(\n destinations.map((d) => Promise.resolve().then(() => d.send(events, data)))\n );\n const ids = events.map((event) => event.id).join(', ');\n settled.forEach((outcome) => {\n if (outcome.status === 'rejected') {\n console.error(`Conversions not sent, events: ${ids}`, outcome.reason);\n }\n });\n }\n\n /**\n * Reports a server-only event; resolves with it as sent, or `undefined` when it was not: a\n * user with no session, an event `store` had already stored, or a failure, which is logged.\n */\n async function track<T extends EventName>(\n { resolveUser, store }: NonNullable<ConversionsOptions['track']>,\n input: ServerEvent<T>\n ): Promise<TrackEvent<T> | undefined> {\n try {\n const user = await resolveUser(input.userId, input);\n if (!user) {\n console.warn(`Conversion not reported, event: ${input.id}: no session for ${input.userId}`);\n return undefined;\n }\n const event: TrackEvent<T> = {\n id: input.id,\n name: input.name,\n properties: input.properties,\n tags: user.tags,\n visitor_id: user.visitor_id,\n session_id: user.session_id,\n platform: user.platform,\n environment: user.environment,\n created_at: input.createdAt,\n };\n if (!(await store(event))) return undefined;\n await forward([event], user.data);\n return event;\n } catch (e: unknown) {\n console.error(`Conversion not reported, event: ${input.id}`, e);\n return undefined;\n }\n }\n\n if (!trackOptions) return { forward };\n return { forward, track: (input: ServerEvent) => track(trackOptions, input) };\n}\n\ntype Forward = (events: AnyTrackEvent[], data?: UserProvidedData) => Promise<void>;\ntype Track = <T extends EventName>(input: ServerEvent<T>) => Promise<TrackEvent<T> | undefined>;\n"],"mappings":";;;;;AA8BA,SAAgB,sBACd,SACA,MACuB;CACvB,OAAO,EACL,MAAM,OAAO,QAAQ,SAAS;EAC5B,MAAM,WAAW,OAAO,QAAQ,UAAU,QAAQ,MAAM,IAAI,CAAC;EAC7D,IAAI,SAAS,SAAS,GAAG,MAAM,KAAK,UAAU,IAAI;CACpD,EACF;AACF;AA8FA,SAAgB,iBAAiB,SAA6B;CAC5D,MAAM,EAAE,cAAc,OAAO,iBAAiB;CAE9C,eAAe,QAAQ,QAAyB,OAAyB,CAAC,GAAG;EAC3E,IAAI,OAAO,WAAW,GAAG;EAGzB,MAAM,UAAU,MAAM,QAAQ,WAC5B,aAAa,KAAK,MAAM,QAAQ,QAAQ,CAAC,CAAC,WAAW,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,CAC5E;EACA,MAAM,MAAM,OAAO,KAAK,UAAU,MAAM,EAAE,CAAC,CAAC,KAAK,IAAI;EACrD,QAAQ,SAAS,YAAY;GAC3B,IAAI,QAAQ,WAAW,YACrB,QAAQ,MAAM,iCAAiC,OAAO,QAAQ,MAAM;EAExE,CAAC;CACH;;;;;CAMA,eAAe,MACb,EAAE,aAAa,SACf,OACoC;EACpC,IAAI;GACF,MAAM,OAAO,MAAM,YAAY,MAAM,QAAQ,KAAK;GAClD,IAAI,CAAC,MAAM;IACT,QAAQ,KAAK,mCAAmC,MAAM,GAAG,mBAAmB,MAAM,QAAQ;IAC1F;GACF;GACA,MAAM,QAAuB;IAC3B,IAAI,MAAM;IACV,MAAM,MAAM;IACZ,YAAY,MAAM;IAClB,MAAM,KAAK;IACX,YAAY,KAAK;IACjB,YAAY,KAAK;IACjB,UAAU,KAAK;IACf,aAAa,KAAK;IAClB,YAAY,MAAM;GACpB;GACA,IAAI,CAAE,MAAM,MAAM,KAAK,GAAI,OAAO,KAAA;GAClC,MAAM,QAAQ,CAAC,KAAK,GAAG,KAAK,IAAI;GAChC,OAAO;EACT,SAAS,GAAY;GACnB,QAAQ,MAAM,mCAAmC,MAAM,MAAM,CAAC;GAC9D;EACF;CACF;CAEA,IAAI,CAAC,cAAc,OAAO,EAAE,QAAQ;CACpC,OAAO;EAAE;EAAS,QAAQ,UAAuB,MAAM,cAAc,KAAK;CAAE;AAC9E"}
|