@aranova/tracking-react 0.20.2 → 0.22.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/dist/index.mjs CHANGED
@@ -250,6 +250,43 @@ function resetConsent() {
250
250
  notifyConsentChanged(DEFAULT_CHOICE);
251
251
  }
252
252
 
253
+ // ../tracking-core/src/capabilities.ts
254
+ var TRACKING_CAPABILITIES = [
255
+ "ad_tags_google",
256
+ "ad_tags_meta",
257
+ "base_tracking",
258
+ "blog_rendering",
259
+ "calendar_read",
260
+ "calendar_write",
261
+ "consent_controls",
262
+ "conversion_goals_auto",
263
+ "conversion_goals_manual",
264
+ "cta_click_capture",
265
+ "form_capture",
266
+ "phone_click_capture",
267
+ "phone_fields"
268
+ ];
269
+ var CAPABILITY_DOM_ATTRIBUTE = "data-aranova-capability";
270
+ var registered = /* @__PURE__ */ new Set();
271
+ function registerCapability(capability) {
272
+ registered.add(capability);
273
+ }
274
+ function getRegisteredCapabilities() {
275
+ const all = new Set(registered);
276
+ for (const marker of readDomMarkers()) all.add(marker);
277
+ return Array.from(all).sort();
278
+ }
279
+ function readDomMarkers() {
280
+ if (typeof document === "undefined") return [];
281
+ const known = new Set(TRACKING_CAPABILITIES);
282
+ const found = [];
283
+ for (const node of document.querySelectorAll(`[${CAPABILITY_DOM_ATTRIBUTE}]`)) {
284
+ const value = node.getAttribute(CAPABILITY_DOM_ATTRIBUTE);
285
+ if (value && known.has(value)) found.push(value);
286
+ }
287
+ return found;
288
+ }
289
+
253
290
  // ../tracking-core/src/tracking.ts
254
291
  var TRACKING_COOKIE_MAX_AGE_SECONDS = 7776e3;
255
292
  var TRACKING_PARAM_KEYS = [
@@ -623,7 +660,8 @@ function createTrackingClientContext(surface, input = {}) {
623
660
  page_title: input.pageTitle ?? (typeof document === "undefined" ? null : document.title || null),
624
661
  referrer: input.referrer ?? (typeof document === "undefined" ? null : document.referrer || null),
625
662
  environment: input.environment ?? "production",
626
- active_gtag_ids: input.activeGtagIds ?? null
663
+ active_gtag_ids: input.activeGtagIds ?? null,
664
+ capabilities: getRegisteredCapabilities()
627
665
  };
628
666
  }
629
667
  function createTrackingSessionUpsertPayload(trackingParams, input, context) {
@@ -967,6 +1005,21 @@ function automaticThresholdMet(goal, eventType, metadata) {
967
1005
  }
968
1006
  }
969
1007
 
1008
+ // ../tracking-core/src/resources/intl/date.ts
1009
+ function formatDateInTz(iso, timeZone, opts, locale) {
1010
+ const date = new Date(iso);
1011
+ if (Number.isNaN(date.getTime())) return iso;
1012
+ return new Intl.DateTimeFormat(locale, {
1013
+ year: "numeric",
1014
+ month: "short",
1015
+ day: "2-digit",
1016
+ hour: "2-digit",
1017
+ minute: "2-digit",
1018
+ ...opts,
1019
+ timeZone
1020
+ }).format(date);
1021
+ }
1022
+
970
1023
  // ../tracking-core/src/resources/sales/money.ts
971
1024
  var MINOR_UNIT_EXPONENT = {
972
1025
  USD: 2,
@@ -986,19 +1039,6 @@ function formatMoney(cents, currency, locale) {
986
1039
  fromMinor(cents, currency)
987
1040
  );
988
1041
  }
