@shopify/hydrogen-react 2025.7.0 → 2025.7.1

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.
Files changed (115) hide show
  1. package/dist/browser-dev/ShopifyProvider.mjs +18 -1
  2. package/dist/browser-dev/ShopifyProvider.mjs.map +1 -1
  3. package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs +4 -3
  4. package/dist/browser-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
  5. package/dist/browser-dev/analytics.mjs +4 -5
  6. package/dist/browser-dev/analytics.mjs.map +1 -1
  7. package/dist/browser-dev/cart-hooks.mjs +25 -7
  8. package/dist/browser-dev/cart-hooks.mjs.map +1 -1
  9. package/dist/browser-dev/cookies-utils.mjs +4 -4
  10. package/dist/browser-dev/cookies-utils.mjs.map +1 -1
  11. package/dist/browser-dev/index.mjs +4 -0
  12. package/dist/browser-dev/index.mjs.map +1 -1
  13. package/dist/browser-dev/packages/hydrogen-react/package.json.mjs +1 -1
  14. package/dist/browser-dev/tracking-utils.mjs +92 -0
  15. package/dist/browser-dev/tracking-utils.mjs.map +1 -0
  16. package/dist/browser-dev/useShopifyCookies.mjs +96 -9
  17. package/dist/browser-dev/useShopifyCookies.mjs.map +1 -1
  18. package/dist/browser-prod/ShopifyProvider.mjs +18 -1
  19. package/dist/browser-prod/ShopifyProvider.mjs.map +1 -1
  20. package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs +4 -3
  21. package/dist/browser-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
  22. package/dist/browser-prod/analytics.mjs +4 -5
  23. package/dist/browser-prod/analytics.mjs.map +1 -1
  24. package/dist/browser-prod/cart-hooks.mjs +25 -7
  25. package/dist/browser-prod/cart-hooks.mjs.map +1 -1
  26. package/dist/browser-prod/cookies-utils.mjs +4 -4
  27. package/dist/browser-prod/cookies-utils.mjs.map +1 -1
  28. package/dist/browser-prod/index.mjs +4 -0
  29. package/dist/browser-prod/index.mjs.map +1 -1
  30. package/dist/browser-prod/packages/hydrogen-react/package.json.mjs +1 -1
  31. package/dist/browser-prod/tracking-utils.mjs +92 -0
  32. package/dist/browser-prod/tracking-utils.mjs.map +1 -0
  33. package/dist/browser-prod/useShopifyCookies.mjs +96 -9
  34. package/dist/browser-prod/useShopifyCookies.mjs.map +1 -1
  35. package/dist/node-dev/ShopifyProvider.js +18 -1
  36. package/dist/node-dev/ShopifyProvider.js.map +1 -1
  37. package/dist/node-dev/ShopifyProvider.mjs +18 -1
  38. package/dist/node-dev/ShopifyProvider.mjs.map +1 -1
  39. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js +4 -3
  40. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.js.map +1 -1
  41. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs +4 -3
  42. package/dist/node-dev/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
  43. package/dist/node-dev/analytics.js +4 -5
  44. package/dist/node-dev/analytics.js.map +1 -1
  45. package/dist/node-dev/analytics.mjs +4 -5
  46. package/dist/node-dev/analytics.mjs.map +1 -1
  47. package/dist/node-dev/cart-hooks.js +24 -6
  48. package/dist/node-dev/cart-hooks.js.map +1 -1
  49. package/dist/node-dev/cart-hooks.mjs +25 -7
  50. package/dist/node-dev/cart-hooks.mjs.map +1 -1
  51. package/dist/node-dev/cookies-utils.js +4 -4
  52. package/dist/node-dev/cookies-utils.js.map +1 -1
  53. package/dist/node-dev/cookies-utils.mjs +4 -4
  54. package/dist/node-dev/cookies-utils.mjs.map +1 -1
  55. package/dist/node-dev/index.js +4 -0
  56. package/dist/node-dev/index.js.map +1 -1
  57. package/dist/node-dev/index.mjs +4 -0
  58. package/dist/node-dev/index.mjs.map +1 -1
  59. package/dist/node-dev/packages/hydrogen-react/package.json.js +1 -1
  60. package/dist/node-dev/packages/hydrogen-react/package.json.mjs +1 -1
  61. package/dist/node-dev/tracking-utils.js +92 -0
  62. package/dist/node-dev/tracking-utils.js.map +1 -0
  63. package/dist/node-dev/tracking-utils.mjs +92 -0
  64. package/dist/node-dev/tracking-utils.mjs.map +1 -0
  65. package/dist/node-dev/useShopifyCookies.js +94 -7
  66. package/dist/node-dev/useShopifyCookies.js.map +1 -1
  67. package/dist/node-dev/useShopifyCookies.mjs +96 -9
  68. package/dist/node-dev/useShopifyCookies.mjs.map +1 -1
  69. package/dist/node-prod/ShopifyProvider.js +18 -1
  70. package/dist/node-prod/ShopifyProvider.js.map +1 -1
  71. package/dist/node-prod/ShopifyProvider.mjs +18 -1
  72. package/dist/node-prod/ShopifyProvider.mjs.map +1 -1
  73. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js +4 -3
  74. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.js.map +1 -1
  75. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs +4 -3
  76. package/dist/node-prod/analytics-schema-custom-storefront-customer-tracking.mjs.map +1 -1
  77. package/dist/node-prod/analytics.js +4 -5
  78. package/dist/node-prod/analytics.js.map +1 -1
  79. package/dist/node-prod/analytics.mjs +4 -5
  80. package/dist/node-prod/analytics.mjs.map +1 -1
  81. package/dist/node-prod/cart-hooks.js +24 -6
  82. package/dist/node-prod/cart-hooks.js.map +1 -1
  83. package/dist/node-prod/cart-hooks.mjs +25 -7
  84. package/dist/node-prod/cart-hooks.mjs.map +1 -1
  85. package/dist/node-prod/cookies-utils.js +4 -4
  86. package/dist/node-prod/cookies-utils.js.map +1 -1
  87. package/dist/node-prod/cookies-utils.mjs +4 -4
  88. package/dist/node-prod/cookies-utils.mjs.map +1 -1
  89. package/dist/node-prod/index.js +4 -0
  90. package/dist/node-prod/index.js.map +1 -1
  91. package/dist/node-prod/index.mjs +4 -0
  92. package/dist/node-prod/index.mjs.map +1 -1
  93. package/dist/node-prod/packages/hydrogen-react/package.json.js +1 -1
  94. package/dist/node-prod/packages/hydrogen-react/package.json.mjs +1 -1
  95. package/dist/node-prod/tracking-utils.js +92 -0
  96. package/dist/node-prod/tracking-utils.js.map +1 -0
  97. package/dist/node-prod/tracking-utils.mjs +92 -0
  98. package/dist/node-prod/tracking-utils.mjs.map +1 -0
  99. package/dist/node-prod/useShopifyCookies.js +94 -7
  100. package/dist/node-prod/useShopifyCookies.js.map +1 -1
  101. package/dist/node-prod/useShopifyCookies.mjs +96 -9
  102. package/dist/node-prod/useShopifyCookies.mjs.map +1 -1
  103. package/dist/types/ShopifyProvider.d.ts +5 -0
  104. package/dist/types/analytics-schema-custom-storefront-customer-tracking.d.ts +3 -3
  105. package/dist/types/analytics-types.d.ts +24 -4
  106. package/dist/types/cookies-utils.d.ts +4 -0
  107. package/dist/types/index.d.cts +1 -0
  108. package/dist/types/index.d.ts +1 -0
  109. package/dist/types/tracking-utils.d.ts +21 -0
  110. package/dist/types/useShopifyCookies.d.ts +28 -2
  111. package/dist/umd/hydrogen-react.dev.js +279 -92
  112. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  113. package/dist/umd/hydrogen-react.prod.js +18 -18
  114. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  115. package/package.json +1 -1
