@aranova/tracking-react 1.2.2 → 1.2.4

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/dist/client.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, CSSProperties, InputHTMLAttributes, ChangeEvent, FocusEvent } from 'react';
3
- import { G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, h as ConsentState, f as ConsentChoiceState, g as ConsentSource, T as TrackingParams, b as TrackingEnvironment, k as PhoneConfig, P as ParsedPhone, l as PhoneDisplayFormat } from './phone-utils-C0ds6cqZ.mjs';
3
+ import { G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, h as ConsentState, f as ConsentChoiceState, g as ConsentSource, T as TrackingParams, b as TrackingEnvironment, k as PhoneConfig, P as ParsedPhone, l as PhoneDisplayFormat } from './phone-utils-qLfVpQI7.mjs';
4
4
  import { T as TrackingConfigReference, C as ConversionConfig } from './tracking-config-runtime-C6H7ofmo.mjs';
5
- import { V as TriggerRegistryConfig, X as TypedTrackingClient } from './ingest-typed-UA13xTfI.mjs';
5
+ import { L as TriggerRegistryConfig, O as TypedTrackingClient } from './ingest-typed-D1sYF0bA.mjs';
6
6
  import { CountryCode } from 'libphonenumber-js';
7
7
  import 'zod/mini';
8
8
  import 'src';
@@ -236,9 +236,9 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
236
236
  */
237
237
  environment?: TrackingEnvironment;
238
238
  /**
239
- * When true, the typed client validates every `trackEvent()` metadata
240
- * payload through the Zod schema before forwarding. Errors are thrown
241
- * loudly. Leave off in prod; turn on in dev to catch shape bugs early.
239
+ * When true, `trackEvent()` metadata that fails its Zod schema throws. When
240
+ * off, the invalid event is dropped with a console warning. Turn on in dev
241
+ * to catch shape bugs early.
242
242
  */
243
243
  debug?: boolean;
244
244
  /**
package/dist/client.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, CSSProperties, InputHTMLAttributes, ChangeEvent, FocusEvent } from 'react';
3
- import { G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, h as ConsentState, f as ConsentChoiceState, g as ConsentSource, T as TrackingParams, b as TrackingEnvironment, k as PhoneConfig, P as ParsedPhone, l as PhoneDisplayFormat } from './phone-utils-C0ds6cqZ.js';
3
+ import { G as GtagEnvironmentMap, M as MetaPixelEnvironmentMap, h as ConsentState, f as ConsentChoiceState, g as ConsentSource, T as TrackingParams, b as TrackingEnvironment, k as PhoneConfig, P as ParsedPhone, l as PhoneDisplayFormat } from './phone-utils-qLfVpQI7.js';
4
4
  import { T as TrackingConfigReference, C as ConversionConfig } from './tracking-config-runtime-C6H7ofmo.js';
5
- import { V as TriggerRegistryConfig, X as TypedTrackingClient } from './ingest-typed-MBuMe9Pn.js';
5
+ import { L as TriggerRegistryConfig, O as TypedTrackingClient } from './ingest-typed-QKX9WGr3.js';
6
6
  import { CountryCode } from 'libphonenumber-js';
7
7
  import 'zod/mini';
8
8
  import 'src';
@@ -236,9 +236,9 @@ interface CreateTrackingOptions<TRegistry extends TriggerRegistryConfig> {
236
236
  */
237
237
  environment?: TrackingEnvironment;
238
238
  /**
239
- * When true, the typed client validates every `trackEvent()` metadata
240
- * payload through the Zod schema before forwarding. Errors are thrown
241
- * loudly. Leave off in prod; turn on in dev to catch shape bugs early.
239
+ * When true, `trackEvent()` metadata that fails its Zod schema throws. When
240
+ * off, the invalid event is dropped with a console warning. Turn on in dev
241
+ * to catch shape bugs early.
242
242
  */
243
243
  debug?: boolean;
