@aranova/tracking-react 0.7.0 → 0.7.2

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/index.d.mts CHANGED
@@ -81,8 +81,14 @@ interface TrackingClientContext {
81
81
  page_title: string | null;
82
82
  /** Browser document referrer at client creation time. */
83
83
  referrer: string | null;
84
- /** Deployment environment label, e.g. `'production'`, `'development'`. */
85
- environment: TrackingEnvironment | null;
84
+ /**
85
+ * Deployment environment label, e.g. `'production'`, `'development'`.
86
+ *
87
+ * Always set — defaults to `'production'` when the consumer doesn't
88
+ * pass `environment` to the factory. Sending `null` would fail the
89
+ * backend's strict enum validation.
90
+ */
91
+ environment: TrackingEnvironment;
86
92
  /** All active gtag IDs loaded on this page, keyed by label. */
87
93
  active_gtag_ids: Record<string, string> | null;
88
94
  }
@@ -188,7 +194,7 @@ interface TrackingContextInput {
188
194
  referrer?: string | null;
189
195
  sdkVersion?: string | null;
190
196
  siteOrigin?: string | null;
191
- environment?: TrackingEnvironment | null;
197
+ environment?: TrackingEnvironment;
192
198
  activeGtagIds?: Record<string, string> | null;
193
199
  }
194
200
  interface TrackingEventInput {
package/dist/index.d.ts CHANGED
@@ -81,8 +81,14 @@ interface TrackingClientContext {
81
81
  page_title: string | null;
82
82
  /** Browser document referrer at client creation time. */
83
83
  referrer: string | null;
84
- /** Deployment environment label, e.g. `'production'`, `'development'`. */
85
- environment: TrackingEnvironment | null;
84
+ /**
85
+ * Deployment environment label, e.g. `'production'`, `'development'`.
86
+ *
87
+ * Always set — defaults to `'production'` when the consumer doesn't
88
+ * pass `environment` to the factory. Sending `null` would fail the
89
+ * backend's strict enum validation.
90
+ */
91
+ environment: TrackingEnvironment;
86
92
  /** All active gtag IDs loaded on this page, keyed by label. */
87
93
  active_gtag_ids: Record<string, string> | null;
88
94
  }
@@ -188,7 +194,7 @@ interface TrackingContextInput {
188
194
  referrer?: string | null;
189
195
  sdkVersion?: string | null;
190
196
  siteOrigin?: string | null;
191
- environment?: TrackingEnvironment | null;
197
+ environment?: TrackingEnvironment;
192
198
  activeGtagIds?: Record<string, string> | null;
193
199
  }
194
200
  interface TrackingEventInput {
package/dist/index.js CHANGED
@@ -82,7 +82,7 @@ function createTrackingClientContext(surface, input = {}) {
82
82
  site_origin: input.siteOrigin ?? (typeof window === "undefined" ? null : window.location.origin),
83
83
  page_title: input.pageTitle ?? (typeof document === "undefined" ? null : document.title || null),
84
84
  referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null),
85
- environment: input.environment ?? null,
85
+ environment: input.environment ?? "production",
86
86
  active_gtag_ids: input.activeGtagIds ?? null
87
87
  };
88
88
  }
@@ -503,6 +503,10 @@ var DEFAULT_FLUSH_INTERVAL_MS = 2e3;
503
503
  var DEFAULT_MAX_QUEUE_SIZE = 10;
504
504
  var HARD_MAX_BATCH = 50;
505
505
  var API_KEY_HEADER = "X-Aranova-Api-Key";
506
+ var SDK_VERSION_HEADER = "X-Aranova-Sdk-Version";
507
+ var SDK_PACKAGE_HEADER = "X-Aranova-Sdk-Package";
508
+ var SDK_SURFACE_HEADER = "X-Aranova-Sdk-Surface";
509
+ var SDK_ENVIRONMENT_HEADER = "X-Aranova-Sdk-Environment";
506
510
  function buildContext(surface, sdkVersion, packageName, environment, activeGtagIds) {
507
511
  return {
508
512
  surface,
@@ -531,7 +535,7 @@ function consentSnapshot() {
531
535
  return null;
532
536
  }
533
537
  }
534
- async function postWithFetch(url, body, apiKey, keepalive) {
538
+ async function postWithFetch(url, body, apiKey, identity, keepalive) {
535
539
  if (typeof fetch !== "function")
536
540
  return;
537
541
  try {
@@ -539,7 +543,11 @@ async function postWithFetch(url, body, apiKey, keepalive) {
539
543
  method: "POST",
540
544
  headers: {
541
545
  "Content-Type": "application/json",
542
- [API_KEY_HEADER]: apiKey
546
+ [API_KEY_HEADER]: apiKey,
547
+ [SDK_VERSION_HEADER]: identity.sdkVersion,
548
+ [SDK_PACKAGE_HEADER]: identity.packageName,
549
+ [SDK_SURFACE_HEADER]: identity.surface,
550
+ [SDK_ENVIRONMENT_HEADER]: identity.environment
543
551
  },
544
552
  body,
545
553
  keepalive,
@@ -572,10 +580,16 @@ function createTrackingClient(config) {
572
580
  const maxQueueSize = Math.min(config.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE, HARD_MAX_BATCH);
573
581
  const sdkVersion = config.sdkVersion ?? null;
574
582
  const packageName = config.packageName ?? null;
575
- const environment = config.environment ?? null;
583
+ const environment = config.environment ?? "production";
576
584
  const activeGtagIds = config.activeGtagIds ?? null;
577
585
  const endpointBase = config.endpoint.replace(/\/$/, "");
578
586
  const eventsUrl = `${endpointBase}/events`;
587
+ const identityHeaders = {
588
+ sdkVersion: sdkVersion ?? "",
589
+ packageName: packageName ?? "",
590
+ surface: config.surface,
591
+ environment
592
+ };
579
593
  let queue = [];
580
594
  let flushTimer = null;
581
595
  let firstPage = null;
@@ -651,7 +665,7 @@ function createTrackingClient(config) {
651
665
  events
652
666
  };
653
667
  const serialized = JSON.stringify(body);
654
- await postWithFetch(eventsUrl, serialized, config.apiKey, false);
668
+ await postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders, false);
655
669
  }
656
670
  function trackEvent(input) {
657
671
  if (destroyed)
@@ -682,7 +696,7 @@ function createTrackingClient(config) {
682
696
  events
683
697
  };
684
698
  const serialized = JSON.stringify(body);
685
- void postWithFetch(eventsUrl, serialized, config.apiKey, true);
699
+ void postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders, true);
686
700
  }
687
701
  if (typeof window !== "undefined") {
688
702
  window.addEventListener("pagehide", flushOnUnload);
@@ -1375,7 +1389,7 @@ function useConsentState() {
1375
1389
  var import_react4 = require("react");
1376
1390
 
1377
1391
  // package.json
1378
- var version = "0.7.0";
1392
+ var version = "0.7.2";
1379
1393
 
1380
1394
  // src/factory.tsx
1381
1395
  var import_jsx_runtime2 = require("react/jsx-runtime");