@moonbase.sh/react 0.0.0-next-20261111151018 → 0.0.0-next-20261111164652

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/README.md CHANGED
@@ -103,7 +103,7 @@ identity across renders, so it can go in a dependency list or to a memoized chil
103
103
  - `useCommunicationPreferences()` - newsletter sign-ups, and the preferences page an email's footer links to.
104
104
  - `useVendor()` - who runs the store.
105
105
  - `useStorefront()` - the storefront itself, and `useStorefrontState(state => ...)` for any part of its state
106
- (`catalog`, `catalogLoaded`, `closed`, `order`, `user`, `userLoaded`, `utm`).
106
+ (`attributionConsentStatus`, `catalog`, `catalogLoaded`, `closed`, `order`, `user`, `userLoaded`, `utm`).
107
107
 
108
108
  ### Where checkout happens
109
109
 
@@ -226,7 +226,12 @@ onConsentUpdate(({ adUserData, adPersonalization }) => storefront.setAttribution
226
226
 
227
227
  The cart, checkout, sign-up, trial, newsletter subscription and download requests also tell Moonbase what your banner
228
228
  reported (nothing until it reports) and when and on which page (origin and path only) a tagged visit first landed.
229
- `storefront.adSignals()` returns what they send.
229
+ Where the store connected Meta or Google Analytics in Moonbase, and the visitor's consent lets click IDs go, they also
230
+ carry the visitor's Meta and Google Analytics browser IDs (read from the `_fbp`, `_fbc`, `_ga` and `_ga_<stream>`
231
+ cookies as each request is made) and the page's origin and path. `storefront.adSignals()` returns what they send, and
232
+ `attributionConsentStatus` in the storefront's state says where the visitor's consent stands (`'granted'`, `'refused'`
233
+ or `'unknown'`). When your banner reports a refusal for a signed-in customer, the storefront tells Moonbase, once per
234
+ tab.
230
235
 
231
236
  ## Server rendering
232
237
 
package/dist/index.cjs CHANGED
@@ -54,7 +54,7 @@ module.exports = __toCommonJS(index_exports);
54
54
  var import_storefront_api11 = require("@moonbase.sh/storefront-api");
55
55
 
56
56
  // package.json
57
- var version = "0.0.0-next-20261111151018";
57
+ var version = "0.0.0-next-20261111164652";
58
58
 
59
59
  // src/storefront.ts
60
60
  var import_storefront_api5 = require("@moonbase.sh/storefront-api");
@@ -627,6 +627,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
627
627
  this.cart = createCart(this, { setOrder: (order2) => this.setState({ order: order2 }) });
628
628
  const initialCatalog = options.initialCatalog ? _MoonbaseStorefront.normalizeCatalog(options.initialCatalog) : emptyCatalog();
629
629
  this.serverState = {
630
+ attributionConsentStatus: "unknown",
630
631
  catalog: initialCatalog,
631
632
  catalogLoaded: !!options.initialCatalog,
632
633
  closed: false,
@@ -693,7 +694,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
693
694
  }
694
695
  const cachedCatalogJson = (0, import_storefront_api5.readStorage)(_MoonbaseStorefront.storefrontKey);
695
696
  const cachedCatalog = cachedCatalogJson ? _MoonbaseStorefront.parseCachedCatalog(cachedCatalogJson) : null;
696
- const catalog = cachedCatalog != null ? cachedCatalog : this.serverState.catalog;
697
+ const catalog = cachedCatalog ? { ...cachedCatalog, tracking: void 0 } : this.serverState.catalog;
697
698
  const cachedOrder = _MoonbaseStorefront.parseCachedOrder((0, import_storefront_api5.readStorage)(_MoonbaseStorefront.sessionKey));
698
699
  const order = cachedOrder != null ? cachedOrder : newOrder();
699
700
  let user = null;
@@ -706,6 +707,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
706
707
  }
707
708
  }