244
244
  /**
package/dist/client.js CHANGED
@@ -1747,6 +1747,12 @@ var EVENT_SEMANTICS = {
1747
1747
  outcomeRole: "diagnostic",
1748
1748
  clientVisibility: "detailed"
1749
1749
  },
1750
+ form_step: {
1751
+ label: "Form step",
1752
+ category: "engagement",
1753
+ outcomeRole: "engagement",
1754
+ clientVisibility: "detailed"
1755
+ },
1750
1756
  form_submit: {
1751
1757
  label: "Form submitted",
1752
1758
  category: "lead",
@@ -2467,58 +2473,79 @@ var formStartConfigSchema = z5.strictObject({
2467
2473
  selector: z5.optional(z5.string())
2468
2474
  });
2469
2475
 
2470
- // ../tracking-core/src/events/form-submit.ts
2476
+ // ../tracking-core/src/events/form-step.ts
2471
2477
  var z6 = __toESM(require("zod/mini"));
2472
- var jsonValueSchema = z6.lazy(
2473
- () => z6.union([
2474
- z6.string(),
2475
- z6.number(),
2476
- z6.boolean(),
2477
- z6.null(),
2478
- z6.array(jsonValueSchema),
2479
- z6.record(z6.string(), jsonValueSchema)
2480
- ])
2481
- ).register(z6.globalRegistry, { id: "JsonSerializableValue" });
2482
- var formSubmitMetadataSchema = z6.strictObject({
2478
+ var formStepMetadataSchema = z6.strictObject({
2483
2479
  form: z6.strictObject({
2484
2480
  id: z6.string(),
2485
- action: z6.nullable(z6.string()),
2486
- fields: z6.optional(
2487
- z6.array(
2488
- z6.strictObject({
2489
- name: z6.string(),
2490
- type: z6.string(),
2491
- label: z6.nullable(z6.string()),
2492
- value: jsonValueSchema
2493
- })
2494
- )
2495
- )
2481
+ action: z6.nullable(z6.string())
2482
+ }),
2483
+ step: z6.strictObject({
2484
+ id: z6.string().check(z6.minLength(1), z6.maxLength(64), z6.regex(/^[A-Za-z0-9_-]+$/)),
2485
+ // 1-based position in the flow the visitor is on right now.
2486
+ index: z6.int().check(z6.gte(1), z6.lte(50)),
2487
+ // Null when the number of steps depends on earlier answers.
2488
+ total: z6.nullable(z6.int().check(z6.gte(1), z6.lte(50)))
2496
2489
  }),
2490
+ direction: z6.enum(["forward", "back"]),
2497
2491
  page: z6.strictObject({
2498
2492
  path: z6.string()
2499
2493
  })
2500
2494
  });
2501
- var formSubmitConfigSchema = z6.strictObject({});
2495
+ var formStepConfigSchema = z6.strictObject({});
2502
2496
 
2503
- // ../tracking-core/src/events/multi-page-session.ts
2497
+ // ../tracking-core/src/events/form-submit.ts
2504
2498
  var z7 = __toESM(require("zod/mini"));
2505
- var multiPageSessionMetadataSchema = z7.strictObject({
2506
- page_count: z7.int().check(z7.gte(2)),
2499
+ var jsonValueSchema = z7.lazy(
2500
+ () => z7.union([
2501
+ z7.string(),
2502
+ z7.number(),
2503
+ z7.boolean(),
2504
+ z7.null(),
2505
+ z7.array(jsonValueSchema),
2506
+ z7.record(z7.string(), jsonValueSchema)
2507
+ ])
2508
+ ).register(z7.globalRegistry, { id: "JsonSerializableValue" });
2509
+ var formSubmitMetadataSchema = z7.strictObject({
2510
+ form: z7.strictObject({
2511
+ id: z7.string(),
2512
+ action: z7.nullable(z7.string()),
2513
+ fields: z7.optional(
2514
+ z7.array(
2515
+ z7.strictObject({
2516
+ name: z7.string(),
2517
+ type: z7.string(),
2518
+ label: z7.nullable(z7.string()),
2519
+ value: jsonValueSchema
2520
+ })
2521
+ )
2522
+ )
2523
+ }),
2507
2524
  page: z7.strictObject({
2508
2525
  path: z7.string()
2509
2526
  })
2510
2527
  });
2511
- var multiPageSessionConfigSchema = z7.strictObject({
2512
- pageThreshold: z7.int().check(z7.gte(2))
2528
+ var formSubmitConfigSchema = z7.strictObject({});
2529
+
2530
+ // ../tracking-core/src/events/multi-page-session.ts
2531
+ var z8 = __toESM(require("zod/mini"));
2532
+ var multiPageSessionMetadataSchema = z8.strictObject({
2533
+ page_count: z8.int().check(z8.gte(2)),
2534
+ page: z8.strictObject({
2535
+ path: z8.string()
2536
+ })
2537
+ });
2538
+ var multiPageSessionConfigSchema = z8.strictObject({
2539
+ pageThreshold: z8.int().check(z8.gte(2))
2513
2540
  });
2514
2541
 
2515
2542
  // ../tracking-core/src/events/page-exit.ts
2516
- var z8 = __toESM(require("zod/mini"));
2517
- var pageExitMetadataSchema = z8.strictObject({
2518
- dwell_ms: z8.int().check(z8.gte(0)),
2543
+ var z9 = __toESM(require("zod/mini"));
2544
+ var pageExitMetadataSchema = z9.strictObject({
2545
+ dwell_ms: z9.int().check(z9.gte(0)),
2519
2546
  // null = left without any scroll signal; floor is 0 so a valid 0% is never
2520
2547
  // rejected (a single bad field 422s the whole keepalive beacon batch).
2521
- max_scroll_percent: z8.nullable(z8.int().check(z8.gte(0), z8.lte(100))),
2548
+ max_scroll_percent: z9.nullable(z9.int().check(z9.gte(0), z9.lte(100))),
2522
2549
  // The gating baseline: the fraction of the page visible at load with
2523
2550
  // zero scrolling — or, for pages that grew after the post-paint snapshot
2524
2551
  // (skeleton/streaming renders), the first-scroll position that
@@ -2526,104 +2553,104 @@ var pageExitMetadataSchema = z8.strictObject({
2526
2553
  // ended before the snapshot. Optionality is load-bearing: SDK builds
2527
2554
  // predating this field keep POSTing page_exit without the key —
2528
2555
  // requiring it would 422 whole keepalive beacon batches.
2529
- scroll_baseline_percent: z8.optional(z8.nullable(z8.int().check(z8.gte(0), z8.lte(100)))),
2530
- page: z8.strictObject({
2531
- path: z8.string()
2556
+ scroll_baseline_percent: z9.optional(z9.nullable(z9.int().check(z9.gte(0), z9.lte(100)))),
2557
+ page: z9.strictObject({
2558
+ path: z9.string()
2532
2559
  })
2533
2560
  });
2534
- var pageExitConfigSchema = z8.strictObject({});
2561
+ var pageExitConfigSchema = z9.strictObject({});
2535
2562
 
2536
2563
  // ../tracking-core/src/events/phone-click.ts
2537
- var z9 = __toESM(require("zod/mini"));
2538
- var phoneClickMetadataSchema = z9.strictObject({
2539
- phone_number: z9.string(),
2540
- page: z9.strictObject({
2541
- path: z9.string()
2564
+ var z10 = __toESM(require("zod/mini"));
2565
+ var phoneClickMetadataSchema = z10.strictObject({
2566
+ phone_number: z10.string(),
2567
+ page: z10.strictObject({
2568
+ path: z10.string()
2542
2569
  }),
2543
- section: z9.optional(z9.nullable(z9.string()))
2570
+ section: z10.optional(z10.nullable(z10.string()))
2544
2571
  });
2545
- var phoneClickConfigSchema = z9.strictObject({
2546
- autoCapture: z9.optional(
2547
- z9.strictObject({
2548
- selector: z9.optional(z9.string())
2572
+ var phoneClickConfigSchema = z10.strictObject({
2573
+ autoCapture: z10.optional(
2574
+ z10.strictObject({
2575
+ selector: z10.optional(z10.string())
2549
2576
  })
2550
2577
  )
2551
2578
  });
2552
2579
 
2553
2580
  // ../tracking-core/src/events/scroll-depth.ts
2554
- var z10 = __toESM(require("zod/mini"));
2555
- var scrollDepthMetadataSchema = z10.strictObject({
2556
- depth_percent: z10.int().check(z10.gte(1), z10.lte(100)),
2557
- page: z10.strictObject({
2558
- path: z10.string()
2581
+ var z11 = __toESM(require("zod/mini"));
2582
+ var scrollDepthMetadataSchema = z11.strictObject({
2583
+ depth_percent: z11.int().check(z11.gte(1), z11.lte(100)),
2584
+ page: z11.strictObject({
2585
+ path: z11.string()
2559
2586
  })
2560
2587
  });
2561
- var scrollDepthConfigSchema = z10.strictObject({
2562
- thresholds: z10.array(z10.int().check(z10.gte(1), z10.lte(100))).check(z10.minLength(1))
2588
+ var scrollDepthConfigSchema = z11.strictObject({
2589
+ thresholds: z11.array(z11.int().check(z11.gte(1), z11.lte(100))).check(z11.minLength(1))
2563
2590
  });
2564
2591
 
2565
2592
  // ../tracking-core/src/events/specific-page-visit.ts
2566
- var z11 = __toESM(require("zod/mini"));
2593
+ var z12 = __toESM(require("zod/mini"));
2567
2594
  var PAGE_IDENTITY_MAX_LENGTH = 64;
2568
2595
  var PAGE_IDENTITY_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
2569
- var pageIdentitySchema = z11.string().check(
2570
- z11.maxLength(PAGE_IDENTITY_MAX_LENGTH),
2571
- z11.regex(PAGE_IDENTITY_PATTERN, {
2596
+ var pageIdentitySchema = z12.string().check(
2597
+ z12.maxLength(PAGE_IDENTITY_MAX_LENGTH),
2598
+ z12.regex(PAGE_IDENTITY_PATTERN, {
2572
2599
  message: "page identity must be lowercase snake_case, start with a letter, and contain at most 64 characters"
2573
2600
  })
2574
2601
  );
2575
2602
  var specificPageNameSchema = pageIdentitySchema;
2576
- var specificPageVisitMetadataSchema = z11.strictObject({
2603
+ var specificPageVisitMetadataSchema = z12.strictObject({
2577
2604
  page_name: specificPageNameSchema,
2578
- page: z11.strictObject({
2579
- path: z11.string()
2605
+ page: z12.strictObject({
2606
+ path: z12.string()
2580
2607
  })
2581
2608
  });
2582
- var specificPageVisitConfigSchema = z11.strictObject({
2583
- pages: z11.array(
2584
- z11.strictObject({
2609
+ var specificPageVisitConfigSchema = z12.strictObject({
2610
+ pages: z12.array(
2611
+ z12.strictObject({
2585
2612
  name: specificPageNameSchema,
2586
- pathPattern: z11.custom((value) => value instanceof RegExp, {
2613
+ pathPattern: z12.custom((value) => value instanceof RegExp, {
2587
2614
  message: "pathPattern must be a RegExp"
2588
2615
  })
2589
2616
  })
2590
- ).check(z11.minLength(1))
2617
+ ).check(z12.minLength(1))
2591
2618
  });
2592
2619
 
2593
2620
  // ../tracking-core/src/events/site-link.ts
2594
- var z12 = __toESM(require("zod/mini"));
2595
- var siteLinkClickMetadataSchema = z12.strictObject({
2596
- destination_host: z12.string(),
2597
- destination_url: z12.string(),
2598
- page: z12.strictObject({
2599
- path: z12.string()
2621
+ var z13 = __toESM(require("zod/mini"));
2622
+ var siteLinkClickMetadataSchema = z13.strictObject({
2623
+ destination_host: z13.string(),
2624
+ destination_url: z13.string(),
2625
+ page: z13.strictObject({
2626
+ path: z13.string()
2600
2627
  })
2601
2628
  });
2602
- var siteLinkClickConfigSchema = z12.strictObject({});
2603
- var siteLinkArrivalMetadataSchema = z12.strictObject({
2604
- outcome: z12.enum(["linked", "stale", "invalid"]),
2605
- origin_session_id: z12.optional(z12.nullable(z12.string())),
2606
- origin_visitor_id: z12.optional(z12.nullable(z12.string())),
2629
+ var siteLinkClickConfigSchema = z13.strictObject({});
2630
+ var siteLinkArrivalMetadataSchema = z13.strictObject({
2631
+ outcome: z13.enum(["linked", "stale", "invalid"]),
2632
+ origin_session_id: z13.optional(z13.nullable(z13.string())),
2633
+ origin_visitor_id: z13.optional(z13.nullable(z13.string())),
2607
2634
  // Milliseconds between the origin click and this page load.
2608
- transit_ms: z12.optional(z12.nullable(z12.number())),
2635
+ transit_ms: z13.optional(z13.nullable(z13.number())),
2609
2636
  // True when this browser had no visitor id and took the origin's.
2610
- adopted_visitor: z12.boolean(),
2611
- page: z12.strictObject({
2612
- path: z12.string()
2637
+ adopted_visitor: z13.boolean(),
2638
+ page: z13.strictObject({
2639
+ path: z13.string()
2613
2640
  })
2614
2641
  });
2615
- var siteLinkArrivalConfigSchema = z12.strictObject({});
2642
+ var siteLinkArrivalConfigSchema = z13.strictObject({});
2616
2643
 
2617
2644
  // ../tracking-core/src/events/time-on-site.ts
2618
- var z13 = __toESM(require("zod/mini"));
2619
- var timeOnSiteMetadataSchema = z13.strictObject({
2620
- duration_ms: z13.int().check(z13.nonnegative()),
2621
- page: z13.strictObject({
2622
- path: z13.string()
2645
+ var z14 = __toESM(require("zod/mini"));
2646
+ var timeOnSiteMetadataSchema = z14.strictObject({
2647
+ duration_ms: z14.int().check(z14.nonnegative()),
2648
+ page: z14.strictObject({
2649
+ path: z14.string()
2623
2650
  })
2624
2651
  });
2625
- var timeOnSiteConfigSchema = z13.strictObject({
2626
- thresholdSeconds: z13.int().check(z13.positive())
2652
+ var timeOnSiteConfigSchema = z14.strictObject({
2653
+ thresholdSeconds: z14.int().check(z14.positive())
2627
2654
  });
2628
2655
 
2629
2656
  // ../tracking-core/src/events/registry.ts
@@ -2699,6 +2726,12 @@ var EVENT_REGISTRY = {
2699
2726
  metadataSchema: formSubmitMetadataSchema,
2700
2727
  configSchema: formSubmitConfigSchema
2701
2728
  },
2729
+ form_step: {
2730
+ kind: "manual",
2731
+ semantics: EVENT_SEMANTICS.form_step,
2732
+ metadataSchema: formStepMetadataSchema,
2733
+ configSchema: formStepConfigSchema
2734
+ },
2702
2735
  phone_click: {
2703
2736
  kind: "manual",
2704
2737
  semantics: EVENT_SEMANTICS.phone_click,
@@ -2725,9 +2758,14 @@ function createTypedClient(raw, registry, options = {}) {
2725
2758
  if (registry.manual?.form_submit) registerCapability("form_capture");
2726
2759
  return {
2727
2760
  trackEvent(eventType, metadata, opts) {
2761
+ const def = getEventDefinition(eventType);
2728
2762
  if (debug) {
2729
- const def = getEventDefinition(eventType);
2730
2763
  (0, import_mini2.parse)(def.metadataSchema, metadata);
2764
+ } else if (!(0, import_mini2.safeParse)(def.metadataSchema, metadata).success) {
2765
+ console.warn(
2766
+ `[AranovaTracking] trackEvent: metadata for "${eventType}" failed schema validation; event dropped`
2767
+ );
2768
+ return;
2731
2769
  }
2732
2770
  raw.trackEvent({
2733
2771
  eventType,
@@ -3102,8 +3140,14 @@ function attachFormStart(client, config) {
3102
3140
  return `index:${forms.indexOf(form)}`;
3103
3141
  }
3104
3142
  function onFocusIn(event) {
3105
- const target = event.target;
3106
- if (!(target instanceof HTMLElement)) return;
3143
+ startFrom(event.target);
3144
+ }
3145
+ function onPointerDown(event) {
3146
+ if (event.button !== 0) return;
3147
+ startFrom(event.target);
3148
+ }
3149
+ function startFrom(target) {
3150
+ if (!(target instanceof Element)) return;
3107
3151
  const form = target.closest(selector);
3108
3152
  if (!form || form.tagName !== "FORM") return;
3109
3153
  const key = getFormKey(form);
@@ -3142,11 +3186,13 @@ function attachFormStart(client, config) {
3142
3186
  history.replaceState = patchedReplaceState;
3143
3187
  window.addEventListener("popstate", resetIfPathChanged);
3144
3188
  document.addEventListener("focusin", onFocusIn);
3189
+ document.addEventListener("pointerdown", onPointerDown, { capture: true, passive: true });
3145
3190
  return () => {
3146
3191
  history.pushState = originalPushState;
3147
3192
  history.replaceState = originalReplaceState;
3148
3193
  window.removeEventListener("popstate", resetIfPathChanged);
3149
3194
  document.removeEventListener("focusin", onFocusIn);
3195
+ document.removeEventListener("pointerdown", onPointerDown, { capture: true });
3150
3196
  };
3151
3197
  }
3152
3198
 
@@ -3733,7 +3779,7 @@ function GoogleAdsTracking(props) {
3733
3779
  var import_react6 = require("react");
3734
3780
 
3735
3781
  // package.json
3736
- var version = "1.2.2";
3782
+ var version = "1.2.4";
3737
3783
 
3738
3784
  // ../tracking-core/src/phone-react.tsx
3739
3785
  var import_react5 = require("react");