tracklane 0.1.0 → 0.2.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.
@@ -1,152 +0,0 @@
1
- import { c as UserData, i as EventData, n as ConsentState, o as ProviderDefault, r as EventBinding, s as TrackingError, t as ActionSource } from "./vocabulary-ByyXHVWd.js";
2
- //#region src/providers/ga4.server.d.ts
3
- /** Credentials for the GA4 Measurement Protocol. */
4
- interface Ga4ServerCredentials {
5
- /** The `G-` id of the data stream. */
6
- measurementId: string;
7
- /** Created under Admin → Data Streams → Measurement Protocol. */
8
- apiSecret: string;
9
- }
10
- /** Optional configuration for the GA4 server provider. */
11
- interface Ga4ServerConfig {
12
- events?: Record<string, EventBinding<string>>;
13
- }
14
- /**
15
- * Google Analytics 4 on the server, through the Measurement Protocol.
16
- *
17
- * @param credentials - The measurement id and API secret.
18
- * @param config - Rarely needed event name overrides.
19
- * @returns A provider for `createTracking` from `tracklane/server`.
20
- *
21
- * @example
22
- * ```ts
23
- * import { createTracking, ga4 } from 'tracklane/server';
24
- *
25
- * const { track } = createTracking({
26
- * providers: [ga4({ measurementId: 'G-XXXXXXX', apiSecret: process.env.GA4_SECRET! })],
27
- * });
28
- *
29
- * await track('purchase', order, { cookies: request.headers.get('cookie') });
30
- * ```
31
- */
32
- declare function ga4(credentials: Ga4ServerCredentials, config?: Ga4ServerConfig): ServerProvider;
33
- //#endregion
34
- //#region src/server.d.ts
35
- /**
36
- * Everything a conversion API needs beyond the event itself: who the person
37
- * is, when it happened, and where it was observed.
38
- *
39
- * None of this is "what happened", which is why it does not travel in the
40
- * event data — putting it there would leak identity into the pass-through
41
- * event params of the vendors that forward the payload as-is.
42
- */
43
- interface EventContext {
44
- user?: UserData;
45
- /**
46
- * The request's raw `Cookie` header, or an already-parsed map.
47
- *
48
- * These are cookies the vendors' own browser tags set — this library never
49
- * writes one. On the server each adapter reads the cookies belonging to
50
- * its own vendor: Meta forwards its value as-is, Google's holds several
51
- * things at once and has to be opened. That knowledge lives in the
52
- * adapters; the core only splits `name=value; name=value` into pairs.
53
- *
54
- * **It splits, it does not interpret.** Values are handed over exactly as
55
- * they appear, with no percent-decoding. The cookies these vendors set do
56
- * not need it; a host reading some other cookie should decode it itself.
57
- */
58
- cookies?: string | Record<string, string> | null;
59
- /** Ties this send to a browser hit. Never invented by the library. */
60
- dedupId?: string;
61
- /**
62
- * When the conversion actually happened. Defaults to now.
63
- *
64
- * A webhook arrives after the fact and LinkedIn rejects conversions older
65
- * than 90 days, so reporting "now" for everything would quietly distort
66
- * attribution.
67
- */
68
- timestamp?: number | Date;
69
- /** Overrides the factory default. Meta requires it on every event. */
70
- source?: ActionSource;
71
- url?: string;
72
- ip?: string;
73
- userAgent?: string;
74
- /** What is known *about* the person: GA4 user properties, PostHog `$set`. */
75
- traits?: Record<string, unknown>;
76
- /**
77
- * Travels inside the event, for the vendors that document such a field.
78
- * Today that is GA4's Measurement Protocol, and it reads two of the
79
- * signals; the others have no slot and ignore it.
80
- */
81
- consent?: ConsentState;
82
- }
83
- /** The context an adapter receives, with the ambiguity resolved. */
84
- interface ResolvedContext extends Omit<EventContext, "cookies" | "timestamp"> {
85
- cookies: Record<string, string>;
86
- /** Epoch milliseconds. Adapters convert to their vendor's spelling. */
87
- timestamp: number;
88
- }
89
- /**
90
- * A destination for server events.
91
- *
92
- * `track` may throw — on a non-2xx, or where a vendor documents a
93
- * precondition the event cannot meet. The dispatcher isolates and reports
94
- * it, so adapters stay honest and loud.
95
- *
96
- * `report` is for a caveat about a request that already succeeded. It is
97
- * never a throw: by then the send happened, and throwing would tell a host's
98
- * retry logic to resend a delivered conversion.
99
- */
100
- interface ServerProvider<Target = string> {
101
- name: string;
102
- default: ProviderDefault;
103
- events?: Record<string, EventBinding<Target>>;
104
- track(name: Target, data: EventData, context: ResolvedContext, report: (message: string) => void): Promise<void>;
105
- }
106
- /** Options accepted by {@link createTracking}. */
107
- interface ServerTrackingOptions {
108
- providers: readonly ServerProvider[];
109
- onError?: (error: TrackingError) => void;
110
- }
111
- /** What {@link createTracking} returns. */
112
- interface ServerTracking {
113
- /**
114
- * Sends one event to every configured conversion API.
115
- *
116
- * Resolves once every provider has settled and never rejects: one vendor
117
- * being down is not the caller's failure to handle. Awaiting is about the
118
- * request surviving a serverless runtime, not about delivery being
119
- * guaranteed.
120
- */
121
- track(name: string, data?: EventData, context?: EventContext): Promise<void>;
122
- }
123
- /**
124
- * Creates the server tracking surface.
125
- *
126
- * There is no `identify` here and nothing is held between calls: a server
127
- * instance is shared by every request, so a retained identity would attach
128
- * one visitor to another visitor's conversion. Identity travels with the
129
- * call, which is also what every conversion API expects.
130
- *
131
- * There is no `consent` call either — consent commands are properties of a
132
- * vendor's on-page tag, and a server request has no tag. The one vendor that
133
- * accepts consent server-side reads it from the context.
134
- *
135
- * @param options - The providers to send to, and an optional error channel.
136
- * @returns The `track` call.
137
- *
138
- * @example
139
- * ```ts
140
- * import { createTracking, ga4 } from 'tracklane/server';
141
- *
142
- * const { track } = createTracking({
143
- * providers: [ga4({ measurementId: 'G-XXXXXXX', apiSecret })],
144
- * });
145
- *
146
- * await track('purchase', order, { cookies: request.headers.get('cookie') });
147
- * ```
148
- */
149
- declare function createTracking(options: ServerTrackingOptions): ServerTracking;
150
- //#endregion
151
- export { ServerTrackingOptions as a, Ga4ServerCredentials as c, ServerTracking as i, ga4 as l, ResolvedContext as n, createTracking as o, ServerProvider as r, Ga4ServerConfig as s, EventContext as t };
152
- //# sourceMappingURL=server-cNxLsKhl.d.ts.map
@@ -1,107 +0,0 @@
1
- //#region src/vocabulary.d.ts
2
- /**
3
- * The vocabulary shared by the browser and server libraries.
4
- *
5
- * These two libraries never talk to each other — no runtime, no state, no
6
- * instance in common. What they share is this: the names of events and the
7
- * shape of the data that travels with them, so that `purchase` means the
8
- * same thing on both sides. It is the only sharing with a reason to exist.
9
- */
10
- /** One item inside an ecommerce event, spelled the way GA4 spells it. */
11
- interface EventItem {
12
- item_id?: string;
13
- item_name?: string;
14
- price?: number;
15
- quantity?: number;
16
- [key: string]: unknown;
17
- }
18
- /**
19
- * The business payload of an event.
20
- *
21
- * The named fields are the ones adapters read to build vendor-specific value
22
- * and content slots. The index signature is deliberate: a business measures
23
- * things this vocabulary does not name, and closing the bag would make the
24
- * library the arbiter of what may be measured.
25
- */
26
- interface EventData {
27
- transaction_id?: string;
28
- value?: number;
29
- currency?: string;
30
- items?: EventItem[];
31
- [key: string]: unknown;
32
- }
33
- /**
34
- * Who the person is.
35
- *
36
- * One identifier for the person, which every vendor receives under its own
37
- * name. Values are always raw — hashing and normalisation are field formats
38
- * each vendor defines, applied inside the adapter that owns the field.
39
- *
40
- * Everything else that identifies someone arrives through cookies on the
41
- * server, read by whichever adapter knows the format.
42
- */
43
- interface UserData {
44
- /** One id for the person, translated per vendor. */
45
- userId?: string;
46
- email?: string;
47
- phone?: string;
48
- firstName?: string;
49
- lastName?: string;
50
- /** From the URL rather than a cookie, which is why it is named here. */
51
- twclid?: string;
52
- }
53
- /**
54
- * Consent signals, in Google's own spelling.
55
- *
56
- * Google's is the most granular surface any of the five vendors exposes, so
57
- * every other vendor receives a *collapse* of it. Carrying the finest
58
- * resolution and reducing per vendor means a projection never claims more
59
- * than the host declared — expanding a coarse answer into fine signals would
60
- * invent information, and this library never does that.
61
- *
62
- * An absent signal produces no key: silence is not a denial, and converting
63
- * it into one would put words in the visitor's mouth just as a grant would.
64
- */
65
- interface ConsentState {
66
- ad_storage?: "granted" | "denied";
67
- analytics_storage?: "granted" | "denied";
68
- ad_user_data?: "granted" | "denied";
69
- ad_personalization?: "granted" | "denied";
70
- }
71
- /**
72
- * Where a conversion happened.
73
- *
74
- * Meta's vocabulary, adopted verbatim — it is the only vendor of the five
75
- * that documents the concept, and it requires the field on every server
76
- * event. Inventing a taxonomy and translating it would be both incomplete
77
- * for Meta and meaningless to everyone else.
78
- */
79
- type ActionSource = "website" | "app" | "email" | "phone_call" | "chat" | "physical_store" | "system_generated" | "business_messaging" | "other";
80
- /**
81
- * How a canonical event name is spelled for one vendor, or `null` to say
82
- * "never send this event here".
83
- */
84
- type EventBinding<Target> = Target | null;
85
- /** What a provider does with a canonical event it has no binding for. */
86
- type ProviderDefault = "passthrough" | "ignore";
87
- /**
88
- * Reported out of band, never thrown at the call site.
89
- *
90
- * Fanning out to N vendors means no single call site can catch anything, so
91
- * this is the replica of the `try/catch` a host would have written around a
92
- * hand-made call. `severity` separates "this did not arrive" from "this
93
- * arrived, and here is something you should know".
94
- *
95
- * It never carries event contents: the payload holds raw personal data by
96
- * design, and no library-owned surface re-emits it into a host's logs.
97
- */
98
- interface TrackingError {
99
- provider: string;
100
- event: string;
101
- severity: "error" | "warning";
102
- message: string;
103
- cause?: unknown;
104
- }
105
- //#endregion
106
- export { EventItem as a, UserData as c, EventData as i, ConsentState as n, ProviderDefault as o, EventBinding as r, TrackingError as s, ActionSource as t };
107
- //# sourceMappingURL=vocabulary-ByyXHVWd.d.ts.map