708
709
  this.state = {
710
+ attributionConsentStatus: this.consentStatus(),
709
711
  catalog,
710
712
  catalogLoaded: !!cachedCatalog || this.serverState.catalogLoaded,
711
713
  closed: false,
@@ -718,6 +720,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
718
720
  };
719
721
  if (this.state.catalogLoaded)
720
722
  this.resolveCatalogLoaded();
723
+ void this.reportAdConsentRefusal();
721
724
  if (cachedOrder) {
722
725
  void this.refreshOrder();
723
726
  } else if (this.hasUtmOrReferrer && this.attributionConsent) {
@@ -802,6 +805,8 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
802
805
  const before = this.attributionConsent;
803
806
  this.attributionConsentSetting = (0, import_storefront_api5.copyConsent)(granted);
804
807
  this.attributionConsentChanged(before);
808
+ this.setState({ attributionConsentStatus: this.consentStatus() });
809
+ void this.reportAdConsentRefusal();
805
810
  if ((0, import_storefront_api5.grantsClickIds)(this.attributionConsentSetting) === false && typeof window !== "undefined") {
806
811
  if (this.hasUtmOrReferrer)
807
812
  (0, import_storefront_api5.writeStorage)(_MoonbaseStorefront.utmKey, JSON.stringify(this.state.utm), "session");
@@ -814,14 +819,17 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
814
819
  /**
815
820
  * What the storefront's requests say of the visit for ad measurement, beside `utm`: what the site last
816
821
  * reported of the visitor's consent, left out until it says, and when and on which page the visit's
817
- * tagged arrival landed, left out for a visit without tags.
822
+ * tagged arrival landed, left out for a visit without tags. Where the store connected Meta or Google
823
+ * Analytics in Moonbase, and while the visitor's consent lets click IDs go, also their browser IDs and
824
+ * the page the request is made on.
818
825
  */
819
826
  adSignals() {
820
827
  const landing = (0, import_storefront_api5.hasCampaignData)(this.state.utm) ? this.landing : void 0;
821
828
  return {
822
829
  consent: (0, import_storefront_api5.copyConsent)(this.attributionConsentSetting),
823
830
  arrivedAt: landing == null ? void 0 : landing.arrivedAt,
824
- landingPage: landing == null ? void 0 : landing.landingPage
831
+ landingPage: landing == null ? void 0 : landing.landingPage,
832
+ ...this.browserIdentifiers(landing)
825
833
  };
826
834
  }
827
835
  /** Asks Moonbase who is signed in. `state.user` is null when nobody is, or the session has run out. */
@@ -868,6 +876,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
868
876
  const consentedBefore = this.attributionConsent;
869
877
  this.storeAllowsAttribution = latest.cookieConsentRequired === false;
870
878
  this.attributionConsentChanged(consentedBefore);
879
+ this.setState({ attributionConsentStatus: this.consentStatus() });
871
880
  if (typeof window !== "undefined")
872
881
  window.dispatchEvent(new CustomEvent("moonbase-storefront-updated", { detail: { storefront: latest } }));
873
882
  return latest;
@@ -945,6 +954,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
945
954
  const keys = Object.keys(patch);
946
955
  if (keys.every((key) => Object.is(this.state[key], patch[key])))
947
956
  return;
957
+ const before = this.state;
948
958
  this.state = { ...this.state, ...patch };
949
959
  if (this.state.catalogLoaded)
950
960
  this.resolveCatalogLoaded();
@@ -952,6 +962,8 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
952
962
  this.resolveUserLoaded();
953
963
  for (const listener of [...this.listeners])
954
964
  listener();
965
+ if (this.state.user !== before.user)
966
+ void this.reportAdConsentRefusal();
955
967
  }
956
968
  /**
957
969
  * The server refused to renew the buyer's session: they signed out of it elsewhere, changed their
@@ -1021,6 +1033,57 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
1021
1033
  consentedUtm(utm) {
1022
1034
  return this.attributionConsent ? utm : (0, import_storefront_api5.withoutClickIds)(utm);
1023
1035
  }
1036
+ /**
1037
+ * The visitor's Meta and Google Analytics browser IDs, and this page, for a store that connected either
1038
+ * in Moonbase, while the visitor's consent lets click IDs go. Read as each request is made, since the
1039
+ * vendors' tags write their cookies after the storefront starts.
1040
+ */
1041
+ browserIdentifiers(landing) {
1042
+ var _a, _b, _c, _d, _e;
1043
+ const tracking = this.state.catalog.tracking;
1044
+ const meta = ((_b = (_a = tracking == null ? void 0 : tracking.meta) == null ? void 0 : _a.pixels.length) != null ? _b : 0) > 0;
1045
+ const googleAnalytics = (_d = (_c = tracking == null ? void 0 : tracking.googleAnalytics) == null ? void 0 : _c.streams.map((stream) => stream.id)) != null ? _d : [];
1046
+ if (!meta && googleAnalytics.length === 0 || !this.attributionConsent || typeof window === "undefined" || (0, import_storefront_api5.sendsGlobalPrivacyControl)())
1047
+ return {};
1048
+ return {
1049
+ ...(0, import_storefront_api5.readBrowserIdentifiers)({
1050
+ cookies: (0, import_storefront_api5.readCookies)(),
1051
+ meta,
1052
+ googleAnalytics,
1053
+ arrival: { fbclid: (_e = this.state.utm) == null ? void 0 : _e.fbclid, arrivedAt: landing == null ? void 0 : landing.arrivedAt }
1054
+ }),
1055
+ pageUrl: `${window.location.origin}${window.location.pathname}`
1056
+ };
1057
+ }
1058
+ consentStatus() {
1059
+ return (0, import_storefront_api5.grantsClickIds)(this.attributionConsentSetting) === false || (0, import_storefront_api5.sendsGlobalPrivacyControl)() ? "refused" : this.attributionConsent ? "granted" : "unknown";
1060
+ }
1061
+ /**
1062
+ * Tells Moonbase when the site reports that a signed-in customer refuses ad tracking, which renewals
1063
+ * and other events sent without a visit then follow. Once per tab for each customer and report, as a
1064
+ * site's banner often reports the same choice on every page.
1065
+ */
1066
+ async reportAdConsentRefusal() {
1067
+ if (typeof window === "undefined")
1068
+ return;
1069
+ const user = this.state.user;
1070
+ const consent = this.attributionConsentSetting;
1071
+ const globalPrivacyControl = (0, import_storefront_api5.sendsGlobalPrivacyControl)();
1072
+ if (!(0, import_storefront_api5.refusesAny)(consent) && !globalPrivacyControl) {
1073
+ if (consent !== void 0)
1074
+ (0, import_storefront_api5.removeStorage)(_MoonbaseStorefront.adConsentReportedKey, "session");
1075
+ return;
1076
+ }
1077
+ const reported = JSON.stringify({ user: user == null ? void 0 : user.id, consent, globalPrivacyControl });
1078
+ if (!user || (0, import_storefront_api5.readStorage)(_MoonbaseStorefront.adConsentReportedKey, "session") === reported)
1079
+ return;
1080
+ (0, import_storefront_api5.writeStorage)(_MoonbaseStorefront.adConsentReportedKey, reported, "session");
1081
+ try {
1082
+ await this.client.identity.reportAdConsent(this.adSignals());
1083
+ } catch (e) {
1084
+ (0, import_storefront_api5.removeStorage)(_MoonbaseStorefront.adConsentReportedKey, "session");
1085
+ }
1086
+ }
1024
1087
  handleStorageUpdate(event) {
1025
1088
  var _a;
1026
1089
  switch (event.key) {
@@ -1131,6 +1194,7 @@ _MoonbaseStorefront.sessionKey = "moonbase_session";
1131
1194
  _MoonbaseStorefront.storefrontKey = "moonbase_storefront";
1132
1195
  _MoonbaseStorefront.utmKey = "moonbase_utm";
1133
1196
  _MoonbaseStorefront.arrivalKey = "moonbase_arrival";
1197
+ _MoonbaseStorefront.adConsentReportedKey = "moonbase_ad_consent_reported";
1134
1198
  var MoonbaseStorefront = _MoonbaseStorefront;
1135
1199
 
1136
1200
  // src/provider.ts
package/dist/index.d.cts CHANGED
@@ -127,8 +127,15 @@ interface StorefrontCart {
127
127
  removeCartOffer: () => Promise<void>;
128
128
  }
129
129
 
130
+ type AttributionConsentStatus = 'granted' | 'refused' | 'unknown';
130
131
  /** Everything a storefront knows that a page draws from. Replaced, never changed in place, on every update. */
131
132
  interface StorefrontState {
133
+ /**
134
+ * Where the visitor's consent to marketing cookies stands: `'refused'` once the site reports a refusal,
135
+ * `'granted'` once the site reports consent or the store's own setting lets them go unasked, and
136
+ * `'unknown'` until either says.
137
+ */
138
+ attributionConsentStatus: AttributionConsentStatus;
132
139
  /**
133
140
  * The store's catalog for this visitor: products, bundles, offers and promotions, priced in their
134
141
  * currency, with `owned` worked out for whoever is signed in. Starts from the copy this browser
@@ -220,6 +227,7 @@ declare class MoonbaseStorefront {
220
227
  static readonly storefrontKey = "moonbase_storefront";
221
228
  static readonly utmKey = "moonbase_utm";
222
229
  static readonly arrivalKey = "moonbase_arrival";
230
+ static readonly adConsentReportedKey = "moonbase_ad_consent_reported";
223
231
  /**
224
232
  * Whether the cart attaches eligible item-scope offers by itself. See
225
233
  * `StorefrontOptions.autoApplyItemOffers`. Read on every cart change.
@@ -301,7 +309,9 @@ declare class MoonbaseStorefront {
301
309
  /**
302
310
  * What the storefront's requests say of the visit for ad measurement, beside `utm`: what the site last
303
311
  * reported of the visitor's consent, left out until it says, and when and on which page the visit's
304
- * tagged arrival landed, left out for a visit without tags.
312
+ * tagged arrival landed, left out for a visit without tags. Where the store connected Meta or Google
313
+ * Analytics in Moonbase, and while the visitor's consent lets click IDs go, also their browser IDs and
314
+ * the page the request is made on.
305
315
  */
306
316
  adSignals(): AdSignals;
307
317
  /** Asks Moonbase who is signed in. `state.user` is null when nobody is, or the session has run out. */
@@ -352,6 +362,19 @@ declare class MoonbaseStorefront {
352
362
  private storeLanding;
353
363
  /** `utm` as the storefront may keep and send it: with its ad click IDs only once the visitor agreed. */
354
364
  private consentedUtm;
365
+ /**
366
+ * The visitor's Meta and Google Analytics browser IDs, and this page, for a store that connected either
367
+ * in Moonbase, while the visitor's consent lets click IDs go. Read as each request is made, since the
368
+ * vendors' tags write their cookies after the storefront starts.
369
+ */
370
+ private browserIdentifiers;
371
+ private consentStatus;
372
+ /**
373
+ * Tells Moonbase when the site reports that a signed-in customer refuses ad tracking, which renewals
374
+ * and other events sent without a visit then follow. Once per tab for each customer and report, as a
375
+ * site's banner often reports the same choice on every page.
376
+ */
377
+ private reportAdConsentRefusal;
355
378
  private handleStorageUpdate;
356
379
  private refreshOrder;
357
380
  private static parseCachedUtm;
@@ -667,4 +690,4 @@ declare function useStorefrontEvent<K extends keyof StorefrontEvents>(event: K,
667
690
  */
668
691
  declare function createStorefront(endpoint: string, options?: StorefrontOptions): MoonbaseStorefront;
669
692
 
670
- export { type ActivationRequestState, type AddToCartOptions, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VendorState, type Vouchers, createStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrders, useProduct, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useVendor, useVoucher };
693
+ export { type ActivationRequestState, type AddToCartOptions, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VendorState, type Vouchers, createStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrders, useProduct, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useVendor, useVoucher };
package/dist/index.d.ts CHANGED
@@ -127,8 +127,15 @@ interface StorefrontCart {
127
127
  removeCartOffer: () => Promise<void>;
128
128
  }
129
129
 
130
+ type AttributionConsentStatus = 'granted' | 'refused' | 'unknown';
130
131
  /** Everything a storefront knows that a page draws from. Replaced, never changed in place, on every update. */
131
132
  interface StorefrontState {
133
+ /**
134
+ * Where the visitor's consent to marketing cookies stands: `'refused'` once the site reports a refusal,
135
+ * `'granted'` once the site reports consent or the store's own setting lets them go unasked, and
136
+ * `'unknown'` until either says.
137
+ */
138
+ attributionConsentStatus: AttributionConsentStatus;
132
139
  /**
133
140
  * The store's catalog for this visitor: products, bundles, offers and promotions, priced in their
134
141
  * currency, with `owned` worked out for whoever is signed in. Starts from the copy this browser
@@ -220,6 +227,7 @@ declare class MoonbaseStorefront {
220
227
  static readonly storefrontKey = "moonbase_storefront";
221
228
  static readonly utmKey = "moonbase_utm";
222
229
  static readonly arrivalKey = "moonbase_arrival";
230
+ static readonly adConsentReportedKey = "moonbase_ad_consent_reported";
223
231
  /**
224
232
  * Whether the cart attaches eligible item-scope offers by itself. See
225
233
  * `StorefrontOptions.autoApplyItemOffers`. Read on every cart change.
@@ -301,7 +309,9 @@ declare class MoonbaseStorefront {
301
309
  /**
302
310
  * What the storefront's requests say of the visit for ad measurement, beside `utm`: what the site last
303
311
  * reported of the visitor's consent, left out until it says, and when and on which page the visit's
304
- * tagged arrival landed, left out for a visit without tags.
312
+ * tagged arrival landed, left out for a visit without tags. Where the store connected Meta or Google
313
+ * Analytics in Moonbase, and while the visitor's consent lets click IDs go, also their browser IDs and
314
+ * the page the request is made on.
305
315
  */
306
316
  adSignals(): AdSignals;
307
317
  /** Asks Moonbase who is signed in. `state.user` is null when nobody is, or the session has run out. */
@@ -352,6 +362,19 @@ declare class MoonbaseStorefront {
352
362
  private storeLanding;
353
363
  /** `utm` as the storefront may keep and send it: with its ad click IDs only once the visitor agreed. */
354
364
  private consentedUtm;
365
+ /**
366
+ * The visitor's Meta and Google Analytics browser IDs, and this page, for a store that connected either
367
+ * in Moonbase, while the visitor's consent lets click IDs go. Read as each request is made, since the
368
+ * vendors' tags write their cookies after the storefront starts.
369
+ */
370
+ private browserIdentifiers;
371
+ private consentStatus;
372
+ /**
373
+ * Tells Moonbase when the site reports that a signed-in customer refuses ad tracking, which renewals
374
+ * and other events sent without a visit then follow. Once per tab for each customer and report, as a
375
+ * site's banner often reports the same choice on every page.
376
+ */
377
+ private reportAdConsentRefusal;
355
378
  private handleStorageUpdate;
356
379
  private refreshOrder;
357
380
  private static parseCachedUtm;
@@ -667,4 +690,4 @@ declare function useStorefrontEvent<K extends keyof StorefrontEvents>(event: K,
667
690
  */
668
691
  declare function createStorefront(endpoint: string, options?: StorefrontOptions): MoonbaseStorefront;
669
692
 
670
- export { type ActivationRequestState, type AddToCartOptions, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VendorState, type Vouchers, createStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrders, useProduct, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useVendor, useVoucher };
693
+ export { type ActivationRequestState, type AddToCartOptions, type AttributionConsentStatus, type Auth, type Cart, type CartCheckoutOptions, type CartItem, type CartOfferState, type CheckoutItem, type CheckoutOptions, type CheckoutRedirectOptions, type CheckoutResult, type Communications, type Groups, type LockedOffer, MoonbaseStorefront, type Orders, type ProductReviews, type StorefrontAuth, type StorefrontCart, type StorefrontEvents, type StorefrontInventory, type StorefrontOptions, StorefrontProvider, type StorefrontProviderProps, type StorefrontState, type VendorState, type Vouchers, createStorefront, useActivationRequest, useAuth, useBundle, useBundles, useCart, useCartOffer, useCatalog, useCheckout, useCommunicationPreferences, useEligibleOffers, useGroups, useInventory, useLockedOffers, useOffer, useOffers, useOrders, useProduct, useProducts, usePromotions, useReviews, useStorefront, useStorefrontEvent, useStorefrontState, useVendor, useVoucher };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { MoonbaseClient } from "@moonbase.sh/storefront-api";
3
3
 
4
4
  // package.json
5
- var version = "0.0.0-next-20261111151018";
5
+ var version = "0.0.0-next-20261111164652";
6
6
 
7
7
  // src/storefront.ts
8
8
  import {
@@ -23,11 +23,15 @@ import {
23
23
  parseLanding,
24
24
  parseOffSiteReferrer,
25
25
  pruneRememberedPurchase,
26
+ readBrowserIdentifiers,
27
+ readCookies,
26
28
  readStorage,
29
+ refusesAny,
27
30
  removeStorage,
28
31
  resolveDisplayCurrency as resolveDisplayCurrency3,
29
32
  resolveUtm,
30
33
  schemas as schemas2,
34
+ sendsGlobalPrivacyControl,
31
35
  StoreClosedError,
32
36
  TokenStore,
33
37
  withoutClickIds,
@@ -637,6 +641,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
637
641
  this.cart = createCart(this, { setOrder: (order2) => this.setState({ order: order2 }) });
638
642
  const initialCatalog = options.initialCatalog ? _MoonbaseStorefront.normalizeCatalog(options.initialCatalog) : emptyCatalog();
639
643
  this.serverState = {
644
+ attributionConsentStatus: "unknown",
640
645
  catalog: initialCatalog,
641
646
  catalogLoaded: !!options.initialCatalog,
642
647
  closed: false,
@@ -703,7 +708,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
703
708
  }
704
709
  const cachedCatalogJson = readStorage(_MoonbaseStorefront.storefrontKey);
705
710
  const cachedCatalog = cachedCatalogJson ? _MoonbaseStorefront.parseCachedCatalog(cachedCatalogJson) : null;
706
- const catalog = cachedCatalog != null ? cachedCatalog : this.serverState.catalog;
711
+ const catalog = cachedCatalog ? { ...cachedCatalog, tracking: void 0 } : this.serverState.catalog;
707
712
  const cachedOrder = _MoonbaseStorefront.parseCachedOrder(readStorage(_MoonbaseStorefront.sessionKey));
708
713
  const order = cachedOrder != null ? cachedOrder : newOrder();
709
714
  let user = null;
@@ -716,6 +721,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
716
721
  }
717
722
  }
718
723
  this.state = {
724
+ attributionConsentStatus: this.consentStatus(),
719
725
  catalog,
720
726
  catalogLoaded: !!cachedCatalog || this.serverState.catalogLoaded,
721
727
  closed: false,
@@ -728,6 +734,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
728
734
  };
729
735
  if (this.state.catalogLoaded)
730
736
  this.resolveCatalogLoaded();
737
+ void this.reportAdConsentRefusal();
731
738
  if (cachedOrder) {
732
739
  void this.refreshOrder();
733
740
  } else if (this.hasUtmOrReferrer && this.attributionConsent) {
@@ -812,6 +819,8 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
812
819
  const before = this.attributionConsent;
813
820
  this.attributionConsentSetting = copyConsent(granted);
814
821
  this.attributionConsentChanged(before);
822
+ this.setState({ attributionConsentStatus: this.consentStatus() });
823
+ void this.reportAdConsentRefusal();
815
824
  if (grantsClickIds(this.attributionConsentSetting) === false && typeof window !== "undefined") {
816
825
  if (this.hasUtmOrReferrer)
817
826
  writeStorage(_MoonbaseStorefront.utmKey, JSON.stringify(this.state.utm), "session");
@@ -824,14 +833,17 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
824
833
  /**
825
834
  * What the storefront's requests say of the visit for ad measurement, beside `utm`: what the site last
826
835
  * reported of the visitor's consent, left out until it says, and when and on which page the visit's
827
- * tagged arrival landed, left out for a visit without tags.
836
+ * tagged arrival landed, left out for a visit without tags. Where the store connected Meta or Google
837
+ * Analytics in Moonbase, and while the visitor's consent lets click IDs go, also their browser IDs and
838
+ * the page the request is made on.
828
839
  */
829
840
  adSignals() {
830
841
  const landing = hasCampaignData(this.state.utm) ? this.landing : void 0;
831
842
  return {
832
843
  consent: copyConsent(this.attributionConsentSetting),
833
844
  arrivedAt: landing == null ? void 0 : landing.arrivedAt,
834
- landingPage: landing == null ? void 0 : landing.landingPage
845
+ landingPage: landing == null ? void 0 : landing.landingPage,
846
+ ...this.browserIdentifiers(landing)
835
847
  };
836
848
  }
837
849
  /** Asks Moonbase who is signed in. `state.user` is null when nobody is, or the session has run out. */
@@ -878,6 +890,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
878
890
  const consentedBefore = this.attributionConsent;
879
891
  this.storeAllowsAttribution = latest.cookieConsentRequired === false;
880
892
  this.attributionConsentChanged(consentedBefore);
893
+ this.setState({ attributionConsentStatus: this.consentStatus() });
881
894
  if (typeof window !== "undefined")
882
895
  window.dispatchEvent(new CustomEvent("moonbase-storefront-updated", { detail: { storefront: latest } }));
883
896
  return latest;
@@ -955,6 +968,7 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
955
968
  const keys = Object.keys(patch);
956
969
  if (keys.every((key) => Object.is(this.state[key], patch[key])))
957
970
  return;
971
+ const before = this.state;
958
972
  this.state = { ...this.state, ...patch };
959
973
  if (this.state.catalogLoaded)
960
974
  this.resolveCatalogLoaded();
@@ -962,6 +976,8 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
962
976
  this.resolveUserLoaded();
963
977
  for (const listener of [...this.listeners])
964
978
  listener();
979
+ if (this.state.user !== before.user)
980
+ void this.reportAdConsentRefusal();
965
981
  }
966
982
  /**
967
983
  * The server refused to renew the buyer's session: they signed out of it elsewhere, changed their
@@ -1031,6 +1047,57 @@ var _MoonbaseStorefront = class _MoonbaseStorefront {
1031
1047
  consentedUtm(utm) {
1032
1048
  return this.attributionConsent ? utm : withoutClickIds(utm);
1033
1049
  }
1050
+ /**
1051
+ * The visitor's Meta and Google Analytics browser IDs, and this page, for a store that connected either
1052
+ * in Moonbase, while the visitor's consent lets click IDs go. Read as each request is made, since the
1053
+ * vendors' tags write their cookies after the storefront starts.
1054
+ */
1055
+ browserIdentifiers(landing) {
1056
+ var _a, _b, _c, _d, _e;
1057
+ const tracking = this.state.catalog.tracking;
1058
+ const meta = ((_b = (_a = tracking == null ? void 0 : tracking.meta) == null ? void 0 : _a.pixels.length) != null ? _b : 0) > 0;
1059
+ const googleAnalytics = (_d = (_c = tracking == null ? void 0 : tracking.googleAnalytics) == null ? void 0 : _c.streams.map((stream) => stream.id)) != null ? _d : [];
1060
+ if (!meta && googleAnalytics.length === 0 || !this.attributionConsent || typeof window === "undefined" || sendsGlobalPrivacyControl())
1061
+ return {};
1062
+ return {
1063
+ ...readBrowserIdentifiers({
1064
+ cookies: readCookies(),
1065
+ meta,
1066
+ googleAnalytics,
1067
+ arrival: { fbclid: (_e = this.state.utm) == null ? void 0 : _e.fbclid, arrivedAt: landing == null ? void 0 : landing.arrivedAt }
1068
+ }),
1069
+ pageUrl: `${window.location.origin}${window.location.pathname}`
1070
+ };
1071
+ }
1072
+ consentStatus() {
1073
+ return grantsClickIds(this.attributionConsentSetting) === false || sendsGlobalPrivacyControl() ? "refused" : this.attributionConsent ? "granted" : "unknown";
1074
+ }
1075
+ /**
1076
+ * Tells Moonbase when the site reports that a signed-in customer refuses ad tracking, which renewals
1077
+ * and other events sent without a visit then follow. Once per tab for each customer and report, as a
1078
+ * site's banner often reports the same choice on every page.
1079
+ */
1080
+ async reportAdConsentRefusal() {
1081
+ if (typeof window === "undefined")
1082
+ return;
1083
+ const user = this.state.user;
1084
+ const consent = this.attributionConsentSetting;
1085
+ const globalPrivacyControl = sendsGlobalPrivacyControl();
1086
+ if (!refusesAny(consent) && !globalPrivacyControl) {
1087
+ if (consent !== void 0)
1088
+ removeStorage(_MoonbaseStorefront.adConsentReportedKey, "session");
1089
+ return;
1090
+ }
1091
+ const reported = JSON.stringify({ user: user == null ? void 0 : user.id, consent, globalPrivacyControl });
1092
+ if (!user || readStorage(_MoonbaseStorefront.adConsentReportedKey, "session") === reported)
1093
+ return;
1094
+ writeStorage(_MoonbaseStorefront.adConsentReportedKey, reported, "session");
1095
+ try {
1096
+ await this.client.identity.reportAdConsent(this.adSignals());
1097
+ } catch (e) {
1098
+ removeStorage(_MoonbaseStorefront.adConsentReportedKey, "session");
1099
+ }
1100
+ }
1034
1101
  handleStorageUpdate(event) {
1035
1102
  var _a;
1036
1103
  switch (event.key) {
@@ -1141,6 +1208,7 @@ _MoonbaseStorefront.sessionKey = "moonbase_session";
1141
1208
  _MoonbaseStorefront.storefrontKey = "moonbase_storefront";
1142
1209
  _MoonbaseStorefront.utmKey = "moonbase_utm";
1143
1210
  _MoonbaseStorefront.arrivalKey = "moonbase_arrival";
1211
+ _MoonbaseStorefront.adConsentReportedKey = "moonbase_ad_consent_reported";
1144
1212
  var MoonbaseStorefront = _MoonbaseStorefront;
1145
1213
 
1146
1214
  // src/provider.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/react",
3
3
  "type": "module",
4
- "version": "0.0.0-next-20261111151018",
4
+ "version": "0.0.0-next-20261111164652",
5
5
  "description": "Package to let you build React storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "react": ">=18"
17
17
  },
18
18
  "dependencies": {
19
- "@moonbase.sh/storefront-api": "0.0.0-next-20261111151018",
19
+ "@moonbase.sh/storefront-api": "0.0.0-next-20261111164652",
20
20
  "uuid": "^9.0.1"
21
21
  },
22
22
  "devDependencies": {