@aranova/tracking-next 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.mjs CHANGED
@@ -35,7 +35,7 @@ function createTrackingClientContext(surface, input = {}) {
35
35
  site_origin: input.siteOrigin ?? (typeof window === "undefined" ? null : window.location.origin),
36
36
  page_title: input.pageTitle ?? (typeof document === "undefined" ? null : document.title || null),
37
37
  referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null),
38
- environment: input.environment ?? null,
38
+ environment: input.environment ?? "production",
39
39
  active_gtag_ids: input.activeGtagIds ?? null
40
40
  };
41
41
  }
@@ -397,6 +397,10 @@ var DEFAULT_FLUSH_INTERVAL_MS = 2e3;
397
397
  var DEFAULT_MAX_QUEUE_SIZE = 10;
398
398
  var HARD_MAX_BATCH = 50;
399
399
  var API_KEY_HEADER = "X-Aranova-Api-Key";
400
+ var SDK_VERSION_HEADER = "X-Aranova-Sdk-Version";
401
+ var SDK_PACKAGE_HEADER = "X-Aranova-Sdk-Package";
402
+ var SDK_SURFACE_HEADER = "X-Aranova-Sdk-Surface";
403
+ var SDK_ENVIRONMENT_HEADER = "X-Aranova-Sdk-Environment";
400
404
  function buildContext(surface, sdkVersion, packageName, environment, activeGtagIds) {
401
405
  return {
402
406
  surface,
@@ -425,7 +429,7 @@ function consentSnapshot() {
425
429
  return null;
426
430
  }
427
431
  }
428
- async function postWithFetch(url, body, apiKey, keepalive) {
432
+ async function postWithFetch(url, body, apiKey, identity, keepalive) {
429
433
  if (typeof fetch !== "function")
430
434
  return;
431
435
  try {
@@ -433,7 +437,11 @@ async function postWithFetch(url, body, apiKey, keepalive) {
433
437
  method: "POST",
434
438
  headers: {
435
439
  "Content-Type": "application/json",
436
- [API_KEY_HEADER]: apiKey
440
+ [API_KEY_HEADER]: apiKey,
441
+ [SDK_VERSION_HEADER]: identity.sdkVersion,
442
+ [SDK_PACKAGE_HEADER]: identity.packageName,
443
+ [SDK_SURFACE_HEADER]: identity.surface,
444
+ [SDK_ENVIRONMENT_HEADER]: identity.environment
437
445
  },
438
446
  body,
439
447
  keepalive,
@@ -466,10 +474,16 @@ function createTrackingClient(config) {
466
474
  const maxQueueSize = Math.min(config.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE, HARD_MAX_BATCH);
467
475
  const sdkVersion = config.sdkVersion ?? null;
468
476
  const packageName = config.packageName ?? null;
469
- const environment = config.environment ?? null;
477
+ const environment = config.environment ?? "production";
470
478
  const activeGtagIds = config.activeGtagIds ?? null;
471
479
  const endpointBase = config.endpoint.replace(/\/$/, "");
472
480
  const eventsUrl = `${endpointBase}/events`;
481
+ const identityHeaders = {
482
+ sdkVersion: sdkVersion ?? "",
483
+ packageName: packageName ?? "",
484
+ surface: config.surface,
485
+ environment
486
+ };
473
487
  let queue = [];
474
488
  let flushTimer = null;
475
489
  let firstPage = null;
@@ -545,7 +559,7 @@ function createTrackingClient(config) {
545
559
  events
546
560
  };
547
561
  const serialized = JSON.stringify(body);
548
- await postWithFetch(eventsUrl, serialized, config.apiKey, false);
562
+ await postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders, false);
549
563
  }
550
564
  function trackEvent(input) {
551
565
  if (destroyed)
@@ -576,7 +590,7 @@ function createTrackingClient(config) {
576
590
  events
577
591
  };
578
592
  const serialized = JSON.stringify(body);
579
- void postWithFetch(eventsUrl, serialized, config.apiKey, true);
593
+ void postWithFetch(eventsUrl, serialized, config.apiKey, identityHeaders, true);
580
594
  }
581
595
  if (typeof window !== "undefined") {
582
596
  window.addEventListener("pagehide", flushOnUnload);
@@ -1140,7 +1154,7 @@ function GoogleAdsTracking(props) {
1140
1154
  import { usePathname, useSearchParams } from "next/navigation";
1141
1155
 
1142
1156
  // package.json
1143
- var version = "0.7.0";
1157
+ var version = "0.7.2";
1144
1158
 
1145
1159
  // src/factory.tsx
1146
1160
  import {