@hellyeah/x-ray 0.1.0-beta.5
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 +140 -0
- package/dist/astro/index.cjs +48 -0
- package/dist/astro/index.d.cts +36 -0
- package/dist/astro/index.d.ts +36 -0
- package/dist/astro/index.js +6 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.cts +52 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +7 -0
- package/dist/next/index.cjs +145 -0
- package/dist/next/index.d.cts +32 -0
- package/dist/next/index.d.ts +32 -0
- package/dist/next/index.js +105 -0
- package/dist/nuxt/index.cjs +140 -0
- package/dist/nuxt/index.d.cts +33 -0
- package/dist/nuxt/index.d.ts +33 -0
- package/dist/nuxt/index.js +97 -0
- package/dist/react/index.cjs +129 -0
- package/dist/react/index.d.cts +31 -0
- package/dist/react/index.d.ts +31 -0
- package/dist/react/index.js +89 -0
- package/dist/remix/index.cjs +137 -0
- package/dist/remix/index.d.cts +32 -0
- package/dist/remix/index.d.ts +32 -0
- package/dist/remix/index.js +95 -0
- package/dist/server/index.cjs +519 -0
- package/dist/server/index.d.cts +234 -0
- package/dist/server/index.d.ts +234 -0
- package/dist/server/index.js +476 -0
- package/dist/svelte/index.cjs +120 -0
- package/dist/svelte/index.d.cts +31 -0
- package/dist/svelte/index.d.ts +31 -0
- package/dist/svelte/index.js +77 -0
- package/dist/vue/index.cjs +136 -0
- package/dist/vue/index.d.cts +32 -0
- package/dist/vue/index.d.ts +32 -0
- package/dist/vue/index.js +95 -0
- package/package.json +255 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
declare const cv: {
|
|
2
|
+
readonly purchase: "cv_purchase";
|
|
3
|
+
readonly subscribe: "cv_subscribe";
|
|
4
|
+
readonly startTrial: "cv_start_trial";
|
|
5
|
+
readonly leadSubmit: "cv_lead_submit";
|
|
6
|
+
readonly registrationComplete: "cv_registration_complete";
|
|
7
|
+
readonly bookAppointment: "cv_book_appointment";
|
|
8
|
+
readonly contact: "cv_contact";
|
|
9
|
+
readonly submitApplication: "cv_submit_application";
|
|
10
|
+
readonly addToCart: "cv_add_to_cart";
|
|
11
|
+
readonly beginCheckout: "cv_begin_checkout";
|
|
12
|
+
readonly addPaymentInfo: "cv_add_payment_info";
|
|
13
|
+
readonly viewContent: "cv_view_content";
|
|
14
|
+
readonly search: "cv_search";
|
|
15
|
+
};
|
|
16
|
+
type ConversionEvent = (typeof cv)[keyof typeof cv];
|
|
17
|
+
type XRayLogEntry = {
|
|
18
|
+
/** Which SDK operation produced this log. */
|
|
19
|
+
action: "track" | "track_immediate" | "identify" | "flush" | "shutdown" | "enqueue" | "send_batch" | "serverless_detect";
|
|
20
|
+
/** What happened. */
|
|
21
|
+
outcome: "success" | "error" | "drop" | "retry" | "overflow" | "warning";
|
|
22
|
+
/** Human-readable description. */
|
|
23
|
+
message: string;
|
|
24
|
+
/** Event name when relevant. */
|
|
25
|
+
event?: string;
|
|
26
|
+
/** Number of items involved (batch size, queue length). */
|
|
27
|
+
count?: number;
|
|
28
|
+
/** Retry attempt number (1-indexed). */
|
|
29
|
+
attempt?: number;
|
|
30
|
+
/** Total retry attempts configured. */
|
|
31
|
+
maxAttempts?: number;
|
|
32
|
+
/** HTTP status code from server. */
|
|
33
|
+
statusCode?: number;
|
|
34
|
+
/** Error object when outcome is "error". */
|
|
35
|
+
error?: unknown;
|
|
36
|
+
};
|
|
37
|
+
type Attribution = {
|
|
38
|
+
utm_source?: string;
|
|
39
|
+
utm_medium?: string;
|
|
40
|
+
utm_campaign?: string;
|
|
41
|
+
utm_content?: string;
|
|
42
|
+
utm_term?: string;
|
|
43
|
+
gclid?: string;
|
|
44
|
+
fbclid?: string;
|
|
45
|
+
msclkid?: string;
|
|
46
|
+
ttclid?: string;
|
|
47
|
+
li_fat_id?: string;
|
|
48
|
+
twclid?: string;
|
|
49
|
+
};
|
|
50
|
+
type TrackData = {
|
|
51
|
+
/** User identifier. Falls back to the value set via `identify()`. */
|
|
52
|
+
distinctId?: string;
|
|
53
|
+
/** Revenue amount (e.g. `49.99`). Converted to string on the wire. */
|
|
54
|
+
revenue?: number;
|
|
55
|
+
/** ISO 4217 currency code (e.g. `"USD"`). */
|
|
56
|
+
currency?: string;
|
|
57
|
+
/** Arbitrary key-value metadata attached to the event. */
|
|
58
|
+
metadata?: Record<string, string | number | boolean | null>;
|
|
59
|
+
/** Grouping tag for filtering in the dashboard. */
|
|
60
|
+
tag?: string;
|
|
61
|
+
/** Page URL where the event occurred. */
|
|
62
|
+
url?: string;
|
|
63
|
+
/** Hostname of the tracked page (e.g. `"example.com"`). Used for session context. */
|
|
64
|
+
hostname?: string;
|
|
65
|
+
};
|
|
66
|
+
type XRayOptions = {
|
|
67
|
+
/** Base URL of the analytics server. @defaultValue `"https://xray-staging.hellyeahai.com"` */
|
|
68
|
+
host?: string;
|
|
69
|
+
/** Events to batch before flushing. @defaultValue 20 */
|
|
70
|
+
flushAt?: number;
|
|
71
|
+
/** Milliseconds between automatic flushes. @defaultValue 10000 */
|
|
72
|
+
flushInterval?: number;
|
|
73
|
+
/** Maximum events held in memory. Oldest events are dropped when exceeded. @defaultValue 1000 */
|
|
74
|
+
maxQueueSize?: number;
|
|
75
|
+
/** Milliseconds before an HTTP request is aborted. @defaultValue 10000 */
|
|
76
|
+
requestTimeout?: number;
|
|
77
|
+
/** When `true`, all tracking methods become no-ops. @defaultValue false */
|
|
78
|
+
disabled?: boolean;
|
|
79
|
+
/** Custom `fetch` implementation. Useful for proxying or testing. @defaultValue globalThis.fetch */
|
|
80
|
+
fetch?: typeof fetch;
|
|
81
|
+
/** Custom logger callback. Receives structured log entries. */
|
|
82
|
+
logger?: (entry: XRayLogEntry) => void;
|
|
83
|
+
/** Session-scoped attribution fields (UTM params, click IDs) applied to every event. */
|
|
84
|
+
context?: Attribution;
|
|
85
|
+
/** Serverless lifecycle hook — pass your platform's `waitUntil` to ensure flushes complete after the response. */
|
|
86
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
87
|
+
/** @internal */
|
|
88
|
+
retryDelay?: number;
|
|
89
|
+
};
|
|
90
|
+
type IdentifyParams = {
|
|
91
|
+
/** Unique user identifier used as the default for subsequent `track()` calls. */
|
|
92
|
+
distinctId: string;
|
|
93
|
+
/** User traits to associate with this identifier. */
|
|
94
|
+
properties?: Record<string, string | number | boolean | null>;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Wire-format payload for a single queued event.
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
type QueueItem = {
|
|
101
|
+
website: string;
|
|
102
|
+
name: string;
|
|
103
|
+
id: string;
|
|
104
|
+
hy_event_id: string;
|
|
105
|
+
revenue?: string;
|
|
106
|
+
currency?: string;
|
|
107
|
+
tag?: string;
|
|
108
|
+
url?: string;
|
|
109
|
+
hostname?: string;
|
|
110
|
+
utm_source?: string;
|
|
111
|
+
utm_medium?: string;
|
|
112
|
+
utm_campaign?: string;
|
|
113
|
+
utm_content?: string;
|
|
114
|
+
utm_term?: string;
|
|
115
|
+
gclid?: string;
|
|
116
|
+
fbclid?: string;
|
|
117
|
+
msclkid?: string;
|
|
118
|
+
ttclid?: string;
|
|
119
|
+
li_fat_id?: string;
|
|
120
|
+
twclid?: string;
|
|
121
|
+
data?: Record<string, string | number | boolean | null>;
|
|
122
|
+
};
|
|
123
|
+
/** @internal Resolved internal configuration. */
|
|
124
|
+
type XRayConfig = {
|
|
125
|
+
websiteId: string;
|
|
126
|
+
host: string;
|
|
127
|
+
flushAt: number;
|
|
128
|
+
flushInterval: number;
|
|
129
|
+
maxQueueSize: number;
|
|
130
|
+
requestTimeout: number;
|
|
131
|
+
disabled: boolean;
|
|
132
|
+
retryDelay: number;
|
|
133
|
+
context: Attribution;
|
|
134
|
+
waitUntil: ((promise: Promise<unknown>) => void) | null;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Server-side tracking SDK for x-ray analytics.
|
|
138
|
+
*
|
|
139
|
+
* Buffers events in memory and flushes them in batches to the analytics server.
|
|
140
|
+
* A background timer flushes automatically at the configured interval, making
|
|
141
|
+
* this suitable for long-running Node/Bun processes.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const xray = new XRay("site_abc123");
|
|
146
|
+
*
|
|
147
|
+
* xray.identify({ distinctId: "user_42" });
|
|
148
|
+
* xray.track("signup");
|
|
149
|
+
*
|
|
150
|
+
* // On process exit
|
|
151
|
+
* await xray.shutdown();
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* The flush timer is unref'd so it won't keep a Node process alive. In
|
|
156
|
+
* serverless/edge runtimes where the process may exit after a single request,
|
|
157
|
+
* use {@link trackImmediate} or call {@link shutdown} before returning.
|
|
158
|
+
*/
|
|
159
|
+
declare class XRay {
|
|
160
|
+
private readonly queue;
|
|
161
|
+
private timer;
|
|
162
|
+
private defaultDistinctId?;
|
|
163
|
+
private logFn;
|
|
164
|
+
private flushing;
|
|
165
|
+
private readonly fetchFn;
|
|
166
|
+
private shutdownCalled;
|
|
167
|
+
private readonly cfg;
|
|
168
|
+
/**
|
|
169
|
+
* @param websiteId - Your site identifier. Falls back to `XRAY_WEBSITE_ID` env var.
|
|
170
|
+
* @param options - SDK configuration. See {@link XRayOptions}.
|
|
171
|
+
*/
|
|
172
|
+
constructor(websiteId?: string, options?: XRayOptions);
|
|
173
|
+
/**
|
|
174
|
+
* Queue a custom event for batched delivery.
|
|
175
|
+
*
|
|
176
|
+
* @param event - Name of the event (e.g. `"signup"`, `"purchase"`).
|
|
177
|
+
* @param data - Optional event data including distinctId, revenue, metadata, etc.
|
|
178
|
+
*
|
|
179
|
+
* @remarks
|
|
180
|
+
* Events are buffered in memory and flushed automatically when the queue
|
|
181
|
+
* reaches `flushAt` or on the next `flushInterval` tick.
|
|
182
|
+
*/
|
|
183
|
+
track(event: string, data?: TrackData): void;
|
|
184
|
+
/**
|
|
185
|
+
* Send a single event immediately, bypassing the queue.
|
|
186
|
+
*
|
|
187
|
+
* @param event - Name of the event (e.g. `"signup"`, `"purchase"`).
|
|
188
|
+
* @param data - Optional event data including distinctId, revenue, metadata, etc.
|
|
189
|
+
*
|
|
190
|
+
* @remarks
|
|
191
|
+
* Use this in serverless/edge runtimes where the process may exit before the
|
|
192
|
+
* next flush tick. For long-running servers, prefer {@link track} for better
|
|
193
|
+
* batching efficiency.
|
|
194
|
+
*/
|
|
195
|
+
trackImmediate(event: string, data?: TrackData): Promise<void>;
|
|
196
|
+
/** Set the default distinctId for subsequent track() calls. */
|
|
197
|
+
identify(params: IdentifyParams): void;
|
|
198
|
+
/**
|
|
199
|
+
* Drain all queued events immediately.
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* On network failure the failed batch is re-queued at the front so no events
|
|
203
|
+
* are lost. Concurrent calls are deduplicated — only one flush runs at a time.
|
|
204
|
+
*/
|
|
205
|
+
flush(): Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* Stop the flush timer and send all remaining events.
|
|
208
|
+
*
|
|
209
|
+
* @param timeoutMs - Maximum time to wait for the final flush. @defaultValue 5000
|
|
210
|
+
* @remarks
|
|
211
|
+
* Safe to call multiple times — subsequent calls are no-ops.
|
|
212
|
+
*/
|
|
213
|
+
shutdown(timeoutMs?: number): Promise<void>;
|
|
214
|
+
/** Toggle debug logging to console. When enabled, logs structured entries as JSON to console.log. */
|
|
215
|
+
debug(enabled: boolean): void;
|
|
216
|
+
private enqueue;
|
|
217
|
+
private sendBatch;
|
|
218
|
+
private buildItem;
|
|
219
|
+
private sanitizeProperties;
|
|
220
|
+
private resolveWaitUntil;
|
|
221
|
+
private log;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get or create a shared XRay singleton.
|
|
225
|
+
*
|
|
226
|
+
* @param websiteId - Falls back to `XRAY_WEBSITE_ID` env var.
|
|
227
|
+
* @param options - Ignored when an instance already exists.
|
|
228
|
+
*
|
|
229
|
+
* @remarks
|
|
230
|
+
* Uses a `Symbol.for` key on `globalThis` so the instance survives HMR
|
|
231
|
+
* reloads and multiple import paths.
|
|
232
|
+
*/
|
|
233
|
+
declare const createXRay: (websiteId?: string, options?: XRayOptions) => XRay;
|
|
234
|
+
export { cv, createXRay, XRayOptions, XRayLogEntry, XRayConfig, XRay, TrackData, QueueItem, IdentifyParams, ConversionEvent, Attribution };
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
declare const cv: {
|
|
2
|
+
readonly purchase: "cv_purchase";
|
|
3
|
+
readonly subscribe: "cv_subscribe";
|
|
4
|
+
readonly startTrial: "cv_start_trial";
|
|
5
|
+
readonly leadSubmit: "cv_lead_submit";
|
|
6
|
+
readonly registrationComplete: "cv_registration_complete";
|
|
7
|
+
readonly bookAppointment: "cv_book_appointment";
|
|
8
|
+
readonly contact: "cv_contact";
|
|
9
|
+
readonly submitApplication: "cv_submit_application";
|
|
10
|
+
readonly addToCart: "cv_add_to_cart";
|
|
11
|
+
readonly beginCheckout: "cv_begin_checkout";
|
|
12
|
+
readonly addPaymentInfo: "cv_add_payment_info";
|
|
13
|
+
readonly viewContent: "cv_view_content";
|
|
14
|
+
readonly search: "cv_search";
|
|
15
|
+
};
|
|
16
|
+
type ConversionEvent = (typeof cv)[keyof typeof cv];
|
|
17
|
+
type XRayLogEntry = {
|
|
18
|
+
/** Which SDK operation produced this log. */
|
|
19
|
+
action: "track" | "track_immediate" | "identify" | "flush" | "shutdown" | "enqueue" | "send_batch" | "serverless_detect";
|
|
20
|
+
/** What happened. */
|
|
21
|
+
outcome: "success" | "error" | "drop" | "retry" | "overflow" | "warning";
|
|
22
|
+
/** Human-readable description. */
|
|
23
|
+
message: string;
|
|
24
|
+
/** Event name when relevant. */
|
|
25
|
+
event?: string;
|
|
26
|
+
/** Number of items involved (batch size, queue length). */
|
|
27
|
+
count?: number;
|
|
28
|
+
/** Retry attempt number (1-indexed). */
|
|
29
|
+
attempt?: number;
|
|
30
|
+
/** Total retry attempts configured. */
|
|
31
|
+
maxAttempts?: number;
|
|
32
|
+
/** HTTP status code from server. */
|
|
33
|
+
statusCode?: number;
|
|
34
|
+
/** Error object when outcome is "error". */
|
|
35
|
+
error?: unknown;
|
|
36
|
+
};
|
|
37
|
+
type Attribution = {
|
|
38
|
+
utm_source?: string;
|
|
39
|
+
utm_medium?: string;
|
|
40
|
+
utm_campaign?: string;
|
|
41
|
+
utm_content?: string;
|
|
42
|
+
utm_term?: string;
|
|
43
|
+
gclid?: string;
|
|
44
|
+
fbclid?: string;
|
|
45
|
+
msclkid?: string;
|
|
46
|
+
ttclid?: string;
|
|
47
|
+
li_fat_id?: string;
|
|
48
|
+
twclid?: string;
|
|
49
|
+
};
|
|
50
|
+
type TrackData = {
|
|
51
|
+
/** User identifier. Falls back to the value set via `identify()`. */
|
|
52
|
+
distinctId?: string;
|
|
53
|
+
/** Revenue amount (e.g. `49.99`). Converted to string on the wire. */
|
|
54
|
+
revenue?: number;
|
|
55
|
+
/** ISO 4217 currency code (e.g. `"USD"`). */
|
|
56
|
+
currency?: string;
|
|
57
|
+
/** Arbitrary key-value metadata attached to the event. */
|
|
58
|
+
metadata?: Record<string, string | number | boolean | null>;
|
|
59
|
+
/** Grouping tag for filtering in the dashboard. */
|
|
60
|
+
tag?: string;
|
|
61
|
+
/** Page URL where the event occurred. */
|
|
62
|
+
url?: string;
|
|
63
|
+
/** Hostname of the tracked page (e.g. `"example.com"`). Used for session context. */
|
|
64
|
+
hostname?: string;
|
|
65
|
+
};
|
|
66
|
+
type XRayOptions = {
|
|
67
|
+
/** Base URL of the analytics server. @defaultValue `"https://xray-staging.hellyeahai.com"` */
|
|
68
|
+
host?: string;
|
|
69
|
+
/** Events to batch before flushing. @defaultValue 20 */
|
|
70
|
+
flushAt?: number;
|
|
71
|
+
/** Milliseconds between automatic flushes. @defaultValue 10000 */
|
|
72
|
+
flushInterval?: number;
|
|
73
|
+
/** Maximum events held in memory. Oldest events are dropped when exceeded. @defaultValue 1000 */
|
|
74
|
+
maxQueueSize?: number;
|
|
75
|
+
/** Milliseconds before an HTTP request is aborted. @defaultValue 10000 */
|
|
76
|
+
requestTimeout?: number;
|
|
77
|
+
/** When `true`, all tracking methods become no-ops. @defaultValue false */
|
|
78
|
+
disabled?: boolean;
|
|
79
|
+
/** Custom `fetch` implementation. Useful for proxying or testing. @defaultValue globalThis.fetch */
|
|
80
|
+
fetch?: typeof fetch;
|
|
81
|
+
/** Custom logger callback. Receives structured log entries. */
|
|
82
|
+
logger?: (entry: XRayLogEntry) => void;
|
|
83
|
+
/** Session-scoped attribution fields (UTM params, click IDs) applied to every event. */
|
|
84
|
+
context?: Attribution;
|
|
85
|
+
/** Serverless lifecycle hook — pass your platform's `waitUntil` to ensure flushes complete after the response. */
|
|
86
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
87
|
+
/** @internal */
|
|
88
|
+
retryDelay?: number;
|
|
89
|
+
};
|
|
90
|
+
type IdentifyParams = {
|
|
91
|
+
/** Unique user identifier used as the default for subsequent `track()` calls. */
|
|
92
|
+
distinctId: string;
|
|
93
|
+
/** User traits to associate with this identifier. */
|
|
94
|
+
properties?: Record<string, string | number | boolean | null>;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Wire-format payload for a single queued event.
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
type QueueItem = {
|
|
101
|
+
website: string;
|
|
102
|
+
name: string;
|
|
103
|
+
id: string;
|
|
104
|
+
hy_event_id: string;
|
|
105
|
+
revenue?: string;
|
|
106
|
+
currency?: string;
|
|
107
|
+
tag?: string;
|
|
108
|
+
url?: string;
|
|
109
|
+
hostname?: string;
|
|
110
|
+
utm_source?: string;
|
|
111
|
+
utm_medium?: string;
|
|
112
|
+
utm_campaign?: string;
|
|
113
|
+
utm_content?: string;
|
|
114
|
+
utm_term?: string;
|
|
115
|
+
gclid?: string;
|
|
116
|
+
fbclid?: string;
|
|
117
|
+
msclkid?: string;
|
|
118
|
+
ttclid?: string;
|
|
119
|
+
li_fat_id?: string;
|
|
120
|
+
twclid?: string;
|
|
121
|
+
data?: Record<string, string | number | boolean | null>;
|
|
122
|
+
};
|
|
123
|
+
/** @internal Resolved internal configuration. */
|
|
124
|
+
type XRayConfig = {
|
|
125
|
+
websiteId: string;
|
|
126
|
+
host: string;
|
|
127
|
+
flushAt: number;
|
|
128
|
+
flushInterval: number;
|
|
129
|
+
maxQueueSize: number;
|
|
130
|
+
requestTimeout: number;
|
|
131
|
+
disabled: boolean;
|
|
132
|
+
retryDelay: number;
|
|
133
|
+
context: Attribution;
|
|
134
|
+
waitUntil: ((promise: Promise<unknown>) => void) | null;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Server-side tracking SDK for x-ray analytics.
|
|
138
|
+
*
|
|
139
|
+
* Buffers events in memory and flushes them in batches to the analytics server.
|
|
140
|
+
* A background timer flushes automatically at the configured interval, making
|
|
141
|
+
* this suitable for long-running Node/Bun processes.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const xray = new XRay("site_abc123");
|
|
146
|
+
*
|
|
147
|
+
* xray.identify({ distinctId: "user_42" });
|
|
148
|
+
* xray.track("signup");
|
|
149
|
+
*
|
|
150
|
+
* // On process exit
|
|
151
|
+
* await xray.shutdown();
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* The flush timer is unref'd so it won't keep a Node process alive. In
|
|
156
|
+
* serverless/edge runtimes where the process may exit after a single request,
|
|
157
|
+
* use {@link trackImmediate} or call {@link shutdown} before returning.
|
|
158
|
+
*/
|
|
159
|
+
declare class XRay {
|
|
160
|
+
private readonly queue;
|
|
161
|
+
private timer;
|
|
162
|
+
private defaultDistinctId?;
|
|
163
|
+
private logFn;
|
|
164
|
+
private flushing;
|
|
165
|
+
private readonly fetchFn;
|
|
166
|
+
private shutdownCalled;
|
|
167
|
+
private readonly cfg;
|
|
168
|
+
/**
|
|
169
|
+
* @param websiteId - Your site identifier. Falls back to `XRAY_WEBSITE_ID` env var.
|
|
170
|
+
* @param options - SDK configuration. See {@link XRayOptions}.
|
|
171
|
+
*/
|
|
172
|
+
constructor(websiteId?: string, options?: XRayOptions);
|
|
173
|
+
/**
|
|
174
|
+
* Queue a custom event for batched delivery.
|
|
175
|
+
*
|
|
176
|
+
* @param event - Name of the event (e.g. `"signup"`, `"purchase"`).
|
|
177
|
+
* @param data - Optional event data including distinctId, revenue, metadata, etc.
|
|
178
|
+
*
|
|
179
|
+
* @remarks
|
|
180
|
+
* Events are buffered in memory and flushed automatically when the queue
|
|
181
|
+
* reaches `flushAt` or on the next `flushInterval` tick.
|
|
182
|
+
*/
|
|
183
|
+
track(event: string, data?: TrackData): void;
|
|
184
|
+
/**
|
|
185
|
+
* Send a single event immediately, bypassing the queue.
|
|
186
|
+
*
|
|
187
|
+
* @param event - Name of the event (e.g. `"signup"`, `"purchase"`).
|
|
188
|
+
* @param data - Optional event data including distinctId, revenue, metadata, etc.
|
|
189
|
+
*
|
|
190
|
+
* @remarks
|
|
191
|
+
* Use this in serverless/edge runtimes where the process may exit before the
|
|
192
|
+
* next flush tick. For long-running servers, prefer {@link track} for better
|
|
193
|
+
* batching efficiency.
|
|
194
|
+
*/
|
|
195
|
+
trackImmediate(event: string, data?: TrackData): Promise<void>;
|
|
196
|
+
/** Set the default distinctId for subsequent track() calls. */
|
|
197
|
+
identify(params: IdentifyParams): void;
|
|
198
|
+
/**
|
|
199
|
+
* Drain all queued events immediately.
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* On network failure the failed batch is re-queued at the front so no events
|
|
203
|
+
* are lost. Concurrent calls are deduplicated — only one flush runs at a time.
|
|
204
|
+
*/
|
|
205
|
+
flush(): Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* Stop the flush timer and send all remaining events.
|
|
208
|
+
*
|
|
209
|
+
* @param timeoutMs - Maximum time to wait for the final flush. @defaultValue 5000
|
|
210
|
+
* @remarks
|
|
211
|
+
* Safe to call multiple times — subsequent calls are no-ops.
|
|
212
|
+
*/
|
|
213
|
+
shutdown(timeoutMs?: number): Promise<void>;
|
|
214
|
+
/** Toggle debug logging to console. When enabled, logs structured entries as JSON to console.log. */
|
|
215
|
+
debug(enabled: boolean): void;
|
|
216
|
+
private enqueue;
|
|
217
|
+
private sendBatch;
|
|
218
|
+
private buildItem;
|
|
219
|
+
private sanitizeProperties;
|
|
220
|
+
private resolveWaitUntil;
|
|
221
|
+
private log;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get or create a shared XRay singleton.
|
|
225
|
+
*
|
|
226
|
+
* @param websiteId - Falls back to `XRAY_WEBSITE_ID` env var.
|
|
227
|
+
* @param options - Ignored when an instance already exists.
|
|
228
|
+
*
|
|
229
|
+
* @remarks
|
|
230
|
+
* Uses a `Symbol.for` key on `globalThis` so the instance survives HMR
|
|
231
|
+
* reloads and multiple import paths.
|
|
232
|
+
*/
|
|
233
|
+
declare const createXRay: (websiteId?: string, options?: XRayOptions) => XRay;
|
|
234
|
+
export { cv, createXRay, XRayOptions, XRayLogEntry, XRayConfig, XRay, TrackData, QueueItem, IdentifyParams, ConversionEvent, Attribution };
|