tracklane 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{browser-CddkJdvX.d.ts → browser-34-CHcxK.d.ts} +163 -10
- package/dist/browser-DhzO5qPS.js +432 -0
- package/dist/browser-DhzO5qPS.js.map +1 -0
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +2 -397
- package/dist/conformance.d.ts +7 -1
- package/dist/conformance.js +67 -10
- package/dist/conformance.js.map +1 -1
- package/dist/{dispatch-BLBoCn-b.js → dispatch-B32jGhlh.js} +6 -3
- package/dist/dispatch-B32jGhlh.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -0
- package/dist/server-DnP7RtEn.js +647 -0
- package/dist/server-DnP7RtEn.js.map +1 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -509
- package/dist/src-DLRGPWMj.js +75 -0
- package/dist/src-DLRGPWMj.js.map +1 -0
- package/package.json +2 -2
- package/dist/browser.js.map +0 -1
- package/dist/dispatch-BLBoCn-b.js.map +0 -1
- package/dist/server.js.map +0 -1
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ build, so it is never ahead of the library.
|
|
|
91
91
|
| -------- | -------------------- | ------ |
|
|
92
92
|
| GA4 | Measurement Protocol | shipped |
|
|
93
93
|
| Meta | Conversions API | shipped |
|
|
94
|
-
| LinkedIn | Conversions API |
|
|
94
|
+
| LinkedIn | Conversions API | shipped |
|
|
95
95
|
| PostHog | Capture API | shipped |
|
|
96
96
|
| X | Conversions API | next |
|
|
97
97
|
|
|
@@ -1,3 +1,62 @@
|
|
|
1
|
+
//#region src/errors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Thrown by a server provider when the vendor's endpoint answers with a
|
|
4
|
+
* non-2xx status. The message stays exactly what the provider composed,
|
|
5
|
+
* free of the payload, per `TrackingError`'s guarantee, and the vendor's own
|
|
6
|
+
* answer travels separately on `status` and `body`, for a host that asks for
|
|
7
|
+
* it via `onError` rather than a host that logs by default.
|
|
8
|
+
*
|
|
9
|
+
* See ADR-0013 for why the split exists and why `body` is a property rather
|
|
10
|
+
* than `cause`.
|
|
11
|
+
*
|
|
12
|
+
* @param message - The same one-line message the provider already throws
|
|
13
|
+
* today (e.g. `meta: the Conversions API answered 400`). Not composed here.
|
|
14
|
+
* @param details - The vendor's own answer: `provider` is the name it
|
|
15
|
+
* registers under, `status` is the HTTP status, and `body` is the response
|
|
16
|
+
* body verbatim, capped at 2048 characters with a `…[truncated]` suffix that
|
|
17
|
+
* fits inside the cap.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* throw new VendorResponseError(`meta: the Conversions API answered ${status}`, {
|
|
22
|
+
* provider: 'meta',
|
|
23
|
+
* status,
|
|
24
|
+
* body: await response.text().catch(() => ''),
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare class VendorResponseError extends Error {
|
|
29
|
+
readonly provider: string;
|
|
30
|
+
readonly status: number;
|
|
31
|
+
readonly body: string;
|
|
32
|
+
constructor(message: string, details: {
|
|
33
|
+
provider: string;
|
|
34
|
+
status: number;
|
|
35
|
+
body: string;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Tests the brand `VendorResponseError` sets, not `instanceof`: two copies
|
|
40
|
+
* of this package in one `node_modules` produce two constructors, and
|
|
41
|
+
* `instanceof` would say `false` for an instance the other copy built. The
|
|
42
|
+
* `Symbol.for` brand is the same symbol across both.
|
|
43
|
+
*
|
|
44
|
+
* @param value - Anything a `catch` block might hand back.
|
|
45
|
+
* @returns Whether `value` carries the `VendorResponseError` brand.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* try {
|
|
50
|
+
* await track.server('purchase', data, context);
|
|
51
|
+
* } catch (error) {
|
|
52
|
+
* if (isVendorResponseError(error)) {
|
|
53
|
+
* reportWithFingerprint(error.provider, error.status, error.body);
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function isVendorResponseError(value: unknown): value is VendorResponseError;
|
|
59
|
+
//#endregion
|
|
1
60
|
//#region src/providers/ga4.server.d.ts
|
|
2
61
|
/** Credentials for the GA4 Measurement Protocol. */
|
|
3
62
|
interface Ga4ServerCredentials {
|
|
@@ -30,6 +89,41 @@ interface Ga4ServerConfig {
|
|
|
30
89
|
*/
|
|
31
90
|
declare function ga4$1(credentials: Ga4ServerCredentials, config?: Ga4ServerConfig): ServerProvider;
|
|
32
91
|
//#endregion
|
|
92
|
+
//#region src/providers/linkedin.server.d.ts
|
|
93
|
+
/** Credentials for LinkedIn's Conversions API. */
|
|
94
|
+
interface LinkedinServerCredentials {
|
|
95
|
+
/** An access token authorized for the conversion's ad account. */
|
|
96
|
+
accessToken: string;
|
|
97
|
+
}
|
|
98
|
+
/** Configuration for the LinkedIn Conversions API provider. */
|
|
99
|
+
interface LinkedinServerConfig {
|
|
100
|
+
/** Conversion IDs minted in Campaign Manager. `null` explicitly suppresses an event. */
|
|
101
|
+
events: Record<string, EventBinding<string>>;
|
|
102
|
+
/** LinkedIn's Marketing API version, in YYYYMM form. Defaults to `202609`. */
|
|
103
|
+
apiVersion?: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Sends event-specific conversions to LinkedIn's Conversions API.
|
|
107
|
+
* Value and currency become conversionValue; items, transaction_id, custom
|
|
108
|
+
* properties, traits and consent have no documented field on this endpoint.
|
|
109
|
+
* The host's deduplication ID becomes eventId, without generating one.
|
|
110
|
+
*
|
|
111
|
+
* @param credentials - The ad account's Conversions API access token.
|
|
112
|
+
* @param config - Canonical event to conversion ID map and API version.
|
|
113
|
+
* @returns A server provider for `createTracking`.
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { createTracking, linkedin } from 'tracklane/server';
|
|
117
|
+
* const { track } = createTracking({
|
|
118
|
+
* providers: [linkedin({ accessToken }, { events: { purchase: '12345' } })],
|
|
119
|
+
* });
|
|
120
|
+
* await track('purchase', { value: 15, currency: 'BRL' }, {
|
|
121
|
+
* user: { email: 'buyer@example.com' }, dedupId: 'order-1',
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function linkedin$1(credentials: LinkedinServerCredentials, config: LinkedinServerConfig): ServerProvider;
|
|
126
|
+
//#endregion
|
|
33
127
|
//#region src/providers/meta.server.d.ts
|
|
34
128
|
/** Credentials for Meta's Conversions API. */
|
|
35
129
|
interface MetaServerCredentials {
|
|
@@ -76,6 +170,11 @@ interface MetaServerConfig {
|
|
|
76
170
|
/**
|
|
77
171
|
* Meta's Conversions API.
|
|
78
172
|
*
|
|
173
|
+
* If any item lacks a nonempty `item_id`, the complete `contents` list is
|
|
174
|
+
* omitted while totals and order metadata remain unchanged. This avoids
|
|
175
|
+
* presenting a partial order or inventing product identifiers. The error
|
|
176
|
+
* channel receives one payload-free warning after HTTP acceptance.
|
|
177
|
+
*
|
|
79
178
|
* @param credentials - The pixel id and an access token.
|
|
80
179
|
* @param config - Event overrides, the default action source, and Meta's own
|
|
81
180
|
* levers: the API version, a test event code, and Limited Data Use.
|
|
@@ -267,8 +366,9 @@ type ProviderDefault = "passthrough" | "ignore";
|
|
|
267
366
|
*
|
|
268
367
|
* Fanning out to N vendors means no single call site can catch anything, so
|
|
269
368
|
* this is the replica of the `try/catch` a host would have written around a
|
|
270
|
-
* hand-made call. `severity` separates
|
|
271
|
-
*
|
|
369
|
+
* hand-made call. `severity` separates an observed failure from a caveat.
|
|
370
|
+
* Neither proves delivery: a browser command may only be queued, an HTTP
|
|
371
|
+
* success does not prove processing, and a network error may follow acceptance.
|
|
272
372
|
*
|
|
273
373
|
* It never carries event contents: the payload holds raw personal data by
|
|
274
374
|
* design, and no library-owned surface re-emits it into a host's logs.
|
|
@@ -278,7 +378,7 @@ interface TrackingError {
|
|
|
278
378
|
provider: string;
|
|
279
379
|
/** The canonical event name being sent when this happened. */
|
|
280
380
|
event: string;
|
|
281
|
-
/** `'error'`
|
|
381
|
+
/** `'error'` for an observed failure; `'warning'` for a caveat. Neither guarantees delivery. */
|
|
282
382
|
severity: "error" | "warning";
|
|
283
383
|
/** What happened, in one line, excluding the payload: event data never appears here. */
|
|
284
384
|
message: string;
|
|
@@ -374,6 +474,8 @@ interface ServerTrackingOptions {
|
|
|
374
474
|
/**
|
|
375
475
|
* The one diagnostic channel. Without it the library is silent, exactly as
|
|
376
476
|
* a hand-written vendor call is.
|
|
477
|
+
* Unmapped events on an `ignore` provider report warnings; explicit `null`
|
|
478
|
+
* exclusions stay silent. Attach a reporter in development to catch omissions.
|
|
377
479
|
*/
|
|
378
480
|
onError?: (error: TrackingError) => void;
|
|
379
481
|
}
|
|
@@ -440,8 +542,10 @@ interface Ga4BrowserConfig {
|
|
|
440
542
|
* configures the property is yours. Use {@link ConsentState} through
|
|
441
543
|
* `consent()` for changes after that.
|
|
442
544
|
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
545
|
+
* With no measurement ID, events keep the tag's configured routing. Pass a
|
|
546
|
+
* measurement ID to address that destination through `send_to` instead.
|
|
547
|
+
* Neither form installs or configures the tag.
|
|
548
|
+
*
|
|
445
549
|
* @param config - Rarely needed event name overrides.
|
|
446
550
|
* @returns A provider for `createTracking` from `tracklane/browser`.
|
|
447
551
|
*
|
|
@@ -450,13 +554,50 @@ interface Ga4BrowserConfig {
|
|
|
450
554
|
* import { createTracking, ga4 } from 'tracklane/browser';
|
|
451
555
|
*
|
|
452
556
|
* // Google's own snippet is already in the page.
|
|
453
|
-
* const { track } = createTracking({ providers: [ga4(
|
|
557
|
+
* const { track } = createTracking({ providers: [ga4()] });
|
|
454
558
|
*
|
|
455
559
|
* track('purchase', { transaction_id: 'T-1', value: 49.9, currency: 'BRL' });
|
|
456
560
|
* ```
|
|
457
561
|
*/
|
|
562
|
+
declare function ga4(config?: Ga4BrowserConfig): BrowserProvider;
|
|
563
|
+
/**
|
|
564
|
+
* Addresses one configured Google destination instead of using the tag's
|
|
565
|
+
* default routing. Existing calls keep their `send_to` behavior.
|
|
566
|
+
*
|
|
567
|
+
* @param measurementId - The `G-` ID of the configured data stream.
|
|
568
|
+
* @param config - Rarely needed event name overrides.
|
|
569
|
+
* @returns A provider for `createTracking` from `tracklane/browser`.
|
|
570
|
+
* @example
|
|
571
|
+
* ```ts
|
|
572
|
+
* const provider = ga4('G-XXXXXXX', { events: { my_event: 'my_ga4_name' } });
|
|
573
|
+
* ```
|
|
574
|
+
*/
|
|
458
575
|
declare function ga4(measurementId: string, config?: Ga4BrowserConfig): BrowserProvider;
|
|
459
576
|
//#endregion
|
|
577
|
+
//#region src/providers/linkedin.browser.d.ts
|
|
578
|
+
/** Configuration for the LinkedIn Insight Tag provider. */
|
|
579
|
+
interface LinkedinBrowserConfig {
|
|
580
|
+
/** Conversion IDs minted in Campaign Manager. `null` explicitly suppresses an event. */
|
|
581
|
+
events: Record<string, EventBinding<string>>;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Calls the host-installed LinkedIn Insight Tag for event-specific conversions.
|
|
585
|
+
* LinkedIn has no event names, user-identification command or consent command.
|
|
586
|
+
* Items and custom parameters have no documented slot and are not forwarded.
|
|
587
|
+
*
|
|
588
|
+
* @param config - The canonical event to conversion ID map.
|
|
589
|
+
* @returns A browser provider; it does not install the Insight Tag.
|
|
590
|
+
* @example
|
|
591
|
+
* ```ts
|
|
592
|
+
* import { createTracking, linkedin } from 'tracklane/browser';
|
|
593
|
+
* const { track } = createTracking({
|
|
594
|
+
* providers: [linkedin({ events: { purchase: '12345' } })],
|
|
595
|
+
* });
|
|
596
|
+
* track('purchase', { value: 15, currency: 'BRL' }, { dedupId: 'order-1' });
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
declare function linkedin(config: LinkedinBrowserConfig): BrowserProvider;
|
|
600
|
+
//#endregion
|
|
460
601
|
//#region src/providers/meta.browser.d.ts
|
|
461
602
|
/** Optional configuration for the Meta browser provider. */
|
|
462
603
|
interface MetaBrowserConfig {
|
|
@@ -502,6 +643,11 @@ interface MetaBrowserConfig {
|
|
|
502
643
|
* this adapter cannot deliver. Which pixels exist is declared by your snippet,
|
|
503
644
|
* in `fbq('init')`.
|
|
504
645
|
*
|
|
646
|
+
* If any item lacks a nonempty `item_id`, the complete `contents` list is
|
|
647
|
+
* omitted while totals and order metadata remain unchanged. This avoids
|
|
648
|
+
* presenting a partial order or inventing product identifiers. The error
|
|
649
|
+
* channel receives one payload-free warning after the browser command returns.
|
|
650
|
+
*
|
|
505
651
|
* @param config - Event name overrides, merged over the built-in map.
|
|
506
652
|
* @returns A provider for `createTracking` from `tracklane/browser`.
|
|
507
653
|
*
|
|
@@ -589,8 +735,13 @@ interface BrowserProvider<Target = string> {
|
|
|
589
735
|
* installs again, including providers that were already there.
|
|
590
736
|
*/
|
|
591
737
|
install?(): void | Promise<void>;
|
|
592
|
-
/**
|
|
593
|
-
|
|
738
|
+
/**
|
|
739
|
+
* Sends one event to this vendor. Throwing here reaches `onError`, not the caller.
|
|
740
|
+
* The optional report callback emits a payload-free warning; it is not proof
|
|
741
|
+
* of delivery or provider-side processing. Older three-argument providers
|
|
742
|
+
* and direct calls remain supported.
|
|
743
|
+
*/
|
|
744
|
+
track(name: Target, data: EventData, options: TrackOptions, report?: (message: string) => void): void;
|
|
594
745
|
/** Absent where the vendor keeps no user of its own. */
|
|
595
746
|
identify?(user: UserData, traits?: Record<string, unknown>): void;
|
|
596
747
|
/** Absent where the vendor documents no consent command. */
|
|
@@ -603,6 +754,8 @@ interface BrowserTrackingOptions {
|
|
|
603
754
|
/**
|
|
604
755
|
* The one diagnostic channel. Without it the library is silent, exactly as
|
|
605
756
|
* a hand-written vendor call is.
|
|
757
|
+
* Unmapped events on an `ignore` provider report warnings; explicit `null`
|
|
758
|
+
* exclusions stay silent. Attach a reporter in development to catch omissions.
|
|
606
759
|
*/
|
|
607
760
|
onError?: (error: TrackingError) => void;
|
|
608
761
|
}
|
|
@@ -639,5 +792,5 @@ interface BrowserTracking {
|
|
|
639
792
|
*/
|
|
640
793
|
declare function createTracking(options: BrowserTrackingOptions): BrowserTracking;
|
|
641
794
|
//#endregion
|
|
642
|
-
export {
|
|
643
|
-
//# sourceMappingURL=browser-
|
|
795
|
+
export { posthog$1 as A, VendorResponseError as B, EventData as C, UserData as D, TrackingError as E, LinkedinServerCredentials as F, linkedin$1 as I, Ga4ServerConfig as L, MetaServerCredentials as M, meta$1 as N, PosthogServerConfig as O, LinkedinServerConfig as P, Ga4ServerCredentials as R, EventBinding as S, ProviderDefault as T, isVendorResponseError as V, ServerTracking as _, createTracking as a, ActionSource as b, MetaBrowserConfig as c, linkedin as d, Ga4BrowserConfig as f, ServerProvider as g, ResolvedContext as h, TrackOptions as i, MetaServerConfig as j, PosthogServerCredentials as k, meta as l, EventContext as m, BrowserTracking as n, PosthogBrowserConfig as o, ga4 as p, BrowserTrackingOptions as r, posthog as s, BrowserProvider as t, LinkedinBrowserConfig as u, ServerTrackingOptions as v, EventItem as w, ConsentState as x, createTracking$1 as y, ga4$1 as z };
|
|
796
|
+
//# sourceMappingURL=browser-34-CHcxK.d.ts.map
|