989
- function formatDateInTz(iso, timeZone, opts, locale) {
990
- const date = new Date(iso);
991
- if (Number.isNaN(date.getTime())) return iso;
992
- return new Intl.DateTimeFormat(locale, {
993
- year: "numeric",
994
- month: "short",
995
- day: "2-digit",
996
- hour: "2-digit",
997
- minute: "2-digit",
998
- ...opts,
999
- timeZone
1000
- }).format(date);
1001
- }
1002
1042
 
1003
1043
  // ../tracking-core/src/resources/tracking-config-runtime.ts
1004
1044
  var CACHE_PREFIX2 = "_aranova_cfg_runtime_";
@@ -1653,7 +1693,10 @@ function buildContext(surface, sdkVersion, packageName, environment, activeGtagI
1653
1693
  page_title: typeof document === "undefined" ? null : document.title || null,
1654
1694
  referrer: typeof document === "undefined" ? null : document.referrer || null,
1655
1695
  environment,
1656
- active_gtag_ids: activeGtagIds
1696
+ active_gtag_ids: activeGtagIds,
1697
+ // Rebuilt per flush (this runs inside the payload builder), so a client
1698
+ // constructed later on a deeper route still gets reported.
1699
+ capabilities: getRegisteredCapabilities()
1657
1700
  };
1658
1701
  }