@@ -69,7 +69,7 @@
69
69
  return t2 === n2;
70
70
  };
71
71
  }
72
- function u$1(t2) {
72
+ function u(t2) {
73
73
  return "string" == typeof t2 ? { type: t2 } : t2;
74
74
  }
75
75
  function c(t2, n2) {
@@ -93,7 +93,7 @@
93
93
  var s2 = t(f(r(n2.states[n2.initial].entry).map((function(t2) {
94
94
  return o(t2, i2.actions);
95
95
  })), n2.context, e), 2), l2 = s2[0], v2 = s2[1], y = { config: n2, _options: i2, initialState: { value: n2.initial, actions: l2, context: v2, matches: a(n2.initial) }, transition: function(e2, i3) {
96
- var s3, l3, v3 = "string" == typeof e2 ? { value: e2, context: n2.context } : e2, p = v3.value, g2 = v3.context, d = u$1(i3), x = n2.states[p];
96
+ var s3, l3, v3 = "string" == typeof e2 ? { value: e2, context: n2.context } : e2, p = v3.value, g = v3.context, d = u(i3), x = n2.states[p];
97
97
  if (x.on) {
98
98
  var m = r(x.on[d.type]);
99
99
  try {
@@ -106,16 +106,16 @@
106
106
  throw new TypeError(n3 ? "Object is not iterable." : "Symbol.iterator is not defined.");
107
107
  })(m), b = h.next(); !b.done; b = h.next()) {
108
108
  var S = b.value;
109
- if (void 0 === S) return c(p, g2);
109
+ if (void 0 === S) return c(p, g);
110
110
  var w = "string" == typeof S ? { target: S } : S, j = w.target, E = w.actions, R = void 0 === E ? [] : E, N = w.cond, O = void 0 === N ? function() {
111
111
  return true;
112
112
  } : N, _ = void 0 === j, k = null != j ? j : p, T = n2.states[k];
113
- if (O(g2, d)) {
113
+ if (O(g, d)) {
114
114
  var q = t(f((_ ? r(R) : [].concat(x.exit, R, T.entry).filter((function(t2) {
115
115
  return t2;
116
116
  }))).map((function(t2) {
117
117
  return o(t2, y._options.actions);
118
- })), g2, d), 3), z = q[0], A = q[1], B = q[2], C = null != j ? j : p;
118
+ })), g, d), 3), z = q[0], A = q[1], B = q[2], C = null != j ? j : p;
119
119
  return { value: C, context: A, actions: z, changed: j !== p || z.length > 0 || B, matches: a(C) };
120
120
  }
