tracklane 0.6.0 → 0.8.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.
@@ -67,13 +67,28 @@ interface Ga4ServerCredentials {
67
67
  }
68
68
  /** Optional configuration for the GA4 server provider. */
69
69
  interface Ga4ServerConfig {
70
+ /** How this property spells each canonical event. Rarely needed. */
70
71
  events?: Record<string, EventBinding<string>>;
72
+ /**
73
+ * Sends `user_data` built from `user` (email, phone, first and last name),
74
+ * normalised and SHA-256 hashed the way Google documents. Off by default:
75
+ * it starts a new flow of personal data to Google, and the property needs
76
+ * user-provided data collection turned on in GA4's admin.
77
+ *
78
+ * There is no consent check in it. To withhold it, pass `user: { userId }`.
79
+ */
80
+ userProvidedData?: boolean;
71
81
  }
72
82
  /**
73
83
  * Google Analytics 4 on the server, through the Measurement Protocol.
74
84
  *
85
+ * **`identify` sends user properties with no event**, which Google
86
+ * documents. With no user property to send it sends nothing, because each
87
+ * `track` already carries `user_id`.
88
+ *
75
89
  * @param credentials - The measurement id and API secret.
76
- * @param config - Rarely needed event name overrides.
90
+ * @param config - Rarely needed event name overrides, and the opt-in for
91
+ * user-provided data.
77
92
  * @returns A provider for `createTracking` from `tracklane/server`.
78
93
  *
79
94
  * @example
@@ -89,6 +104,41 @@ interface Ga4ServerConfig {
89
104
  */
90
105
  declare function ga4$1(credentials: Ga4ServerCredentials, config?: Ga4ServerConfig): ServerProvider;
91
106
  //#endregion
107
+ //#region src/providers/linkedin.server.d.ts
108
+ /** Credentials for LinkedIn's Conversions API. */
109
+ interface LinkedinServerCredentials {
110
+ /** An access token authorized for the conversion's ad account. */
111
+ accessToken: string;
112
+ }
113
+ /** Configuration for the LinkedIn Conversions API provider. */
114
+ interface LinkedinServerConfig {
115
+ /** Conversion IDs minted in Campaign Manager. `null` explicitly suppresses an event. */
116
+ events: Record<string, EventBinding<string>>;
117
+ /** LinkedIn's Marketing API version, in YYYYMM form. Defaults to `202609`. */
118
+ apiVersion?: string;
119
+ }
120
+ /**
121
+ * Sends event-specific conversions to LinkedIn's Conversions API.
122
+ * Value and currency become conversionValue; items, transaction_id, custom
123
+ * properties, traits and consent have no documented field on this endpoint.
124
+ * The host's deduplication ID becomes eventId, without generating one.
125
+ *
126
+ * @param credentials - The ad account's Conversions API access token.
127
+ * @param config - Canonical event to conversion ID map and API version.
128
+ * @returns A server provider for `createTracking`.
129
+ * @example
130
+ * ```ts
131
+ * import { createTracking, linkedin } from 'tracklane/server';
132
+ * const { track } = createTracking({
133
+ * providers: [linkedin({ accessToken }, { events: { purchase: '12345' } })],
134
+ * });
135
+ * await track('purchase', { value: 15, currency: 'BRL' }, {
136
+ * user: { email: 'buyer@example.com' }, dedupId: 'order-1',
137
+ * });
138
+ * ```
139
+ */
140
+ declare function linkedin$1(credentials: LinkedinServerCredentials, config: LinkedinServerConfig): ServerProvider;
141
+ //#endregion
92
142
  //#region src/providers/meta.server.d.ts
93
143
  /** Credentials for Meta's Conversions API. */
