@aranova/tracking-react 0.11.0 → 0.12.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 +35 -24
- package/dist/index.d.mts +304 -306
- package/dist/index.d.ts +304 -306
- package/dist/index.js +237 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -17
- package/dist/index.mjs.map +1 -1
- package/dist/phone-utils-CVX7JmqB.d.mts +343 -0
- package/dist/phone-utils-CVX7JmqB.d.ts +343 -0
- package/dist/phone.d.mts +3 -0
- package/dist/phone.d.ts +3 -0
- package/dist/phone.js +318 -0
- package/dist/phone.js.map +1 -0
- package/dist/phone.mjs +286 -0
- package/dist/phone.mjs.map +1 -0
- package/package.json +7 -1
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* JSON-serializable value accepted by `form_submit.fields[].value`.
|
|
6
|
+
*
|
|
7
|
+
* This intentionally excludes `undefined`, functions, symbols, `Date`
|
|
8
|
+
* instances, and non-finite numbers. Values are stored in PostgreSQL JSONB, so
|
|
9
|
+
* consumers should send only data that has a stable JSON representation.
|
|
10
|
+
*/
|
|
11
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
12
|
+
[key: string]: JsonValue;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Metadata for a manually fired `form_submit` event.
|
|
16
|
+
*
|
|
17
|
+
* Register the event with `manual: { form_submit: {} }`, then call
|
|
18
|
+
* `trackEvent('form_submit', metadata)` from the host site's submit handler.
|
|
19
|
+
*
|
|
20
|
+
* `fields` is optional. If present, each field value must be JSON-serializable
|
|
21
|
+
* and should be explicitly allowlisted by the integration. Do not send names,
|
|
22
|
+
* emails, visitor phone numbers, addresses, payment data, medical details,
|
|
23
|
+
* passwords, file contents, or free-text messages.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* tracking.trackEvent('form_submit', {
|
|
28
|
+
* form: {
|
|
29
|
+
* id: 'lead-form',
|
|
30
|
+
* action: '/api/lead',
|
|
31
|
+
* fields: [
|
|
32
|
+
* {
|
|
33
|
+
* name: 'service_interest',
|
|
34
|
+
* type: 'select',
|
|
35
|
+
* label: 'Service interest',
|
|
36
|
+
* value: 'teeth_whitening',
|
|
37
|
+
* },
|
|
38
|
+
* ],
|
|
39
|
+
* },
|
|
40
|
+
* page: { path: window.location.pathname },
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare const formSubmitMetadataSchema: z.ZodObject<{
|
|
45
|
+
form: z.ZodObject<{
|
|
46
|
+
id: z.ZodString;
|
|
47
|
+
action: z.ZodNullable<z.ZodString>;
|
|
48
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
49
|
+
name: z.ZodString;
|
|
50
|
+
type: z.ZodString;
|
|
51
|
+
label: z.ZodNullable<z.ZodString>;
|
|
52
|
+
value: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
53
|
+
}, "strict", z.ZodTypeAny, {
|
|
54
|
+
value: JsonValue;
|
|
55
|
+
type: string;
|
|
56
|
+
name: string;
|
|
57
|
+
label: string | null;
|
|
58
|
+
}, {
|
|
59
|
+
value: JsonValue;
|
|
60
|
+
type: string;
|
|
61
|
+
name: string;
|
|
62
|
+
label: string | null;
|
|
63
|
+
}>, "many">>;
|
|
64
|
+
}, "strict", z.ZodTypeAny, {
|
|
65
|
+
id: string;
|
|
66
|
+
action: string | null;
|
|
67
|
+
fields?: {
|
|
68
|
+
value: JsonValue;
|
|
69
|
+
type: string;
|
|
70
|
+
name: string;
|
|
71
|
+
label: string | null;
|
|
72
|
+
}[] | undefined;
|
|
73
|
+
}, {
|
|
74
|
+
id: string;
|
|
75
|
+
action: string | null;
|
|
76
|
+
fields?: {
|
|
77
|
+
value: JsonValue;
|
|
78
|
+
type: string;
|
|
79
|
+
name: string;
|
|
80
|
+
label: string | null;
|
|
81
|
+
}[] | undefined;
|
|
82
|
+
}>;
|
|
83
|
+
page: z.ZodObject<{
|
|
84
|
+
path: z.ZodString;
|
|
85
|
+
}, "strict", z.ZodTypeAny, {
|
|
86
|
+
path: string;
|
|
87
|
+
}, {
|
|
88
|
+
path: string;
|
|
89
|
+
}>;
|
|
90
|
+
}, "strict", z.ZodTypeAny, {
|
|
91
|
+
form: {
|
|
92
|
+
id: string;
|
|
93
|
+
action: string | null;
|
|
94
|
+
fields?: {
|
|
95
|
+
value: JsonValue;
|
|
96
|
+
type: string;
|
|
97
|
+
name: string;
|
|
98
|
+
label: string | null;
|
|
99
|
+
}[] | undefined;
|
|
100
|
+
};
|
|
101
|
+
page: {
|
|
102
|
+
path: string;
|
|
103
|
+
};
|
|
104
|
+
}, {
|
|
105
|
+
form: {
|
|
106
|
+
id: string;
|
|
107
|
+
action: string | null;
|
|
108
|
+
fields?: {
|
|
109
|
+
value: JsonValue;
|
|
110
|
+
type: string;
|
|
111
|
+
name: string;
|
|
112
|
+
label: string | null;
|
|
113
|
+
}[] | undefined;
|
|
114
|
+
};
|
|
115
|
+
page: {
|
|
116
|
+
path: string;
|
|
117
|
+
};
|
|
118
|
+
}>;
|
|
119
|
+
type FormSubmitMetadata = z.infer<typeof formSubmitMetadataSchema>;
|
|
120
|
+
/**
|
|
121
|
+
* Registration config for `form_submit`.
|
|
122
|
+
*
|
|
123
|
+
* This event is manual-only and currently has no registration options. The
|
|
124
|
+
* empty object enables typed `trackEvent('form_submit', ...)` calls.
|
|
125
|
+
*/
|
|
126
|
+
declare const formSubmitConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
127
|
+
type FormSubmitConfig = z.infer<typeof formSubmitConfigSchema>;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* How a phone number is shown in the UI. The transmitted value is always E.164
|
|
131
|
+
* and is deliberately NOT part of this — only the display format is configurable.
|
|
132
|
+
* A function form covers the long tail (`(parsed) => string`).
|
|
133
|
+
*/
|
|
134
|
+
type PhoneDisplayFormat = 'national' | 'international' | 'e164' | ((parsed: ParsedPhone) => string);
|
|
135
|
+
interface ParsedPhone {
|
|
136
|
+
/** E.164 (`"+14165550199"`) or `null` when the input isn't a valid number. This is what gets transmitted. */
|
|
137
|
+
e164: string | null;
|
|
138
|
+
/** National display form (`"(416) 555-0199"`); empty string when unparseable. */
|
|
139
|
+
national: string;
|
|
140
|
+
/** International display form (`"+1 416 555 0199"`); empty string when unparseable. */
|
|
141
|
+
international: string;
|
|
142
|
+
/** ISO-3166 country resolved by libphonenumber, or `null`. */
|
|
143
|
+
country: CountryCode | null;
|
|
144
|
+
isValid: boolean;
|
|
145
|
+
}
|
|
146
|
+
/** Region assumed for numbers typed without a country code. */
|
|
147
|
+
declare const DEFAULT_PHONE_COUNTRY: CountryCode;
|
|
148
|
+
/** Parse a raw/display string into every representation at once (one parse → display + wire never drift). */
|
|
149
|
+
declare function parsePhone(raw: string, country?: CountryCode): ParsedPhone;
|
|
150
|
+
/** Normalize any raw/display value to E.164, or `null` if it isn't a valid number. */
|
|
151
|
+
declare function toE164(raw: string, country?: CountryCode): string | null;
|
|
152
|
+
/** Format a value for display. Defaults to `'national'`. Never affects the wire value. */
|
|
153
|
+
declare function formatPhone(value: string, format?: PhoneDisplayFormat, country?: CountryCode): string;
|
|
154
|
+
/** Live, incremental formatting for an `<input>` as the user types (`AsYouType`). */
|
|
155
|
+
declare function formatPhoneAsTyped(raw: string, country?: CountryCode): string;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Init-time phone config (`createTracking({ phone })`). The transmitted value is
|
|
159
|
+
* ALWAYS E.164 and is deliberately not configurable here — only display is.
|
|
160
|
+
*/
|
|
161
|
+
interface PhoneConfig {
|
|
162
|
+
/** Region assumed for numbers typed without a country code. Default `'CA'`. */
|
|
163
|
+
defaultCountry?: CountryCode;
|
|
164
|
+
/** How the input DISPLAYS to the user. Default `'national'`. Does not affect the wire. */
|
|
165
|
+
display?: PhoneDisplayFormat;
|
|
166
|
+
}
|
|
167
|
+
/** A single tracked form field destined for `form_submit.fields[]`. */
|
|
168
|
+
interface TrackedField {
|
|
169
|
+
name: string;
|
|
170
|
+
type: string;
|
|
171
|
+
value: JsonValue;
|
|
172
|
+
label?: string | null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Build a tracked field whose wire value is ALWAYS E.164. The client keeps its
|
|
176
|
+
* own display value for UI/email; this puts `+E.164` on the wire (or `null` when
|
|
177
|
+
* the input isn't a valid number).
|
|
178
|
+
*/
|
|
179
|
+
declare function phoneField(name: string, raw: string, country?: CountryCode): TrackedField;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Visitor consent state stored by the SDK.
|
|
183
|
+
*
|
|
184
|
+
* - `pending`: the visitor has not accepted or declined yet.
|
|
185
|
+
* - `granted`: consent was accepted and Google Consent Mode is updated to granted.
|
|
186
|
+
* - `denied`: consent was declined and Google Consent Mode is updated to denied.
|
|
187
|
+
*/
|
|
188
|
+
type ConsentState = 'granted' | 'denied' | 'pending';
|
|
189
|
+
/**
|
|
190
|
+
* Attribution parameters captured from the landing URL and persisted in cookies.
|
|
191
|
+
*
|
|
192
|
+
* Missing params are represented as `null` so payloads can be serialized
|
|
193
|
+
* directly without checking for `undefined`.
|
|
194
|
+
*/
|
|
195
|
+
interface TrackingParams {
|
|
196
|
+
/** Google Ads click id. */
|
|
197
|
+
gclid: string | null;
|
|
198
|
+
/** Meta/Facebook click id. */
|
|
199
|
+
fbclid: string | null;
|
|
200
|
+
/** UTM source, for example `google` or `newsletter`. */
|
|
201
|
+
utm_source: string | null;
|
|
202
|
+
/** UTM medium, for example `cpc` or `email`. */
|
|
203
|
+
utm_medium: string | null;
|
|
204
|
+
/** UTM campaign name. */
|
|
205
|
+
utm_campaign: string | null;
|
|
206
|
+
/** UTM paid-search term. */
|
|
207
|
+
utm_term: string | null;
|
|
208
|
+
/** UTM content/ad creative label. */
|
|
209
|
+
utm_content: string | null;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Runtime surface that installed the tracking SDK.
|
|
213
|
+
*
|
|
214
|
+
* Included in ingest payloads and heartbeat events so the dashboard can tell
|
|
215
|
+
* whether a site uses the Next, React, or script-tag integration.
|
|
216
|
+
*/
|
|
217
|
+
type TrackingInstallSurface = 'next' | 'react' | 'script';
|
|
218
|
+
/**
|
|
219
|
+
* Deployment environment label for event tagging.
|
|
220
|
+
*
|
|
221
|
+
* Used to stamp tracking events with the deployment context so the dashboard
|
|
222
|
+
* can distinguish production traffic from dev test traffic. The backend
|
|
223
|
+
* enforces this via a Postgres enum, so values are strictly one of
|
|
224
|
+
* `'production'` or `'development'`.
|
|
225
|
+
*/
|
|
226
|
+
type TrackingEnvironment = 'production' | 'development';
|
|
227
|
+
/**
|
|
228
|
+
* Labelled map of Google Ads tag IDs.
|
|
229
|
+
*
|
|
230
|
+
* ALL entries are loaded simultaneously via `gtag('config', ...)` — the keys
|
|
231
|
+
* are human-readable labels (e.g. `production`, `test`) and the values are
|
|
232
|
+
* Google Ads tag IDs (e.g. `AW-123456789`).
|
|
233
|
+
*/
|
|
234
|
+
type GtagEnvironmentMap = Record<string, string>;
|
|
235
|
+
/**
|
|
236
|
+
* Runtime context attached to tracking sessions and events.
|
|
237
|
+
*/
|
|
238
|
+
interface TrackingClientContext {
|
|
239
|
+
/** Install surface that created the client. */
|
|
240
|
+
surface: TrackingInstallSurface;
|
|
241
|
+
/** Package version, when available. */
|
|
242
|
+
sdk_version: string | null;
|
|
243
|
+
/** Package name, for example `@aranova/tracking-react`. */
|
|
244
|
+
package_name: string | null;
|
|
245
|
+
/** Browser origin of the tracked site. */
|
|
246
|
+
site_origin: string | null;
|
|
247
|
+
/** Current document title at client creation time. */
|
|
248
|
+
page_title: string | null;
|
|
249
|
+
/** Browser document referrer at client creation time. */
|
|
250
|
+
referrer: string | null;
|
|
251
|
+
/**
|
|
252
|
+
* Deployment environment label, e.g. `'production'`, `'development'`.
|
|
253
|
+
*
|
|
254
|
+
* Always set — defaults to `'production'` when the consumer doesn't
|
|
255
|
+
* pass `environment` to the factory. Sending `null` would fail the
|
|
256
|
+
* backend's strict enum validation.
|
|
257
|
+
*/
|
|
258
|
+
environment: TrackingEnvironment;
|
|
259
|
+
/** All active gtag IDs loaded on this page, keyed by label. */
|
|
260
|
+
active_gtag_ids: Record<string, string> | null;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Session payload sent to `POST /tracking/events`.
|
|
264
|
+
*
|
|
265
|
+
* The backend upserts this by `(business_id, session_id)` before inserting
|
|
266
|
+
* individual events.
|
|
267
|
+
*/
|
|
268
|
+
interface TrackingSessionUpsertPayload {
|
|
269
|
+
/** Rolling 30-minute client-side session id. */
|
|
270
|
+
session_id: string;
|
|
271
|
+
/** Persistent client-side visitor id. */
|
|
272
|
+
visitor_id: string | null;
|
|
273
|
+
gclid: string | null;
|
|
274
|
+
fbclid: string | null;
|
|
275
|
+
utm_source: string | null;
|
|
276
|
+
utm_medium: string | null;
|
|
277
|
+
utm_campaign: string | null;
|
|
278
|
+
utm_term: string | null;
|
|
279
|
+
utm_content: string | null;
|
|
280
|
+
first_page: string | null;
|
|
281
|
+
consent_state: Record<string, unknown> | null;
|
|
282
|
+
context: TrackingClientContext;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Event payload shape before batching into the ingest request.
|
|
286
|
+
*/
|
|
287
|
+
interface TrackingEventCreatePayload {
|
|
288
|
+
/** Session id that logically owns the event. */
|
|
289
|
+
session_id: string;
|
|
290
|
+
/** Registered event name, for example `page_view` or `form_submit`. */
|
|
291
|
+
event_type: string;
|
|
292
|
+
gclid: string | null;
|
|
293
|
+
fbclid: string | null;
|
|
294
|
+
/** Full page URL associated with the event, if known. */
|
|
295
|
+
page_url: string | null;
|
|
296
|
+
/** Event-specific metadata. Runtime shape depends on `event_type`. */
|
|
297
|
+
metadata: Record<string, unknown> | null;
|
|
298
|
+
context: TrackingClientContext;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Browser-script initialization config passed to `window.AranovaTracking.init()`.
|
|
302
|
+
*/
|
|
303
|
+
interface TrackingInitConfig {
|
|
304
|
+
/** Public tracking API key issued from the Aranova dashboard. */
|
|
305
|
+
apiKey?: string;
|
|
306
|
+
/** Tracking endpoint base URL, usually ending in `/tracking`. */
|
|
307
|
+
endpoint?: string;
|
|
308
|
+
/** Optional Google Ads tag id, for example `AW-123456789`. */
|
|
309
|
+
gtagId?: string;
|
|
310
|
+
/**
|
|
311
|
+
* Labelled map of Google Ads tag IDs. ALL are loaded simultaneously.
|
|
312
|
+
* When provided, `gtagId` is ignored.
|
|
313
|
+
*/
|
|
314
|
+
gtagIds?: GtagEnvironmentMap;
|
|
315
|
+
/** Deployment environment label reported in session context. */
|
|
316
|
+
environment?: TrackingEnvironment;
|
|
317
|
+
/** Whether to capture attribution params from `window.location`. Defaults to true. */
|
|
318
|
+
autoCaptureTrackingParams?: boolean;
|
|
319
|
+
/** Whether the browser script should inject the default consent banner. */
|
|
320
|
+
renderConsentBanner?: boolean;
|
|
321
|
+
/** Attribution cookie max age in seconds. Defaults to 90 days. */
|
|
322
|
+
cookieMaxAgeSeconds?: number;
|
|
323
|
+
/** Override the install surface reported in payload context. */
|
|
324
|
+
surface?: TrackingInstallSurface;
|
|
325
|
+
/** Phone-field display + default-country config. Transmit is always E.164. */
|
|
326
|
+
phone?: PhoneConfig;
|
|
327
|
+
}
|
|
328
|
+
declare global {
|
|
329
|
+
interface Window {
|
|
330
|
+
gtag?: (...args: unknown[]) => void;
|
|
331
|
+
dataLayer?: unknown[];
|
|
332
|
+
AranovaTracking?: {
|
|
333
|
+
init: (config: TrackingInitConfig) => void;
|
|
334
|
+
captureTrackingParams: () => TrackingParams;
|
|
335
|
+
getTrackingParams: () => TrackingParams;
|
|
336
|
+
getConsentState: () => ConsentState;
|
|
337
|
+
setConsentState: (state: 'granted' | 'denied') => void;
|
|
338
|
+
trackEvent: (eventType: string, metadata: Record<string, unknown>) => void;
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export { type ConsentState as C, DEFAULT_PHONE_COUNTRY as D, type FormSubmitConfig as F, type GtagEnvironmentMap as G, type JsonValue as J, type PhoneConfig as P, type TrackingInstallSurface as T, type TrackingEnvironment as a, type TrackingClientContext as b, type TrackingParams as c, type TrackingEventCreatePayload as d, type TrackingSessionUpsertPayload as e, type FormSubmitMetadata as f, type ParsedPhone as g, type PhoneDisplayFormat as h, type TrackedField as i, type TrackingInitConfig as j, formatPhone as k, formatPhoneAsTyped as l, phoneField as m, parsePhone as p, toE164 as t };
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* JSON-serializable value accepted by `form_submit.fields[].value`.
|
|
6
|
+
*
|
|
7
|
+
* This intentionally excludes `undefined`, functions, symbols, `Date`
|
|
8
|
+
* instances, and non-finite numbers. Values are stored in PostgreSQL JSONB, so
|
|
9
|
+
* consumers should send only data that has a stable JSON representation.
|
|
10
|
+
*/
|
|
11
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
12
|
+
[key: string]: JsonValue;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Metadata for a manually fired `form_submit` event.
|
|
16
|
+
*
|
|
17
|
+
* Register the event with `manual: { form_submit: {} }`, then call
|
|
18
|
+
* `trackEvent('form_submit', metadata)` from the host site's submit handler.
|
|
19
|
+
*
|
|
20
|
+
* `fields` is optional. If present, each field value must be JSON-serializable
|
|
21
|
+
* and should be explicitly allowlisted by the integration. Do not send names,
|
|
22
|
+
* emails, visitor phone numbers, addresses, payment data, medical details,
|
|
23
|
+
* passwords, file contents, or free-text messages.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* tracking.trackEvent('form_submit', {
|
|
28
|
+
* form: {
|
|
29
|
+
* id: 'lead-form',
|
|
30
|
+
* action: '/api/lead',
|
|
31
|
+
* fields: [
|
|
32
|
+
* {
|
|
33
|
+
* name: 'service_interest',
|
|
34
|
+
* type: 'select',
|
|
35
|
+
* label: 'Service interest',
|
|
36
|
+
* value: 'teeth_whitening',
|
|
37
|
+
* },
|
|
38
|
+
* ],
|
|
39
|
+
* },
|
|
40
|
+
* page: { path: window.location.pathname },
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare const formSubmitMetadataSchema: z.ZodObject<{
|
|
45
|
+
form: z.ZodObject<{
|
|
46
|
+
id: z.ZodString;
|
|
47
|
+
action: z.ZodNullable<z.ZodString>;
|
|
48
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
49
|
+
name: z.ZodString;
|
|
50
|
+
type: z.ZodString;
|
|
51
|
+
label: z.ZodNullable<z.ZodString>;
|
|
52
|
+
value: z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>;
|
|
53
|
+
}, "strict", z.ZodTypeAny, {
|
|
54
|
+
value: JsonValue;
|
|
55
|
+
type: string;
|
|
56
|
+
name: string;
|
|
57
|
+
label: string | null;
|
|
58
|
+
}, {
|
|
59
|
+
value: JsonValue;
|
|
60
|
+
type: string;
|
|
61
|
+
name: string;
|
|
62
|
+
label: string | null;
|
|
63
|
+
}>, "many">>;
|
|
64
|
+
}, "strict", z.ZodTypeAny, {
|
|
65
|
+
id: string;
|
|
66
|
+
action: string | null;
|
|
67
|
+
fields?: {
|
|
68
|
+
value: JsonValue;
|
|
69
|
+
type: string;
|
|
70
|
+
name: string;
|
|
71
|
+
label: string | null;
|
|
72
|
+
}[] | undefined;
|
|
73
|
+
}, {
|
|
74
|
+
id: string;
|
|
75
|
+
action: string | null;
|
|
76
|
+
fields?: {
|
|
77
|
+
value: JsonValue;
|
|
78
|
+
type: string;
|
|
79
|
+
name: string;
|
|
80
|
+
label: string | null;
|
|
81
|
+
}[] | undefined;
|
|
82
|
+
}>;
|
|
83
|
+
page: z.ZodObject<{
|
|
84
|
+
path: z.ZodString;
|
|
85
|
+
}, "strict", z.ZodTypeAny, {
|
|
86
|
+
path: string;
|
|
87
|
+
}, {
|
|
88
|
+
path: string;
|
|
89
|
+
}>;
|
|
90
|
+
}, "strict", z.ZodTypeAny, {
|
|
91
|
+
form: {
|
|
92
|
+
id: string;
|
|
93
|
+
action: string | null;
|
|
94
|
+
fields?: {
|
|
95
|
+
value: JsonValue;
|
|
96
|
+
type: string;
|
|
97
|
+
name: string;
|
|
98
|
+
label: string | null;
|
|
99
|
+
}[] | undefined;
|
|
100
|
+
};
|
|
101
|
+
page: {
|
|
102
|
+
path: string;
|
|
103
|
+
};
|
|
104
|
+
}, {
|
|
105
|
+
form: {
|
|
106
|
+
id: string;
|
|
107
|
+
action: string | null;
|
|
108
|
+
fields?: {
|
|
109
|
+
value: JsonValue;
|
|
110
|
+
type: string;
|
|
111
|
+
name: string;
|
|
112
|
+
label: string | null;
|
|
113
|
+
}[] | undefined;
|
|
114
|
+
};
|
|
115
|
+
page: {
|
|
116
|
+
path: string;
|
|
117
|
+
};
|
|
118
|
+
}>;
|
|
119
|
+
type FormSubmitMetadata = z.infer<typeof formSubmitMetadataSchema>;
|
|
120
|
+
/**
|
|
121
|
+
* Registration config for `form_submit`.
|
|
122
|
+
*
|
|
123
|
+
* This event is manual-only and currently has no registration options. The
|
|
124
|
+
* empty object enables typed `trackEvent('form_submit', ...)` calls.
|
|
125
|
+
*/
|
|
126
|
+
declare const formSubmitConfigSchema: z.ZodObject<{}, "strict", z.ZodTypeAny, {}, {}>;
|
|
127
|
+
type FormSubmitConfig = z.infer<typeof formSubmitConfigSchema>;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* How a phone number is shown in the UI. The transmitted value is always E.164
|
|
131
|
+
* and is deliberately NOT part of this — only the display format is configurable.
|
|
132
|
+
* A function form covers the long tail (`(parsed) => string`).
|
|
133
|
+
*/
|
|
134
|
+
type PhoneDisplayFormat = 'national' | 'international' | 'e164' | ((parsed: ParsedPhone) => string);
|
|
135
|
+
interface ParsedPhone {
|
|
136
|
+
/** E.164 (`"+14165550199"`) or `null` when the input isn't a valid number. This is what gets transmitted. */
|
|
137
|
+
e164: string | null;
|
|
138
|
+
/** National display form (`"(416) 555-0199"`); empty string when unparseable. */
|
|
139
|
+
national: string;
|
|
140
|
+
/** International display form (`"+1 416 555 0199"`); empty string when unparseable. */
|
|
141
|
+
international: string;
|
|
142
|
+
/** ISO-3166 country resolved by libphonenumber, or `null`. */
|
|
143
|
+
country: CountryCode | null;
|
|
144
|
+
isValid: boolean;
|
|
145
|
+
}
|
|
146
|
+
/** Region assumed for numbers typed without a country code. */
|
|
147
|
+
declare const DEFAULT_PHONE_COUNTRY: CountryCode;
|
|
148
|
+
/** Parse a raw/display string into every representation at once (one parse → display + wire never drift). */
|
|
149
|
+
declare function parsePhone(raw: string, country?: CountryCode): ParsedPhone;
|
|
150
|
+
/** Normalize any raw/display value to E.164, or `null` if it isn't a valid number. */
|
|
151
|
+
declare function toE164(raw: string, country?: CountryCode): string | null;
|
|
152
|
+
/** Format a value for display. Defaults to `'national'`. Never affects the wire value. */
|
|
153
|
+
declare function formatPhone(value: string, format?: PhoneDisplayFormat, country?: CountryCode): string;
|
|
154
|
+
/** Live, incremental formatting for an `<input>` as the user types (`AsYouType`). */
|
|
155
|
+
declare function formatPhoneAsTyped(raw: string, country?: CountryCode): string;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Init-time phone config (`createTracking({ phone })`). The transmitted value is
|
|
159
|
+
* ALWAYS E.164 and is deliberately not configurable here — only display is.
|
|
160
|
+
*/
|
|
161
|
+
interface PhoneConfig {
|
|
162
|
+
/** Region assumed for numbers typed without a country code. Default `'CA'`. */
|
|
163
|
+
defaultCountry?: CountryCode;
|
|
164
|
+
/** How the input DISPLAYS to the user. Default `'national'`. Does not affect the wire. */
|
|
165
|
+
display?: PhoneDisplayFormat;
|
|
166
|
+
}
|
|
167
|
+
/** A single tracked form field destined for `form_submit.fields[]`. */
|
|
168
|
+
interface TrackedField {
|
|
169
|
+
name: string;
|
|
170
|
+
type: string;
|
|
171
|
+
value: JsonValue;
|
|
172
|
+
label?: string | null;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Build a tracked field whose wire value is ALWAYS E.164. The client keeps its
|
|
176
|
+
* own display value for UI/email; this puts `+E.164` on the wire (or `null` when
|
|
177
|
+
* the input isn't a valid number).
|
|
178
|
+
*/
|
|
179
|
+
declare function phoneField(name: string, raw: string, country?: CountryCode): TrackedField;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Visitor consent state stored by the SDK.
|
|
183
|
+
*
|
|
184
|
+
* - `pending`: the visitor has not accepted or declined yet.
|
|
185
|
+
* - `granted`: consent was accepted and Google Consent Mode is updated to granted.
|
|
186
|
+
* - `denied`: consent was declined and Google Consent Mode is updated to denied.
|
|
187
|
+
*/
|
|
188
|
+
type ConsentState = 'granted' | 'denied' | 'pending';
|
|
189
|
+
/**
|
|
190
|
+
* Attribution parameters captured from the landing URL and persisted in cookies.
|
|
191
|
+
*
|
|
192
|
+
* Missing params are represented as `null` so payloads can be serialized
|
|
193
|
+
* directly without checking for `undefined`.
|
|
194
|
+
*/
|
|
195
|
+
interface TrackingParams {
|
|
196
|
+
/** Google Ads click id. */
|
|
197
|
+
gclid: string | null;
|
|
198
|
+
/** Meta/Facebook click id. */
|
|
199
|
+
fbclid: string | null;
|
|
200
|
+
/** UTM source, for example `google` or `newsletter`. */
|
|
201
|
+
utm_source: string | null;
|
|
202
|
+
/** UTM medium, for example `cpc` or `email`. */
|
|
203
|
+
utm_medium: string | null;
|
|
204
|
+
/** UTM campaign name. */
|
|
205
|
+
utm_campaign: string | null;
|
|
206
|
+
/** UTM paid-search term. */
|
|
207
|
+
utm_term: string | null;
|
|
208
|
+
/** UTM content/ad creative label. */
|
|
209
|
+
utm_content: string | null;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Runtime surface that installed the tracking SDK.
|
|
213
|
+
*
|
|
214
|
+
* Included in ingest payloads and heartbeat events so the dashboard can tell
|
|
215
|
+
* whether a site uses the Next, React, or script-tag integration.
|
|
216
|
+
*/
|
|
217
|
+
type TrackingInstallSurface = 'next' | 'react' | 'script';
|
|
218
|
+
/**
|
|
219
|
+
* Deployment environment label for event tagging.
|
|
220
|
+
*
|
|
221
|
+
* Used to stamp tracking events with the deployment context so the dashboard
|
|
222
|
+
* can distinguish production traffic from dev test traffic. The backend
|
|
223
|
+
* enforces this via a Postgres enum, so values are strictly one of
|
|
224
|
+
* `'production'` or `'development'`.
|
|
225
|
+
*/
|
|
226
|
+
type TrackingEnvironment = 'production' | 'development';
|
|
227
|
+
/**
|
|
228
|
+
* Labelled map of Google Ads tag IDs.
|
|
229
|
+
*
|
|
230
|
+
* ALL entries are loaded simultaneously via `gtag('config', ...)` — the keys
|
|
231
|
+
* are human-readable labels (e.g. `production`, `test`) and the values are
|
|
232
|
+
* Google Ads tag IDs (e.g. `AW-123456789`).
|
|
233
|
+
*/
|
|
234
|
+
type GtagEnvironmentMap = Record<string, string>;
|
|
235
|
+
/**
|
|
236
|
+
* Runtime context attached to tracking sessions and events.
|
|
237
|
+
*/
|
|
238
|
+
interface TrackingClientContext {
|
|
239
|
+
/** Install surface that created the client. */
|
|
240
|
+
surface: TrackingInstallSurface;
|
|
241
|
+
/** Package version, when available. */
|
|
242
|
+
sdk_version: string | null;
|
|
243
|
+
/** Package name, for example `@aranova/tracking-react`. */
|
|
244
|
+
package_name: string | null;
|
|
245
|
+
/** Browser origin of the tracked site. */
|
|
246
|
+
site_origin: string | null;
|
|
247
|
+
/** Current document title at client creation time. */
|
|
248
|
+
page_title: string | null;
|
|
249
|
+
/** Browser document referrer at client creation time. */
|
|
250
|
+
referrer: string | null;
|
|
251
|
+
/**
|
|
252
|
+
* Deployment environment label, e.g. `'production'`, `'development'`.
|
|
253
|
+
*
|
|
254
|
+
* Always set — defaults to `'production'` when the consumer doesn't
|
|
255
|
+
* pass `environment` to the factory. Sending `null` would fail the
|
|
256
|
+
* backend's strict enum validation.
|
|
257
|
+
*/
|
|
258
|
+
environment: TrackingEnvironment;
|
|
259
|
+
/** All active gtag IDs loaded on this page, keyed by label. */
|
|
260
|
+
active_gtag_ids: Record<string, string> | null;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Session payload sent to `POST /tracking/events`.
|
|
264
|
+
*
|
|
265
|
+
* The backend upserts this by `(business_id, session_id)` before inserting
|
|
266
|
+
* individual events.
|
|
267
|
+
*/
|
|
268
|
+
interface TrackingSessionUpsertPayload {
|
|
269
|
+
/** Rolling 30-minute client-side session id. */
|
|
270
|
+
session_id: string;
|
|
271
|
+
/** Persistent client-side visitor id. */
|
|
272
|
+
visitor_id: string | null;
|
|
273
|
+
gclid: string | null;
|
|
274
|
+
fbclid: string | null;
|
|
275
|
+
utm_source: string | null;
|
|
276
|
+
utm_medium: string | null;
|
|
277
|
+
utm_campaign: string | null;
|
|
278
|
+
utm_term: string | null;
|
|
279
|
+
utm_content: string | null;
|
|
280
|
+
first_page: string | null;
|
|
281
|
+
consent_state: Record<string, unknown> | null;
|
|
282
|
+
context: TrackingClientContext;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Event payload shape before batching into the ingest request.
|
|
286
|
+
*/
|
|
287
|
+
interface TrackingEventCreatePayload {
|
|
288
|
+
/** Session id that logically owns the event. */
|
|
289
|
+
session_id: string;
|
|
290
|
+
/** Registered event name, for example `page_view` or `form_submit`. */
|
|
291
|
+
event_type: string;
|
|
292
|
+
gclid: string | null;
|
|
293
|
+
fbclid: string | null;
|
|
294
|
+
/** Full page URL associated with the event, if known. */
|
|
295
|
+
page_url: string | null;
|
|
296
|
+
/** Event-specific metadata. Runtime shape depends on `event_type`. */
|
|
297
|
+
metadata: Record<string, unknown> | null;
|
|
298
|
+
context: TrackingClientContext;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Browser-script initialization config passed to `window.AranovaTracking.init()`.
|
|
302
|
+
*/
|
|
303
|
+
interface TrackingInitConfig {
|
|
304
|
+
/** Public tracking API key issued from the Aranova dashboard. */
|
|
305
|
+
apiKey?: string;
|
|
306
|
+
/** Tracking endpoint base URL, usually ending in `/tracking`. */
|
|
307
|
+
endpoint?: string;
|
|
308
|
+
/** Optional Google Ads tag id, for example `AW-123456789`. */
|
|
309
|
+
gtagId?: string;
|
|
310
|
+
/**
|
|
311
|
+
* Labelled map of Google Ads tag IDs. ALL are loaded simultaneously.
|
|
312
|
+
* When provided, `gtagId` is ignored.
|
|
313
|
+
*/
|
|
314
|
+
gtagIds?: GtagEnvironmentMap;
|
|
315
|
+
/** Deployment environment label reported in session context. */
|
|
316
|
+
environment?: TrackingEnvironment;
|
|
317
|
+
/** Whether to capture attribution params from `window.location`. Defaults to true. */
|
|
318
|
+
autoCaptureTrackingParams?: boolean;
|
|
319
|
+
/** Whether the browser script should inject the default consent banner. */
|
|
320
|
+
renderConsentBanner?: boolean;
|
|
321
|
+
/** Attribution cookie max age in seconds. Defaults to 90 days. */
|
|
322
|
+
cookieMaxAgeSeconds?: number;
|
|
323
|
+
/** Override the install surface reported in payload context. */
|
|
324
|
+
surface?: TrackingInstallSurface;
|
|
325
|
+
/** Phone-field display + default-country config. Transmit is always E.164. */
|
|
326
|
+
phone?: PhoneConfig;
|
|
327
|
+
}
|
|
328
|
+
declare global {
|
|
329
|
+
interface Window {
|
|
330
|
+
gtag?: (...args: unknown[]) => void;
|
|
331
|
+
dataLayer?: unknown[];
|
|
332
|
+
AranovaTracking?: {
|
|
333
|
+
init: (config: TrackingInitConfig) => void;
|
|
334
|
+
captureTrackingParams: () => TrackingParams;
|
|
335
|
+
getTrackingParams: () => TrackingParams;
|
|
336
|
+
getConsentState: () => ConsentState;
|
|
337
|
+
setConsentState: (state: 'granted' | 'denied') => void;
|
|
338
|
+
trackEvent: (eventType: string, metadata: Record<string, unknown>) => void;
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export { type ConsentState as C, DEFAULT_PHONE_COUNTRY as D, type FormSubmitConfig as F, type GtagEnvironmentMap as G, type JsonValue as J, type PhoneConfig as P, type TrackingInstallSurface as T, type TrackingEnvironment as a, type TrackingClientContext as b, type TrackingParams as c, type TrackingEventCreatePayload as d, type TrackingSessionUpsertPayload as e, type FormSubmitMetadata as f, type ParsedPhone as g, type PhoneDisplayFormat as h, type TrackedField as i, type TrackingInitConfig as j, formatPhone as k, formatPhoneAsTyped as l, phoneField as m, parsePhone as p, toE164 as t };
|
package/dist/phone.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { D as DEFAULT_PHONE_COUNTRY, g as ParsedPhone, P as PhoneConfig, h as PhoneDisplayFormat, i as TrackedField, k as formatPhone, l as formatPhoneAsTyped, p as parsePhone, m as phoneField, t as toE164 } from './phone-utils-CVX7JmqB.mjs';
|
|
2
|
+
export { CountryCode } from 'libphonenumber-js';
|
|
3
|
+
import 'zod';
|
package/dist/phone.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { D as DEFAULT_PHONE_COUNTRY, g as ParsedPhone, P as PhoneConfig, h as PhoneDisplayFormat, i as TrackedField, k as formatPhone, l as formatPhoneAsTyped, p as parsePhone, m as phoneField, t as toE164 } from './phone-utils-CVX7JmqB.js';
|
|
2
|
+
export { CountryCode } from 'libphonenumber-js';
|
|
3
|
+
import 'zod';
|