121
121
  }
@@ -129,7 +129,7 @@
129
129
  }
130
130
  }
131
131
  }
132
- return c(p, g2);
132
+ return c(p, g);
133
133
  } };
134
134
  return y;
135
135
  }
@@ -141,7 +141,7 @@
141
141
  };
142
142
  function v(t2) {
143
143
  var r2 = t2.initialState, i2 = n.NotStarted, o2 = /* @__PURE__ */ new Set(), c2 = { _machine: t2, send: function(e2) {
144
- i2 === n.Running && (r2 = t2.transition(r2, e2), l$1(r2, u$1(e2)), o2.forEach((function(t3) {
144
+ i2 === n.Running && (r2 = t2.transition(r2, e2), l$1(r2, u(e2)), o2.forEach((function(t3) {
145
145
  return t3(r2);
146
146
  })));
147
147
  }, subscribe: function(t3) {
@@ -929,6 +929,21 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
929
929
  const ShopifyContext = React$1.createContext(
930
930
  defaultShopifyContext
931
931
  );
932
+ function isSfapiProxyEnabled() {
933
+ var _a, _b, _c;
934
+ if (typeof window === "undefined") return false;
935
+ try {
936
+ const navigationEntry = (_b = (_a = window.performance) == null ? void 0 : _a.getEntriesByType) == null ? void 0 : _b.call(
937
+ _a,
938
+ "navigation"
939
+ )[0];
940
+ return !!((_c = navigationEntry == null ? void 0 : navigationEntry.serverTiming) == null ? void 0 : _c.some(
941
+ (entry) => entry.name === "_sfapi_proxy"
942
+ ));
943
+ } catch (e2) {
944
+ return false;
945
+ }
946
+ }
932
947
  function ShopifyProvider({
933
948
  children,
934
949
  ...shopifyConfig
@@ -944,12 +959,14 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
944
959
  );
945
960
  }
946
961
  const finalConfig = React$1.useMemo(() => {
962
+ const sameDomainForStorefrontApi = shopifyConfig.sameDomainForStorefrontApi ?? isSfapiProxyEnabled();
947
963
  function getShopifyDomain(overrideProps) {
948
964
  const domain = (overrideProps == null ? void 0 : overrideProps.storeDomain) ?? shopifyConfig.storeDomain;
949
965
  return domain.includes("://") ? domain : `https://${domain}`;
950
966
  }
951
967
  return {
952
968
  ...shopifyConfig,
969
+ sameDomainForStorefrontApi,
953
970
  getPublicTokenHeaders(overrideProps) {
954
971
  return getPublicTokenHeadersRaw(
955
972
  overrideProps.contentType,
@@ -959,7 +976,7 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
959
976
  },
960
977
  getShopifyDomain,
961
978
  getStorefrontApiUrl(overrideProps) {
962
- const finalDomainUrl = getShopifyDomain({
979
+ const finalDomainUrl = sameDomainForStorefrontApi && typeof window !== "undefined" ? window.location.origin : getShopifyDomain({
963
980
  storeDomain: (overrideProps == null ? void 0 : overrideProps.storeDomain) ?? shopifyConfig.storeDomain
964
981
  });
965
982
  return `${finalDomainUrl}${finalDomainUrl.endsWith("/") ? "" : "/"}api/${(overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) ?? shopifyConfig.storefrontApiVersion}/graphql.json`;
@@ -981,77 +998,98 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
981
998
  const SHOPIFY_STOREFRONT_S_HEADER = "Shopify-Storefront-S";
982
999
  const SHOPIFY_Y = "_shopify_y";
983
1000
  const SHOPIFY_S = "_shopify_s";
984
- var g = /* @__PURE__ */ new Set([
985
- "domain",
986
- "path",
987
- "max-age",
988
- "expires",
989
- "samesite",
990
- "secure",
991
- "httponly"
992
- ]);
993
- function u(a2) {
994
- let r2 = {}, e2, t2, n2 = 0, m = a2.split(/;\s*/g), s2, i2;
995
- for (; n2 < m.length; n2++)
996
- if (t2 = m[n2], e2 = t2.indexOf("="), ~e2) {
997
- if (s2 = t2.substring(0, e2++).trim(), i2 = t2.substring(e2).trim(), i2[0] === '"' && (i2 = i2.substring(1, i2.length - 1)), ~i2.indexOf("%"))
998
- try {
999
- i2 = decodeURIComponent(i2);
1000
- } catch (f2) {
1001
+ const SHOPIFY_VISIT_TOKEN_HEADER = "X-Shopify-VisitToken";
1002
+ const SHOPIFY_UNIQUE_TOKEN_HEADER = "X-Shopify-UniqueToken";
1003
+ const cachedTrackingValues = { current: null };
1004
+ function getTrackingValues() {
1005
+ var _a, _b, _c;
1006
+ let trackingValues;
1007
+ if (typeof window !== "undefined" && typeof window.performance !== "undefined") {
1008
+ try {
1009
+ const resourceRE = /^https?:\/\/([^/]+)(\/api\/(?:unstable|2\d{3}-\d{2})\/graphql\.json(?=$|\?))?/;
1010
+ const entries = performance.getEntriesByType(
1011
+ "resource"
1012
+ );
1013
+ let matchedValues;
1014
+ for (let i2 = entries.length - 1; i2 >= 0; i2--) {
1015
+ const entry = entries[i2];
1016
+ if (entry.initiatorType !== "fetch") continue;
1017
+ const currentHost = window.location.host;
1018
+ const match = entry.name.match(resourceRE);
1019
+ if (!match) continue;
1020
+ const [, matchedHost, sfapiPath] = match;
1021
+ const isMatch = (
1022
+ // Same origin (exact host match)
1023
+ matchedHost === currentHost || // Subdomain with SFAPI path
1024
+ sfapiPath && (matchedHost == null ? void 0 : matchedHost.endsWith(`.${currentHost}`))
1025
+ );
1026
+ if (isMatch) {
1027
+ const values = extractFromPerformanceEntry(entry);
1028
+ if (values) {
1029
+ matchedValues = values;
1030
+ break;
1031
+ }
1001
1032
  }
1002
- g.has(t2 = s2.toLowerCase()) ? t2 === "expires" ? r2.expires = new Date(i2) : t2 === "max-age" ? r2.maxage = +i2 : r2[t2] = i2 : r2[s2] = i2;
1003
- } else
1004
- (s2 = t2.trim().toLowerCase()) && (s2 === "httponly" || s2 === "secure") && (r2[s2] = true);
1005
- return r2;
1006
- }
1007
- function l(a2, r2, e2 = {}) {
1008
- let t2 = a2 + "=" + encodeURIComponent(r2);
1009
- return e2.expires && (t2 += "; Expires=" + new Date(e2.expires).toUTCString()), e2.maxage != null && e2.maxage >= 0 && (t2 += "; Max-Age=" + (e2.maxage | 0)), e2.domain && (t2 += "; Domain=" + e2.domain), e2.path && (t2 += "; Path=" + e2.path), e2.samesite && (t2 += "; SameSite=" + e2.samesite), (e2.secure || e2.samesite === "None") && (t2 += "; Secure"), e2.httponly && (t2 += "; HttpOnly"), t2;
1010
- }
1011
- const tokenHash = "xxxx-4xxx-xxxx-xxxxxxxxxxxx";
1012
- function buildUUID() {
1013
- let hash = "";
1014
- try {
1015
- const crypto = window.crypto;
1016
- const randomValuesArray = new Uint16Array(31);
1017
- crypto.getRandomValues(randomValuesArray);
1018
- let i2 = 0;
1019
- hash = tokenHash.replace(/[x]/g, (c2) => {
1020
- const r2 = randomValuesArray[i2] % 16;
1021
- const v2 = c2 === "x" ? r2 : r2 & 3 | 8;
1022
- i2++;
1023
- return v2.toString(16);
1024
- }).toUpperCase();
1025
- } catch (err) {
1026
- hash = tokenHash.replace(/[x]/g, (c2) => {
1027
- const r2 = Math.random() * 16 | 0;
1028
- const v2 = c2 === "x" ? r2 : r2 & 3 | 8;
1029
- return v2.toString(16);
1030
- }).toUpperCase();
1033
+ }
1034
+ if (matchedValues) {
1035
+ trackingValues = matchedValues;
1036
+ }
1037
+ if (trackingValues) {
1038
+ cachedTrackingValues.current = trackingValues;
1039
+ } else if (cachedTrackingValues.current) {
1040
+ trackingValues = cachedTrackingValues.current;
1041
+ }
1042
+ if (!trackingValues) {
1043
+ const navigationEntries = performance.getEntriesByType(
1044
+ "navigation"
1045
+ )[0];
1046
+ trackingValues = extractFromPerformanceEntry(navigationEntries, false);
1047
+ }
1048
+ } catch {
1049
+ }
1031
1050
  }
1032
- return `${hexTime()}-${hash}`;
1033
- }
1034
- function hexTime() {
1035
- let dateNumber = 0;
1036
- let perfNumber = 0;
1037
- dateNumber = (/* @__PURE__ */ new Date()).getTime() >>> 0;
1038
- try {
1039
- perfNumber = performance.now() >>> 0;
1040
- } catch (err) {
1041
- perfNumber = 0;
1051
+ if (!trackingValues) {
1052
+ const cookie = (
1053
+ // Read from arguments to avoid declaring parameters in this function signature.
1054
+ // This logic is only used internally from `getShopifyCookies` and will be deprecated.
1055
+ typeof arguments[0] === "string" ? arguments[0] : typeof document !== "undefined" ? document.cookie : ""
1056
+ );
1057
+ trackingValues = {
1058
+ uniqueToken: ((_a = cookie.match(/\b_shopify_y=([^;]+)/)) == null ? void 0 : _a[1]) || "",
1059
+ visitToken: ((_b = cookie.match(/\b_shopify_s=([^;]+)/)) == null ? void 0 : _b[1]) || "",
1060
+ consent: ((_c = cookie.match(/\b_tracking_consent=([^;]+)/)) == null ? void 0 : _c[1]) || ""
1061
+ };
1042
1062
  }
1043
- const output = Math.abs(dateNumber + perfNumber).toString(16).toLowerCase();
1044
- return output.padStart(8, "0");
1045
- }
1046
- function getShopifyCookies(cookies) {
1047
- const cookieData = u(cookies);
1048
- return {
1049
- [SHOPIFY_Y]: cookieData[SHOPIFY_Y] || "",
1050
- [SHOPIFY_S]: cookieData[SHOPIFY_S] || ""
1051
- };
1063
+ return trackingValues;
1064
+ }
1065
+ function extractFromPerformanceEntry(entry, isConsentRequired = true) {
1066
+ let uniqueToken = "";
1067
+ let visitToken = "";
1068
+ let consent = "";
1069
+ const serverTiming = entry.serverTiming;
1070
+ if (serverTiming && serverTiming.length >= 3) {
1071
+ for (let i2 = serverTiming.length - 1; i2 >= 0; i2--) {
1072
+ const { name, description } = serverTiming[i2];
1073
+ if (!name || !description) continue;
1074
+ if (name === "_y") {
1075
+ uniqueToken = description;
1076
+ } else if (name === "_s") {
1077
+ visitToken = description;
1078
+ } else if (name === "_cmp") {
1079
+ consent = description;
1080
+ }
1081
+ if (uniqueToken && visitToken && consent) break;
1082
+ }
1083
+ }
1084
+ return uniqueToken && visitToken && (isConsentRequired ? consent : true) ? { uniqueToken, visitToken, consent } : void 0;
1052
1085
  }
1053
1086
  function useCartFetch() {
1054
- const { storefrontId, getPublicTokenHeaders, getStorefrontApiUrl } = useShop();
1087
+ const {
1088
+ storefrontId,
1089
+ getPublicTokenHeaders,
1090
+ getStorefrontApiUrl,
1091
+ sameDomainForStorefrontApi
1092
+ } = useShop();
1055
1093
  return React$1.useCallback(
1056
1094
  ({
1057
1095
  query,
@@ -1061,9 +1099,17 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
1061
1099
  if (storefrontId) {
1062
1100
  headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;
1063
1101
  }
1064
- const cookieData = getShopifyCookies(document.cookie);
1065
- headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];
1066
- headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];
1102
+ if (!sameDomainForStorefrontApi) {
1103
+ const { uniqueToken, visitToken } = getTrackingValues();
1104
+ if (uniqueToken) {
1105
+ headers[SHOPIFY_STOREFRONT_Y_HEADER] = uniqueToken;
1106
+ headers[SHOPIFY_UNIQUE_TOKEN_HEADER] = uniqueToken;
1107
+ }
1108
+ if (visitToken) {
1109
+ headers[SHOPIFY_STOREFRONT_S_HEADER] = visitToken;
1110
+ headers[SHOPIFY_VISIT_TOKEN_HEADER] = visitToken;
1111
+ }
1112
+ }
1067
1113
  return fetch(getStorefrontApiUrl(), {
1068
1114
  method: "POST",
1069
1115
  headers,
@@ -1081,7 +1127,12 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
1081
1127
  };
1082
1128
  });
1083
1129
  },
1084
- [getPublicTokenHeaders, storefrontId, getStorefrontApiUrl]
1130
+ [
1131
+ getPublicTokenHeaders,
1132
+ storefrontId,
1133
+ getStorefrontApiUrl,
1134
+ sameDomainForStorefrontApi
1135
+ ]
1085
1136
  );
1086
1137
  }
1087
1138
  function useCartActions({
@@ -2358,6 +2409,48 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
2358
2409
  }
2359
2410
  return false;
2360
2411
  }
2412
+ const tokenHash = "xxxx-4xxx-xxxx-xxxxxxxxxxxx";
2413
+ function buildUUID() {
2414
+ let hash = "";
2415
+ try {
2416
+ const crypto = window.crypto;
2417
+ const randomValuesArray = new Uint16Array(31);
2418
+ crypto.getRandomValues(randomValuesArray);
2419
+ let i2 = 0;
2420
+ hash = tokenHash.replace(/[x]/g, (c2) => {
2421
+ const r2 = randomValuesArray[i2] % 16;
2422
+ const v2 = c2 === "x" ? r2 : r2 & 3 | 8;
2423
+ i2++;
2424
+ return v2.toString(16);
2425
+ }).toUpperCase();
2426
+ } catch (err) {
2427
+ hash = tokenHash.replace(/[x]/g, (c2) => {
2428
+ const r2 = Math.random() * 16 | 0;
2429
+ const v2 = c2 === "x" ? r2 : r2 & 3 | 8;
2430
+ return v2.toString(16);
2431
+ }).toUpperCase();
2432
+ }
2433
+ return `${hexTime()}-${hash}`;
2434
+ }
2435
+ function hexTime() {
2436
+ let dateNumber = 0;
2437
+ let perfNumber = 0;
2438
+ dateNumber = (/* @__PURE__ */ new Date()).getTime() >>> 0;
2439
+ try {
2440
+ perfNumber = performance.now() >>> 0;
2441
+ } catch (err) {
2442
+ perfNumber = 0;
2443
+ }
2444
+ const output = Math.abs(dateNumber + perfNumber).toString(16).toLowerCase();
2445
+ return output.padStart(8, "0");
2446
+ }
2447
+ function getShopifyCookies(cookies) {
2448
+ const trackingValues = getTrackingValues(cookies);
2449
+ return {
2450
+ [SHOPIFY_Y]: trackingValues.uniqueToken,
2451
+ [SHOPIFY_S]: trackingValues.visitToken
2452
+ };
2453
+ }
2361
2454
  const SCHEMA_ID$1 = "trekkie_storefront_page_view/1.4";
2362
2455
  const OXYGEN_DOMAIN = "myshopify.dev";
2363
2456
  function pageView$1(payload) {
@@ -2409,7 +2502,7 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
2409
2502
  }
2410
2503
  return false;
2411
2504
  }
2412
- const version = "2025.7.0";
2505
+ const version = "2025.7.1";
2413
2506
  const SCHEMA_ID = "custom_storefront_customer_tracking/1.2";
2414
2507
  const PAGE_RENDERED_EVENT_NAME = "page_rendered";
2415
2508
  const COLLECTION_PAGE_RENDERED_EVENT_NAME = "collection_page_rendered";
@@ -2584,6 +2677,7 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
2584
2677
  ];
2585
2678
  }
2586
2679
  function formatPayload(payload) {
2680
+ const payloadWithPrivacy = payload;
2587
2681
  return {
2588
2682
  source: payload.shopifySalesChannel || ShopifySalesChannel.headless,
2589
2683
  asset_version_id: payload.assetVersionId || version,
@@ -2600,9 +2694,9 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
2600
2694
  navigation_api: payload.navigationApi,
2601
2695
  shop_id: parseInt(parseGid(payload.shopId).id),
2602
2696
  currency: payload.currency,
2603
- ccpa_enforced: payload.ccpaEnforced || false,
2604
- gdpr_enforced: payload.gdprEnforced || false,
2605
- gdpr_enforced_as_string: payload.gdprEnforced ? "true" : "false",
2697
+ ccpa_enforced: payloadWithPrivacy.ccpaEnforced || false,
2698
+ gdpr_enforced: payloadWithPrivacy.gdprEnforced || false,
2699
+ gdpr_enforced_as_string: payloadWithPrivacy.gdprEnforced ? "true" : "false",
2606
2700
  analytics_allowed: payload.analyticsAllowed || false,
2607
2701
  marketing_allowed: payload.marketingAllowed || false,
2608
2702
  sale_of_data_allowed: payload.saleOfDataAllowed || false
@@ -2727,10 +2821,10 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
2727
2821
  };
2728
2822
  }
2729
2823
  const [navigationType, navigationApi] = getNavigationType();
2730
- const cookies = getShopifyCookies(document.cookie);
2824
+ const trackingValues = getTrackingValues();
2731
2825
  return {
2732
- uniqueToken: cookies[SHOPIFY_Y],
2733
- visitToken: cookies[SHOPIFY_S],
2826
+ uniqueToken: trackingValues.uniqueToken,
2827
+ visitToken: trackingValues.visitToken,
2734
2828
  url: location.href,
2735
2829
  path: location.pathname,
2736
2830
  search: location.search,
@@ -4628,17 +4722,29 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
4628
4722
  }, [JSON.stringify(selectedOptions)]);
4629
4723
  return null;
4630
4724
  }
4725
+ function l(a2, r2, e2 = {}) {
4726
+ let t2 = a2 + "=" + encodeURIComponent(r2);
4727
+ return e2.expires && (t2 += "; Expires=" + new Date(e2.expires).toUTCString()), e2.maxage != null && e2.maxage >= 0 && (t2 += "; Max-Age=" + (e2.maxage | 0)), e2.domain && (t2 += "; Domain=" + e2.domain), e2.path && (t2 += "; Path=" + e2.path), e2.samesite && (t2 += "; SameSite=" + e2.samesite), (e2.secure || e2.samesite === "None") && (t2 += "; Secure"), e2.httponly && (t2 += "; HttpOnly"), t2;
4728
+ }
4631
4729
  const longTermLength = 60 * 60 * 24 * 360 * 1;
4632
4730
  const shortTermLength = 60 * 30;
4633
4731
  function useShopifyCookies(options) {
4634
4732
  const {
4635
- hasUserConsent = false,
4733
+ hasUserConsent,
4636
4734
  domain = "",
4637
- checkoutDomain = ""
4735
+ checkoutDomain = "",
4736
+ storefrontAccessToken,
4737
+ fetchTrackingValues,
4738
+ ignoreDeprecatedCookies = false
4638
4739
  } = options || {};
4740
+ const coreCookiesReady = useCoreShopifyCookies({
4741
+ storefrontAccessToken,
4742
+ fetchTrackingValues,
4743
+ checkoutDomain
4744
+ });
4639
4745
  React$1.useEffect(() => {
4640
- const cookies = getShopifyCookies(document.cookie);
4641
- let currentDomain = domain || window.document.location.host;
4746
+ if (ignoreDeprecatedCookies || !coreCookiesReady) return;
4747
+ let currentDomain = domain || window.location.host;
4642
4748
  if (checkoutDomain) {
4643
4749
  const checkoutDomainParts = checkoutDomain.split(".").reverse();
4644
4750
  const currentDomainParts = currentDomain.split(".").reverse();
@@ -4653,15 +4759,19 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
4653
4759
  if (/^localhost/.test(currentDomain)) currentDomain = "";
4654
4760
  const domainWithLeadingDot = currentDomain ? /^\./.test(currentDomain) ? currentDomain : `.${currentDomain}` : "";
4655
4761
  if (hasUserConsent) {
4762
+ const trackingValues = getTrackingValues();
4763
+ if ((trackingValues.uniqueToken || trackingValues.visitToken || "").startsWith("00000000-")) {
4764
+ return;
4765
+ }
4656
4766
  setCookie(
4657
4767
  SHOPIFY_Y,
4658
- cookies[SHOPIFY_Y] || buildUUID(),
4768
+ trackingValues.uniqueToken || buildUUID(),
4659
4769
  longTermLength,
4660
4770
  domainWithLeadingDot
4661
4771
  );
4662
4772
  setCookie(
4663
4773
  SHOPIFY_S,
4664
- cookies[SHOPIFY_S] || buildUUID(),
4774
+ trackingValues.visitToken || buildUUID(),
4665
4775
  shortTermLength,
4666
4776
  domainWithLeadingDot
4667
4777
  );
@@ -4669,7 +4779,14 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
4669
4779
  setCookie(SHOPIFY_Y, "", 0, domainWithLeadingDot);
4670
4780
  setCookie(SHOPIFY_S, "", 0, domainWithLeadingDot);
4671
4781
  }
4672
- }, [options, hasUserConsent, domain, checkoutDomain]);
4782
+ }, [
4783
+ coreCookiesReady,
4784
+ hasUserConsent,
4785
+ domain,
4786
+ checkoutDomain,
4787
+ ignoreDeprecatedCookies
4788
+ ]);
4789
+ return coreCookiesReady;
4673
4790
  }
4674
4791
  function setCookie(name, value, maxage, domain) {
4675
4792
  document.cookie = l(name, value, {
@@ -4679,6 +4796,73 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
4679
4796
  path: "/"
4680
4797
  });
4681
4798
  }
4799
+ async function fetchTrackingValuesFromBrowser(storefrontAccessToken, storefrontApiDomain = "") {
4800
+ const { uniqueToken, visitToken } = getTrackingValues();
4801
+ const response = await fetch(
4802
+ // TODO: update this endpoint when it becomes stable
4803
+ `${storefrontApiDomain.replace(/\/+$/, "")}/api/unstable/graphql.json`,
4804
+ {
4805
+ method: "POST",
4806
+ headers: {
4807
+ "Content-Type": "application/json",
4808
+ ...storefrontAccessToken && {
4809
+ "X-Shopify-Storefront-Access-Token": storefrontAccessToken
4810
+ },
4811
+ ...visitToken || uniqueToken ? {
4812
+ [SHOPIFY_VISIT_TOKEN_HEADER]: visitToken,
4813
+ [SHOPIFY_UNIQUE_TOKEN_HEADER]: uniqueToken
4814
+ } : void 0
4815
+ },
4816
+ body: JSON.stringify({
4817
+ query: (
4818
+ // This query ensures we get _cmp (consent) server-timing header, which is not available in other queries.
4819
+ // This value can be passed later to consent-tracking-api and privacy-banner scripts to avoid extra requests.
4820
+ "query ensureCookies { consentManagement { cookies(visitorConsent:{}) { cookieDomain } } }"
4821
+ )
4822
+ })
4823
+ }
4824
+ );
4825
+ if (!response.ok) {
4826
+ throw new Error(
4827
+ `Failed to fetch consent from browser: ${response.status} ${response.statusText}`
4828
+ );
4829
+ }
4830
+ await response.json();
4831
+ getTrackingValues();
4832
+ }
4833
+ function useCoreShopifyCookies({
4834
+ checkoutDomain,
4835
+ storefrontAccessToken,
4836
+ fetchTrackingValues = false
4837
+ }) {
4838
+ const [cookiesReady, setCookiesReady] = React$1.useState(!fetchTrackingValues);
4839
+ const hasFetchedTrackingValues = React$1.useRef(false);
4840
+ React$1.useEffect(() => {
4841
+ if (!fetchTrackingValues) {
4842
+ setCookiesReady(true);
4843
+ return;
4844
+ }
4845
+ if (hasFetchedTrackingValues.current) return;
4846
+ hasFetchedTrackingValues.current = true;
4847
+ fetchTrackingValuesFromBrowser(storefrontAccessToken).catch(
4848
+ (error) => checkoutDomain ? (
4849
+ // Retry with checkout domain if available to at least
4850
+ // get the server-timing values for tracking.
4851
+ fetchTrackingValuesFromBrowser(
4852
+ storefrontAccessToken,
4853
+ checkoutDomain
4854
+ )
4855
+ ) : Promise.reject(error)
4856
+ ).catch((error) => {
4857
+ console.warn(
4858
+ "[h2:warn:useShopifyCookies] Failed to fetch tracking values from browser: " + (error instanceof Error ? error.message : String(error))
4859
+ );
4860
+ }).finally(() => {
4861
+ setCookiesReady(true);
4862
+ });
4863
+ }, [checkoutDomain, fetchTrackingValues, storefrontAccessToken]);
4864
+ return cookiesReady;
4865
+ }
4682
4866
  exports2.AddToCartButton = AddToCartButton;
4683
4867
  exports2.AnalyticsEventName = AnalyticsEventName;
4684
4868
  exports2.AnalyticsPageType = AnalyticsPageType;
@@ -4702,6 +4886,8 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
4702
4886
  exports2.SHOPIFY_STOREFRONT_ID_HEADER = SHOPIFY_STOREFRONT_ID_HEADER;
4703
4887
  exports2.SHOPIFY_STOREFRONT_S_HEADER = SHOPIFY_STOREFRONT_S_HEADER;
4704
4888
  exports2.SHOPIFY_STOREFRONT_Y_HEADER = SHOPIFY_STOREFRONT_Y_HEADER;
4889
+ exports2.SHOPIFY_UNIQUE_TOKEN_HEADER = SHOPIFY_UNIQUE_TOKEN_HEADER;
4890
+ exports2.SHOPIFY_VISIT_TOKEN_HEADER = SHOPIFY_VISIT_TOKEN_HEADER;
4705
4891
  exports2.SHOPIFY_Y = SHOPIFY_Y;
4706
4892
  exports2.ShopPayButton = ShopPayButton;
4707
4893
  exports2.ShopifyProvider = ShopifyProvider;
@@ -4715,6 +4901,7 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
4715
4901
  exports2.getClientBrowserParameters = getClientBrowserParameters;
4716
4902
  exports2.getProductOptions = getProductOptions;
4717
4903
  exports2.getShopifyCookies = getShopifyCookies;
4904
+ exports2.getTrackingValues = getTrackingValues;
4718
4905
  exports2.isOptionValueCombinationInEncodedVariant = isOptionValueCombinationInEncodedVariant;
4719
4906
  exports2.mapSelectedProductOptionToObject = mapSelectedProductOptionToObject;
4720
4907
  exports2.parseGid = parseGid;