@fire-spark/analytics 0.29.0 → 0.31.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.d.ts CHANGED
@@ -777,7 +777,7 @@ declare const customAdapter: (options: CustomAdapterOptions) => CustomAnalyticsA
777
777
  //#endregion
778
778
  //#region src/version.d.ts
779
779
  /** Kept equal to package.json by `pnpm sdk:release` (see version.test.ts). */
780
- declare const SDK_VERSION = "0.29.0";
780
+ declare const SDK_VERSION = "0.31.0";
781
781
  //#endregion
782
782
  //#region src/compact.d.ts
783
783
  /** Drops `undefined`, `null`, non-finite numbers and functions, deeply. */
package/dist/index.js CHANGED
@@ -1000,7 +1000,7 @@ const transformForProvider = (provider, input) => {
1000
1000
  //#endregion
1001
1001
  //#region src/version.ts
1002
1002
  /** Kept equal to package.json by `pnpm sdk:release` (see version.test.ts). */
1003
- const SDK_VERSION = "0.29.0";
1003
+ const SDK_VERSION = "0.31.0";
1004
1004
  //#endregion
1005
1005
  //#region src/contract.ts
1006
1006
  const TRACKING_CONTRACT_VERSION = 1;
@@ -3486,6 +3486,7 @@ const runFlush = async (rt) => {
3486
3486
  }
3487
3487
  if (!await isOnline(rt)) return;
3488
3488
  const entries = await pruneExpired(rt, Date.now());
3489
+ if (entries.length === 0) return;
3489
3490
  const token = await tokenOf(rt, false);
3490
3491
  if (!token) {
3491
3492
  warnRelayOnce(rt, "no-token", "getAuthToken returned no token; relay events stay queued");
@@ -3526,9 +3527,14 @@ const pageReferrer = () => {
3526
3527
  const doc = globalThis.document;
3527
3528
  return textOf(doc?.referrer);
3528
3529
  };
3529
- const buildRelayEvent = async (rt, event) => {
3530
- const relay = rt.serverSide;
3531
- if (!relay) return null;
3530
+ const selectedProviders = (configured, opts) => {
3531
+ const list = [...configured];
3532
+ if (opts?.only) return list.filter((id) => opts.only?.includes(id));
3533
+ if (opts?.exclude) return list.filter((id) => !opts.exclude?.includes(id));
3534
+ return list;
3535
+ };
3536
+ const buildRelayEvent = async (rt, event, providers) => {
3537
+ if (!rt.serverSide) return null;
3532
3538
  if (!resolveConsent(rt).ads) return null;
3533
3539
  const sourceUrl = pageHref();
3534
3540
  if (!sourceUrl) return null;
@@ -3563,7 +3569,7 @@ const buildRelayEvent = async (rt, event) => {
3563
3569
  consent: wireConsent
3564
3570
  };
3565
3571
  const i5 = {
3566
- providers: [...relay.providers],
3572
+ providers,
3567
3573
  context: scopeContext(rt)
3568
3574
  };
3569
3575
  return buildTrackingEvent({
@@ -3642,7 +3648,7 @@ const scheduleRelayFlush = (rt) => {
3642
3648
  * id (the id the Meta SDK copy gets), and never on iOS without ATT
3643
3649
  * `authorized`.
3644
3650
  */
3645
- const buildAppRelayEvent = async (rt, event) => {
3651
+ const buildAppRelayEvent = async (rt, event, providers) => {
3646
3652
  const relay = rt.serverSide;
3647
3653
  if (!relay || !APP_RELAYED_EVENTS.has(event.event.name)) return null;
3648
3654
  if (!resolveConsent(rt).ads) return null;
@@ -3682,7 +3688,7 @@ const buildAppRelayEvent = async (rt, event) => {
3682
3688
  consent: wireConsent
3683
3689
  };
3684
3690
  const i4 = {
3685
- providers: [...relay.providers],
3691
+ providers,
3686
3692
  context
3687
3693
  };
3688
3694
  return buildTrackingEvent({
@@ -3692,19 +3698,21 @@ const buildAppRelayEvent = async (rt, event) => {
3692
3698
  ...i4
3693
3699
  });
3694
3700
  };
3695
- const relayAppTrack = async (rt, event) => {
3701
+ const relayAppTrack = async (rt, event, providers) => {
3696
3702
  if (rt.relayDisabled) return;
3697
- const built = await buildAppRelayEvent(rt, event);
3703
+ const built = await buildAppRelayEvent(rt, event, providers);
3698
3704
  if (!built) return;
3699
3705
  await enqueueOutbox(rt, built, event.at);
3700
3706
  await flushOutbox(rt);
3701
3707
  };
3702
3708
  /** Builds and buffers a contract event, flushing per `batchSize`/purchase. */
3703
- const relayTrack = async (rt, event) => {
3709
+ const relayTrack = async (rt, event, opts) => {
3704
3710
  const relay = rt.serverSide;
3705
3711
  if (!relay || relay.providers.size === 0) return;
3706
- if (relay.runtime === "react-native") return relayAppTrack(rt, event);
3707
- const built = await buildRelayEvent(rt, event);
3712
+ const providers = selectedProviders(relay.providers, opts);
3713
+ if (providers.length === 0) return;
3714
+ if (relay.runtime === "react-native") return relayAppTrack(rt, event, providers);
3715
+ const built = await buildRelayEvent(rt, event, providers);
3708
3716
  if (!built) return;
3709
3717
  rt.relayBuffer.push(built);
3710
3718
  if (event.event.name === "purchase" || rt.relayBuffer.length >= relay.batchSize) {
@@ -4457,7 +4465,7 @@ const dispatch = async (rt, pending) => {
4457
4465
  event: event.name
4458
4466
  });
4459
4467
  });
4460
- const relayP = relayTrack(rt, item).catch((error) => {
4468
+ const relayP = relayTrack(rt, item, opts).catch((error) => {
4461
4469
  report(rt, {
4462
4470
  level: "error",
4463
4471
  source: "relay",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fire-spark/analytics",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "Fire Spark storefront analytics SDK",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "big.js": "6.2.1",
21
21
  "libphonenumber-js": "1.13.16",
22
- "@fire-spark/core": "^0.29.0"
22
+ "@fire-spark/core": "^0.31.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "tsdown": "^0.22.14",