94
144
  interface MetaServerCredentials {
@@ -135,6 +185,11 @@ interface MetaServerConfig {
135
185
  /**
136
186
  * Meta's Conversions API.
137
187
  *
188
+ * If any item lacks a nonempty `item_id`, the complete `contents` list is
189
+ * omitted while totals and order metadata remain unchanged. This avoids
190
+ * presenting a partial order or inventing product identifiers. The error
191
+ * channel receives one payload-free warning after HTTP acceptance.
192
+ *
138
193
  * @param credentials - The pixel id and an access token.
139
194
  * @param config - Event overrides, the default action source, and Meta's own
140
195
  * levers: the API version, a test event code, and Limited Data Use.
@@ -193,6 +248,12 @@ interface PosthogServerConfig {
193
248
  * Deduplication is also eventual, happening during a background merge, so both
194
249
  * rows are visible for a while and a test that counts immediately will fail.
195
250
  *
251
+ * **`identify` sends one `$identify`**, with `$set` and `$unset` from the
252
+ * traits. It merges a visitor into the user only when the context carries
253
+ * `anonymousId`, never from the cookie: a merge is irreversible, and PostHog
254
+ * reports a refused one only as an ingestion warning in its own interface.
255
+ * Identified events are billed with person processing.
256
+ *
196
257
  * @param credentials - The project API key, and the ingestion host for
197
258
  * anything other than PostHog's default US Cloud instance.
198
259
  * @param config - Rarely needed event name overrides.
@@ -326,8 +387,9 @@ type ProviderDefault = "passthrough" | "ignore";
326
387
  *
327
388
  * Fanning out to N vendors means no single call site can catch anything, so
328
389
  * this is the replica of the `try/catch` a host would have written around a
329
- * hand-made call. `severity` separates "this did not arrive" from "this
330
- * arrived, and here is something you should know".
390
+ * hand-made call. `severity` separates an observed failure from a caveat.
391
+ * Neither proves delivery: a browser command may only be queued, an HTTP
392
+ * success does not prove processing, and a network error may follow acceptance.
331
393
  *
332
394
  * It never carries event contents: the payload holds raw personal data by
333
395
  * design, and no library-owned surface re-emits it into a host's logs.
@@ -337,7 +399,7 @@ interface TrackingError {
337
399
  provider: string;
338
400
  /** The canonical event name being sent when this happened. */
339
401
  event: string;
340
- /** `'error'` when the event did not arrive; `'warning'` when it arrived but is worth a look. */
402
+ /** `'error'` for an observed failure; `'warning'` for a caveat. Neither guarantees delivery. */
341
403
  severity: "error" | "warning";
342
404
  /** What happened, in one line, excluding the payload: event data never appears here. */
343
405
  message: string;
@@ -389,8 +451,31 @@ interface EventContext {
389
451
  ip?: string;
390
452
  /** The visitor's user agent. Meta's Conversions API reads it alongside `ip`. */
391
453
  userAgent?: string;
392
- /** What is known *about* the person: GA4 user properties, PostHog `$set`. */
454
+ /**
455
+ * What is known *about* the person: GA4 user properties, PostHog `$set`.
456
+ *
457
+ * A trait set to `null` means "no longer known". PostHog receives it in
458
+ * `$unset`. GA4 leaves it out and reports that it did, because clearing a
459
+ * user property through the Measurement Protocol is not yet verified.
460
+ */
393
461
  traits?: Record<string, unknown>;
462
+ /**
463
+ * When the traits were true, if not when the event happened. Same units as
464
+ * `timestamp`. GA4 stamps each user property with it; vendors with no slot
465
+ * ignore it.
466
+ */
467
+ traitsAt?: number | Date;
468
+ /**
469
+ * Your own stable id for a visitor nobody has identified yet. Never
470
+ * generated by the library.
471
+ *
472
+ * PostHog uses it as `distinct_id` when there is no `user.userId`, ahead of
473
+ * its cookie, and `identify` merges it into the user. It must be the id the
474
+ * earlier PostHog events were captured under, or it merges nothing.
475
+ */
476
+ anonymousId?: string;
477
+ /** Cancels the vendor requests. An aborted send is reported as an error. */
478
+ signal?: AbortSignal;
394
479
  /**
395
480
  * Travels inside the event, for the vendors that document such a field.
396
481
  * Today that is GA4's Measurement Protocol, and it reads two of the
@@ -399,11 +484,23 @@ interface EventContext {
399
484
  consent?: ConsentState;
400
485
  }
401
486
  /** The context an adapter receives, with the ambiguity resolved. */
402
- interface ResolvedContext extends Omit<EventContext, "cookies" | "timestamp"> {
487
+ interface ResolvedContext extends Omit<EventContext, "cookies" | "timestamp" | "traitsAt"> {
403
488
  /** The request's cookies, already split into a `name → value` map. */
404
489
  cookies: Record<string, string>;
405
490
  /** Epoch milliseconds. Adapters convert to their vendor's spelling. */
406
491
  timestamp: number;
492
+ /** Epoch milliseconds, when the host gave one. */
493
+ traitsAt?: number;
494
+ }
495
+ /**
496
+ * The context {@link ServerTracking.identify} takes: the same one `track`
497
+ * takes, with the person's id required.
498
+ */
499
+ interface IdentifyContext extends EventContext {
500
+ /** Who the person is. `userId` is required: identifying nobody is not a call. */
501
+ user: UserData & {
502
+ userId: string;
503
+ };
407
504
  }
408
505
  /**
409
506
  * A destination for server events.
@@ -425,6 +522,11 @@ interface ServerProvider<Target = string> {
425
522
  events?: Record<string, EventBinding<Target>>;
426
523
  /** Sends one event to this vendor's conversion API. May throw, or call `report` for a caveat. */
427
524
  track(name: Target, data: EventData, context: ResolvedContext, report: (message: string) => void): Promise<void>;
525
+ /**
526
+ * Tells this vendor who the person is, with no event. Absent where the
527
+ * vendor keeps no person of its own. May throw, or call `report` for a caveat.
528
+ */
529
+ identify?(context: ResolvedContext, report: (message: string) => void): Promise<void>;
428
530
  }
429
531
  /** Options accepted by {@link createTracking}. */
430
532
  interface ServerTrackingOptions {
@@ -433,6 +535,8 @@ interface ServerTrackingOptions {
433
535
  /**
434
536
  * The one diagnostic channel. Without it the library is silent, exactly as
435
537
  * a hand-written vendor call is.
538
+ * Unmapped events on an `ignore` provider report warnings; explicit `null`
539
+ * exclusions stay silent. Attach a reporter in development to catch omissions.
436
540
  */
437
541
  onError?: (error: TrackingError) => void;
438
542
  }
@@ -447,21 +551,31 @@ interface ServerTracking {
447
551
  * guaranteed.
448
552
  */
449
553
  track(name: string, data?: EventData, context?: EventContext): Promise<void>;
554
+ /**
555
+ * Tells every vendor that keeps a person who this one is, with no event:
556
+ * PostHog's `$identify` and a GA4 request with user properties only.
557
+ * Vendors that keep no person receive nothing.
558
+ *
559
+ * A merge happens only when `anonymousId` is given. PostHog merges are
560
+ * irreversible, so pass it only when you know that visitor is this person.
561
+ * Resolves once every provider has settled and never rejects.
562
+ */
563
+ identify(context: IdentifyContext): Promise<void>;
450
564
  }
451
565
  /**
452
566
  * Creates the server tracking surface.
453
567
  *
454
- * There is no `identify` here and nothing is held between calls: a server
455
- * instance is shared by every request, so a retained identity would attach
456
- * one visitor to another visitor's conversion. Identity travels with the
457
- * call, which is also what every conversion API expects.
568
+ * Nothing is held between calls: a server instance is shared by every
569
+ * request, so a retained identity would attach one visitor to another
570
+ * visitor's conversion. Identity travels with each call, `identify`
571
+ * included, which is also what every conversion API expects.
458
572
  *
459
573
  * There is no `consent` call either. Consent commands are properties of a
460
574
  * vendor's on-page tag, and a server request has no tag. The one vendor that
461
575
  * accepts consent server-side reads it from the context.
462
576
  *
463
577
  * @param options - The providers to send to, and an optional error channel.
464
- * @returns The `track` call.
578
+ * @returns The `track` and `identify` calls.
465
579
  *
466
580
  * @example
467
581
  * ```ts
@@ -499,8 +613,10 @@ interface Ga4BrowserConfig {
499
613
  * configures the property is yours. Use {@link ConsentState} through
500
614
  * `consent()` for changes after that.
501
615
  *
502
- * @param measurementId - The `G-` id of the data stream, matching the tag on
503
- * the page.
616
+ * With no measurement ID, events keep the tag's configured routing. Pass a
617
+ * measurement ID to address that destination through `send_to` instead.
618
+ * Neither form installs or configures the tag.
619
+ *
504
620
  * @param config - Rarely needed event name overrides.
505
621
  * @returns A provider for `createTracking` from `tracklane/browser`.
506
622
  *
@@ -509,13 +625,50 @@ interface Ga4BrowserConfig {
509
625
  * import { createTracking, ga4 } from 'tracklane/browser';
510
626
  *
511
627
  * // Google's own snippet is already in the page.
512
- * const { track } = createTracking({ providers: [ga4('G-XXXXXXX')] });
628
+ * const { track } = createTracking({ providers: [ga4()] });
513
629
  *
514
630
  * track('purchase', { transaction_id: 'T-1', value: 49.9, currency: 'BRL' });
515
631
  * ```
516
632
  */
633
+ declare function ga4(config?: Ga4BrowserConfig): BrowserProvider;
634
+ /**
635
+ * Addresses one configured Google destination instead of using the tag's
636
+ * default routing. Existing calls keep their `send_to` behavior.
637
+ *
638
+ * @param measurementId - The `G-` ID of the configured data stream.
639
+ * @param config - Rarely needed event name overrides.
640
+ * @returns A provider for `createTracking` from `tracklane/browser`.
641
+ * @example
642
+ * ```ts
643
+ * const provider = ga4('G-XXXXXXX', { events: { my_event: 'my_ga4_name' } });
644
+ * ```
645
+ */
517
646
  declare function ga4(measurementId: string, config?: Ga4BrowserConfig): BrowserProvider;
518
647
  //#endregion
648
+ //#region src/providers/linkedin.browser.d.ts
649
+ /** Configuration for the LinkedIn Insight Tag provider. */
650
+ interface LinkedinBrowserConfig {
651
+ /** Conversion IDs minted in Campaign Manager. `null` explicitly suppresses an event. */
652
+ events: Record<string, EventBinding<string>>;
653
+ }
654
+ /**
655
+ * Calls the host-installed LinkedIn Insight Tag for event-specific conversions.
656
+ * LinkedIn has no event names, user-identification command or consent command.
657
+ * Items and custom parameters have no documented slot and are not forwarded.
658
+ *
659
+ * @param config - The canonical event to conversion ID map.
660
+ * @returns A browser provider; it does not install the Insight Tag.
661
+ * @example
662
+ * ```ts
663
+ * import { createTracking, linkedin } from 'tracklane/browser';
664
+ * const { track } = createTracking({
665
+ * providers: [linkedin({ events: { purchase: '12345' } })],
666
+ * });
667
+ * track('purchase', { value: 15, currency: 'BRL' }, { dedupId: 'order-1' });
668
+ * ```
669
+ */
670
+ declare function linkedin(config: LinkedinBrowserConfig): BrowserProvider;
671
+ //#endregion
519
672
  //#region src/providers/meta.browser.d.ts
520
673
  /** Optional configuration for the Meta browser provider. */
521
674
  interface MetaBrowserConfig {
@@ -561,6 +714,11 @@ interface MetaBrowserConfig {
561
714
  * this adapter cannot deliver. Which pixels exist is declared by your snippet,
562
715
  * in `fbq('init')`.
563
716
  *
717
+ * If any item lacks a nonempty `item_id`, the complete `contents` list is
718
+ * omitted while totals and order metadata remain unchanged. This avoids
719
+ * presenting a partial order or inventing product identifiers. The error
720
+ * channel receives one payload-free warning after the browser command returns.
721
+ *
564
722
  * @param config - Event name overrides, merged over the built-in map.
565
723
  * @returns A provider for `createTracking` from `tracklane/browser`.
566
724
  *
@@ -648,10 +806,21 @@ interface BrowserProvider<Target = string> {
648
806
  * installs again, including providers that were already there.
649
807
  */
650
808
  install?(): void | Promise<void>;
651
- /** Sends one event to this vendor. Throwing here reaches `onError`, not the caller. */
652
- track(name: Target, data: EventData, options: TrackOptions): void;
653
- /** Absent where the vendor keeps no user of its own. */
654
- identify?(user: UserData, traits?: Record<string, unknown>): void;
809
+ /**
810
+ * Sends one event to this vendor. Throwing here reaches `onError`, not the caller.
811
+ * The optional report callback emits a payload-free warning; it is not proof
812
+ * of delivery or provider-side processing. Older three-argument providers
813
+ * and direct calls remain supported.
814
+ */
815
+ track(name: Target, data: EventData, options: TrackOptions, report?: (message: string) => void): void;
816
+ /**
817
+ * Absent where the vendor keeps no user of its own. A trait set to `null`
818
+ * means "no longer known". The optional report callback emits a
819
+ * payload-free warning, as on `track`.
820
+ */
821
+ identify?(user: UserData, traits?: Record<string, unknown>, report?: (message: string) => void): void;
822
+ /** Forgets the user, at sign-out. Absent where the vendor keeps no user of its own. */
823
+ reset?(): void;
655
824
  /** Absent where the vendor documents no consent command. */
656
825
  consent?(command: "default" | "update", state: ConsentState): void;
657
826
  }
@@ -662,6 +831,8 @@ interface BrowserTrackingOptions {
662
831
  /**
663
832
  * The one diagnostic channel. Without it the library is silent, exactly as
664
833
  * a hand-written vendor call is.
834
+ * Unmapped events on an `ignore` provider report warnings; explicit `null`
835
+ * exclusions stay silent. Attach a reporter in development to catch omissions.
665
836
  */
666
837
  onError?: (error: TrackingError) => void;
667
838
  }
@@ -671,6 +842,14 @@ interface BrowserTracking {
671
842
  track(name: string, data?: EventData, options?: TrackOptions): void;
672
843
  /** Forwards the user to the vendors that hold one, and to nobody else. */
673
844
  identify(user: UserData, traits?: Record<string, unknown>): void;
845
+ /**
846
+ * Forgets the user in every vendor that holds one, at sign-out. Never throws.
847
+ *
848
+ * Vendors differ: GA4 clears `user_id` and keeps user properties until the
849
+ * page reloads; PostHog's own reset also forgets its opt-in, so call
850
+ * `consent('update', …)` again after it.
851
+ */
852
+ reset(): void;
674
853
  /**
675
854
  * Forwards a consent declaration to every vendor that documents a command
676
855
  * for it. It never decides, stores or withholds anything.
@@ -686,7 +865,7 @@ interface BrowserTracking {
686
865
  * lost to loading and this library needs no queue of its own.
687
866
  *
688
867
  * @param options - The providers to send to, and an optional error channel.
689
- * @returns The `track`, `identify` and `consent` calls.
868
+ * @returns The `track`, `identify`, `reset` and `consent` calls.
690
869
  *
691
870
  * @example
692
871
  * ```ts
@@ -698,5 +877,5 @@ interface BrowserTracking {
698
877
  */
699
878
  declare function createTracking(options: BrowserTrackingOptions): BrowserTracking;
700
879
  //#endregion
701
- export { MetaServerCredentials as A, ProviderDefault as C, PosthogServerCredentials as D, PosthogServerConfig as E, VendorResponseError as F, isVendorResponseError as I, Ga4ServerConfig as M, Ga4ServerCredentials as N, posthog$1 as O, ga4$1 as P, EventItem as S, UserData as T, createTracking$1 as _, createTracking as a, EventBinding as b, MetaBrowserConfig as c, ga4 as d, EventContext as f, ServerTrackingOptions as g, ServerTracking as h, TrackOptions as i, meta$1 as j, MetaServerConfig as k, meta as l, ServerProvider as m, BrowserTracking as n, PosthogBrowserConfig as o, ResolvedContext as p, BrowserTrackingOptions as r, posthog as s, BrowserProvider as t, Ga4BrowserConfig as u, ActionSource as v, TrackingError as w, EventData as x, ConsentState as y };
702
- //# sourceMappingURL=browser-_0LRgTpx.d.ts.map
880
+ export { PosthogServerCredentials as A, ga4$1 as B, EventBinding as C, TrackingError as D, ProviderDefault as E, LinkedinServerConfig as F, isVendorResponseError as H, LinkedinServerCredentials as I, linkedin$1 as L, MetaServerConfig as M, MetaServerCredentials as N, UserData as O, meta$1 as P, Ga4ServerConfig as R, ConsentState as S, EventItem as T, VendorResponseError as V, ServerProvider as _, createTracking as a, createTracking$1 as b, MetaBrowserConfig as c, linkedin as d, Ga4BrowserConfig as f, ResolvedContext as g, IdentifyContext as h, TrackOptions as i, posthog$1 as j, PosthogServerConfig 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, ServerTracking as v, EventData as w, ActionSource as x, ServerTrackingOptions as y, Ga4ServerCredentials as z };
881
+ //# sourceMappingURL=browser-k4gaaQgF.d.ts.map
package/dist/browser.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as createTracking, c as MetaBrowserConfig, d as ga4, i as TrackOptions, l as meta, n as BrowserTracking, o as PosthogBrowserConfig, r as BrowserTrackingOptions, s as posthog, t as BrowserProvider, u as Ga4BrowserConfig } from "./browser-_0LRgTpx.js";
2
- export { BrowserProvider, BrowserTracking, BrowserTrackingOptions, type Ga4BrowserConfig, type MetaBrowserConfig, type PosthogBrowserConfig, TrackOptions, createTracking, ga4, meta, posthog };
1
+ import { a as createTracking, c as MetaBrowserConfig, d as linkedin, f as Ga4BrowserConfig, i as TrackOptions, l as meta, n as BrowserTracking, o as PosthogBrowserConfig, p as ga4, r as BrowserTrackingOptions, s as posthog, t as BrowserProvider, u as LinkedinBrowserConfig } from "./browser-k4gaaQgF.js";
2
+ export { BrowserProvider, BrowserTracking, BrowserTrackingOptions, type Ga4BrowserConfig, type LinkedinBrowserConfig, type MetaBrowserConfig, type PosthogBrowserConfig, TrackOptions, createTracking, ga4, linkedin, meta, posthog };