1659
1702
  function readTrackingParams() {
@@ -2246,8 +2289,9 @@ function getEventDefinition(name) {
2246
2289
  }
2247
2290
 
2248
2291
  // ../tracking-core/src/ingest-typed.ts
2249
- function createTypedClient(raw, _registry, options = {}) {
2292
+ function createTypedClient(raw, registry, options = {}) {
2250
2293
  const debug = options.debug ?? false;
2294
+ if (registry.manual?.form_submit) registerCapability("form_capture");
2251
2295
  return {
2252
2296
  trackEvent(eventType, metadata, opts) {
2253
2297
  if (debug) {
@@ -2789,6 +2833,7 @@ function attachCtaClickCapture(client, config) {
2789
2833
  return () => {
2790
2834
  };
2791
2835
  }
2836
+ registerCapability("cta_click_capture");
2792
2837
  const selector = autoCapture.selector ?? DEFAULT_CTA_SELECTOR;
2793
2838
  function onClick(event) {
2794
2839
  const target = event.target;
@@ -2845,6 +2890,7 @@ function attachPhoneClickCapture(client, config) {
2845
2890
  return () => {
2846
2891
  };
2847
2892
  }
2893
+ registerCapability("phone_click_capture");
2848
2894
  const selector = autoCapture.selector ?? DEFAULT_TEL_SELECTOR;
2849
2895
  function onClick(event) {
2850
2896
  const target = event.target;
@@ -2874,7 +2920,7 @@ function attachPhoneClickCapture(client, config) {
2874
2920
  };
2875
2921
  }
2876
2922
 
2877
- // ../tracking-core/src/resources/sales/errors.ts
2923
+ // ../tracking-core/src/resources/http/errors.ts
2878
2924
  var AranovaApiError = class extends Error {
2879
2925
  constructor(message, options) {
2880
2926
  super(message);
@@ -2885,7 +2931,7 @@ var AranovaApiError = class extends Error {
2885
2931
  }
2886
2932
  };
2887
2933
 
2888
- // ../tracking-core/src/resources/sales/transport.ts
2934
+ // ../tracking-core/src/resources/http/request.ts
2889
2935
  function identityHeaders(config) {
2890
2936
  const headers = { [API_KEY_HEADER]: config.apiKey };
2891
2937
  if (config.sdkVersion) headers[SDK_VERSION_HEADER] = config.sdkVersion;
@@ -2897,8 +2943,8 @@ function identityHeaders(config) {
2897
2943
  function joinUrl(endpoint, path) {
2898
2944
  return `${endpoint.replace(/\/$/, "")}${path}`;
2899
2945
  }
2900
- async function salesRequest(config, method, path, body) {
2901
- const headers = identityHeaders(config);
2946
+ async function apiRequest(config, method, path, body, extraHeaders) {
2947
+ const headers = { ...identityHeaders(config), ...extraHeaders };
2902
2948
  if (body !== void 0) headers["Content-Type"] = "application/json";
2903
2949
  const response = await fetch(joinUrl(config.endpoint, path), {
2904
2950
  method,
@@ -2927,6 +2973,9 @@ async function salesRequest(config, method, path, body) {
2927
2973
  return await response.json();
2928
2974
  }
2929
2975
 
2976
+ // ../tracking-core/src/resources/sales/transport.ts
2977
+ var salesRequest = apiRequest;
2978
+
2930
2979
  // ../tracking-core/src/resources/sales/client.ts
2931
2980
  function fireRecordedConversions(firing, input, recorded, sale, currency) {
2932
2981
  if (!firing) return;
@@ -2958,6 +3007,7 @@ function fireRecordedConversions(firing, input, recorded, sale, currency) {
2958
3007
  }
2959
3008
  }
2960
3009
  function createSalesClient(config) {
3010
+ if (config.firing) registerCapability("conversion_goals_manual");
2961
3011
  async function record(input) {
2962
3012
  const currency = input.currency ?? config.defaultCurrency;
2963
3013
  if (!currency) {
@@ -3253,6 +3303,7 @@ var DEFAULT_CHOICE2 = {
3253
3303
  expiresAt: null
3254
3304
  };
3255
3305
  function useCookiePreferences(options) {
3306
+ registerCapability("consent_controls");
3256
3307
  const [choice, setChoice] = useState(DEFAULT_CHOICE2);
3257
3308
  const ttlDays = options?.declineTtlDays;
3258
3309
  useEffect(() => {
@@ -3515,6 +3566,12 @@ function AdPlatformTracking({
3515
3566
  () => metaPixelIds ? JSON.stringify(metaPixelIds) : "",
3516
3567
  [metaPixelIds]
3517
3568
  );
3569
+ if (trackingConfig || gtagId || gtagIds && Object.keys(gtagIds).length > 0) {
3570
+ registerCapability("ad_tags_google");
3571
+ }
3572
+ if (metaPixelId || metaPixelIds && Object.keys(metaPixelIds).length > 0) {
3573
+ registerCapability("ad_tags_meta");
3574
+ }
3518
3575
  useEffect3(() => {
3519
3576
  if (trackingConfig) {
3520
3577
  const runtime = getTrackingConfigRuntime(trackingConfig);
@@ -3555,7 +3612,7 @@ function GoogleAdsTracking(props) {
3555
3612
  import { createContext as createContext2, useContext as useContext2, useEffect as useEffect5, useMemo as useMemo4 } from "react";
3556
3613
 
3557
3614
  // package.json
3558
- var version = "0.20.2";
3615
+ var version = "0.22.0";
3559
3616
 
3560
3617
  // ../tracking-core/src/phone-react.tsx
3561
3618
  import {
@@ -3586,6 +3643,7 @@ function usePhoneConfig() {
3586
3643
  };
3587
3644
  }
3588
3645
  function usePhoneField(opts = {}) {
3646
+ registerCapability("phone_fields");
3589
3647
  const cfg = usePhoneConfig();
3590
3648
  const country = opts.country ?? cfg.defaultCountry;
3591
3649
  const display = opts.display ?? cfg.display;
@@ -3671,6 +3729,8 @@ function createTracking(options) {
3671
3729
  conversionConfig,
3672
3730
  trackingConfig
3673
3731
  } = options;
3732
+ registerCapability("base_tracking");
3733
+ if (trackingConfig) registerCapability("conversion_goals_auto");
3674
3734
  if (!apiKey || !endpoint) {
3675
3735
  if (apiKey || endpoint) {
3676
3736
  console.warn(