@shopify/hydrogen 0.22.1 → 0.25.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.
Files changed (445) hide show
  1. package/CHANGELOG.md +378 -0
  2. package/dist/esnext/components/AddToCartButton/AddToCartButton.client.d.ts +2 -5
  3. package/dist/esnext/components/AddToCartButton/AddToCartButton.client.js +18 -17
  4. package/dist/esnext/components/BaseButton/BaseButton.client.d.ts +14 -0
  5. package/dist/esnext/components/BaseButton/BaseButton.client.js +15 -0
  6. package/dist/esnext/components/BaseButton/index.d.ts +1 -0
  7. package/dist/esnext/components/BaseButton/index.js +1 -0
  8. package/dist/esnext/components/BuyNowButton/BuyNowButton.client.d.ts +2 -5
  9. package/dist/esnext/components/BuyNowButton/BuyNowButton.client.js +5 -4
  10. package/dist/esnext/components/CartEstimatedCost/CartEstimatedCost.client.js +4 -4
  11. package/dist/esnext/components/CartLinePrice/CartLinePrice.client.js +5 -8
  12. package/dist/esnext/components/CartLineProvider/context.d.ts +10 -0
  13. package/dist/esnext/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.d.ts +4 -5
  14. package/dist/esnext/components/CartLineQuantityAdjustButton/CartLineQuantityAdjustButton.js +16 -14
  15. package/dist/esnext/components/CartLines/{CartLines.d.ts → CartLines.client.d.ts} +0 -0
  16. package/dist/esnext/components/CartLines/{CartLines.js → CartLines.client.js} +1 -1
  17. package/dist/esnext/components/CartLines/index.d.ts +1 -1
  18. package/dist/esnext/components/CartLines/index.js +1 -1
  19. package/dist/esnext/components/CartProvider/CartProvider.client.js +31 -38
  20. package/dist/esnext/components/CartProvider/cart-queries.d.ts +1 -1
  21. package/dist/esnext/components/CartProvider/cart-queries.js +11 -0
  22. package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +11 -1
  23. package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +11 -1
  24. package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.d.ts +11 -1
  25. package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +11 -1
  26. package/dist/esnext/components/CartProvider/graphql/CartFragment.d.ts +11 -1
  27. package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.d.ts +11 -1
  28. package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +11 -1
  29. package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +11 -1
  30. package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +11 -1
  31. package/dist/esnext/components/CartProvider/graphql/CartQuery.d.ts +11 -1
  32. package/dist/esnext/components/CartProvider/hooks.client.js +5 -8
  33. package/dist/esnext/components/CartProvider/types.d.ts +2 -0
  34. package/dist/esnext/components/ExternalVideo/ExternalVideo.js +1 -1
  35. package/dist/esnext/components/Image/Image.d.ts +21 -0
  36. package/dist/esnext/components/Image/Image.js +88 -14
  37. package/dist/esnext/components/Link/Link.client.d.ts +2 -0
  38. package/dist/esnext/components/Link/Link.client.js +8 -5
  39. package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +2 -2
  40. package/dist/esnext/components/Metafield/Metafield.client.d.ts +6 -10
  41. package/dist/esnext/components/Metafield/Metafield.client.js +67 -31
  42. package/dist/esnext/components/Metafield/components/StarRating/StarRating.js +1 -1
  43. package/dist/esnext/components/ModelViewer/ModelViewer.client.js +2 -3
  44. package/dist/esnext/components/Money/Money.client.js +1 -1
  45. package/dist/esnext/components/ProductOptionsProvider/ProductOptionsProvider.client.d.ts +21 -0
  46. package/dist/esnext/components/ProductOptionsProvider/ProductOptionsProvider.client.js +133 -0
  47. package/dist/esnext/components/ProductOptionsProvider/context.d.ts +2 -0
  48. package/dist/esnext/components/{ProductProvider → ProductOptionsProvider}/context.js +0 -1
  49. package/dist/esnext/components/ProductOptionsProvider/index.d.ts +2 -0
  50. package/dist/esnext/components/ProductOptionsProvider/index.js +2 -0
  51. package/dist/esnext/components/ProductPrice/ProductPrice.client.d.ts +5 -2
  52. package/dist/esnext/components/ProductPrice/ProductPrice.client.js +10 -12
  53. package/dist/esnext/components/Seo/CollectionSeo.client.js +2 -3
  54. package/dist/esnext/components/Seo/DefaultPageSeo.client.js +3 -3
  55. package/dist/esnext/components/Seo/NoIndexSeo.client.js +2 -2
  56. package/dist/esnext/components/Seo/PageSeo.client.js +2 -3
  57. package/dist/esnext/components/Seo/ProductSeo.client.js +9 -10
  58. package/dist/esnext/components/ShopPayButton/ShopPayButton.client.js +2 -3
  59. package/dist/esnext/components/Video/Video.js +2 -3
  60. package/dist/esnext/components/index.d.ts +1 -1
  61. package/dist/esnext/components/index.js +1 -1
  62. package/dist/esnext/config.d.ts +4 -0
  63. package/dist/esnext/config.js +4 -0
  64. package/dist/esnext/constants.d.ts +2 -0
  65. package/dist/esnext/constants.js +2 -0
  66. package/dist/esnext/entry-client.js +107 -21
  67. package/dist/esnext/entry-server.d.ts +2 -31
  68. package/dist/esnext/entry-server.js +400 -335
  69. package/dist/esnext/foundation/Analytics/Analytics.client.js +15 -13
  70. package/dist/esnext/foundation/Analytics/Analytics.server.js +27 -20
  71. package/dist/esnext/foundation/Analytics/ClientAnalytics.d.ts +4 -2
  72. package/dist/esnext/foundation/Analytics/ClientAnalytics.js +16 -14
  73. package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.d.ts +4 -0
  74. package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.js +36 -0
  75. package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/ServerAnalyticsConnector.d.ts +3 -0
  76. package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/ServerAnalyticsConnector.js +27 -0
  77. package/dist/esnext/foundation/Analytics/connectors/Shopify/ServerAnalyticsConnector.d.ts +3 -0
  78. package/dist/esnext/foundation/Analytics/connectors/Shopify/ServerAnalyticsConnector.js +21 -0
  79. package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.client.d.ts +3 -0
  80. package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.client.js +190 -0
  81. package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.server.d.ts +3 -0
  82. package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.server.js +23 -0
  83. package/dist/esnext/foundation/Analytics/connectors/Shopify/const.d.ts +28 -0
  84. package/dist/esnext/foundation/Analytics/connectors/Shopify/const.js +51 -0
  85. package/dist/esnext/foundation/Analytics/connectors/Shopify/utils.d.ts +3 -0
  86. package/dist/esnext/foundation/Analytics/connectors/Shopify/utils.js +56 -0
  87. package/dist/esnext/foundation/Analytics/hook.js +4 -2
  88. package/dist/esnext/foundation/Analytics/utils.d.ts +2 -0
  89. package/dist/esnext/foundation/Analytics/utils.js +21 -0
  90. package/dist/esnext/foundation/BuiltInRoutes/BuiltInRoutes.d.ts +2 -0
  91. package/dist/esnext/foundation/BuiltInRoutes/BuiltInRoutes.js +23 -0
  92. package/dist/esnext/foundation/BuiltInRoutes/healthCheck.d.ts +1 -0
  93. package/dist/esnext/foundation/BuiltInRoutes/healthCheck.js +3 -0
  94. package/dist/{node/framework → esnext/foundation/Cache}/cache-sub-request.d.ts +1 -1
  95. package/dist/esnext/{framework → foundation/Cache}/cache-sub-request.js +4 -4
  96. package/dist/esnext/{framework → foundation/Cache}/cache.d.ts +1 -1
  97. package/dist/esnext/{framework → foundation/Cache}/cache.js +4 -4
  98. package/dist/esnext/foundation/Cache/strategies/index.d.ts +7 -0
  99. package/dist/esnext/foundation/Cache/strategies/index.js +54 -0
  100. package/dist/esnext/foundation/Cookie/Cookie.d.ts +3 -3
  101. package/dist/esnext/foundation/Cookie/Cookie.js +5 -0
  102. package/dist/esnext/foundation/DevTools/DevTools.client.d.ts +3 -0
  103. package/dist/esnext/foundation/DevTools/DevTools.client.js +17 -0
  104. package/dist/esnext/foundation/DevTools/DevTools.server.d.ts +1 -0
  105. package/dist/esnext/foundation/DevTools/DevTools.server.js +14 -0
  106. package/dist/esnext/foundation/DevTools/components/GraphQL.client.d.ts +1 -0
  107. package/dist/esnext/foundation/DevTools/components/GraphQL.client.js +25 -0
  108. package/dist/esnext/foundation/DevTools/components/Heading.d.ts +5 -0
  109. package/dist/esnext/foundation/DevTools/components/Heading.js +12 -0
  110. package/dist/esnext/foundation/DevTools/components/Interface.client.d.ts +11 -0
  111. package/dist/esnext/foundation/DevTools/components/Interface.client.js +47 -0
  112. package/dist/esnext/foundation/DevTools/components/Panels.d.ts +8 -0
  113. package/dist/esnext/foundation/DevTools/components/Panels.js +60 -0
  114. package/dist/esnext/foundation/DevTools/components/Performance.client.d.ts +14 -0
  115. package/dist/esnext/foundation/DevTools/components/Performance.client.js +26 -0
  116. package/dist/esnext/foundation/DevTools/components/Settings.client.d.ts +7 -0
  117. package/dist/esnext/foundation/DevTools/components/Settings.client.js +20 -0
  118. package/dist/esnext/foundation/DevTools/components/Table.d.ts +9 -0
  119. package/dist/esnext/foundation/DevTools/components/Table.js +7 -0
  120. package/dist/esnext/foundation/DevTools/components/icons.d.ts +2 -0
  121. package/dist/esnext/foundation/DevTools/components/icons.js +13 -0
  122. package/dist/esnext/foundation/DevTools/components/index.d.ts +2 -0
  123. package/dist/esnext/foundation/DevTools/components/index.js +2 -0
  124. package/dist/esnext/foundation/FileRoutes/FileRoutes.server.js +4 -4
  125. package/dist/{node/framework/Hydration → esnext/foundation/Html}/Html.d.ts +3 -1
  126. package/dist/esnext/{framework/Hydration → foundation/Html}/Html.js +15 -5
  127. package/dist/esnext/{framework/Hydration/ServerComponentRequest.server.d.ts → foundation/HydrogenRequest/HydrogenRequest.server.d.ts} +14 -4
  128. package/dist/esnext/{framework/Hydration/ServerComponentRequest.server.js → foundation/HydrogenRequest/HydrogenRequest.server.js} +70 -12
  129. package/dist/esnext/{framework/Hydration/ServerComponentResponse.server.d.ts → foundation/HydrogenResponse/HydrogenResponse.server.d.ts} +6 -11
  130. package/dist/esnext/foundation/HydrogenResponse/HydrogenResponse.server.js +48 -0
  131. package/dist/esnext/foundation/Router/BrowserRouter.client.js +15 -9
  132. package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.d.ts +2 -1
  133. package/dist/esnext/foundation/ServerPropsProvider/ServerPropsProvider.js +1 -1
  134. package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +5 -6
  135. package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +19 -24
  136. package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.d.ts +1 -1
  137. package/dist/esnext/foundation/ServerStateProvider/ServerStateProvider.js +1 -1
  138. package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +4 -5
  139. package/dist/esnext/foundation/fetchSync/server/fetchSync.js +1 -1
  140. package/dist/esnext/foundation/index.d.ts +1 -1
  141. package/dist/esnext/foundation/index.js +1 -1
  142. package/dist/esnext/foundation/runtime.d.ts +2 -0
  143. package/dist/esnext/foundation/runtime.js +6 -0
  144. package/dist/esnext/foundation/session/session.d.ts +3 -3
  145. package/dist/esnext/foundation/ssr-interop.d.ts +2 -2
  146. package/dist/esnext/foundation/useNavigate/useNavigate.d.ts +2 -0
  147. package/dist/esnext/foundation/useNavigate/useNavigate.js +10 -4
  148. package/dist/esnext/foundation/useQuery/hooks.d.ts +1 -0
  149. package/dist/esnext/foundation/useQuery/hooks.js +29 -18
  150. package/dist/esnext/foundation/useRequestContext/index.d.ts +15 -0
  151. package/dist/esnext/foundation/useRequestContext/index.js +23 -0
  152. package/dist/esnext/foundation/useServerProps/use-server-props.js +2 -2
  153. package/dist/esnext/foundation/useSession/useSession.js +1 -2
  154. package/dist/esnext/foundation/useUrl/useUrl.js +1 -2
  155. package/dist/esnext/framework/cache/in-memory.js +3 -3
  156. package/dist/esnext/framework/middleware.d.ts +1 -1
  157. package/dist/esnext/framework/middleware.js +3 -4
  158. package/dist/esnext/framework/plugin.d.ts +7 -3
  159. package/dist/esnext/framework/plugin.js +4 -1
  160. package/dist/esnext/framework/plugins/vite-plugin-client-imports.js +1 -1
  161. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-config.js +70 -64
  162. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +1 -1
  163. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-middleware.js +3 -4
  164. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-rsc.js +5 -13
  165. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-suppress-warnings.d.ts +3 -0
  166. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-suppress-warnings.js +19 -0
  167. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-virtual-files.d.ts +1 -1
  168. package/dist/esnext/framework/plugins/vite-plugin-hydrogen-virtual-files.js +6 -4
  169. package/dist/esnext/framework/types.d.ts +5 -0
  170. package/dist/esnext/framework/types.js +1 -0
  171. package/dist/esnext/hooks/index.d.ts +0 -1
  172. package/dist/esnext/hooks/index.js +0 -1
  173. package/dist/esnext/hooks/useCartLine/useCartLine.d.ts +10 -0
  174. package/dist/esnext/hooks/useMoney/hooks.js +53 -39
  175. package/dist/esnext/hooks/useProductOptions/helpers.js +6 -10
  176. package/dist/esnext/hooks/useProductOptions/types.d.ts +17 -15
  177. package/dist/esnext/hooks/useProductOptions/useProductOptions.client.d.ts +1 -15
  178. package/dist/esnext/hooks/useProductOptions/useProductOptions.client.js +8 -107
  179. package/dist/esnext/hooks/useShopQuery/hooks.js +30 -18
  180. package/dist/esnext/index.d.ts +7 -5
  181. package/dist/esnext/index.js +5 -5
  182. package/dist/esnext/shared-types.d.ts +26 -0
  183. package/dist/esnext/shared-types.js +4 -0
  184. package/dist/esnext/storefront-api-types.d.ts +37 -443
  185. package/dist/esnext/streaming.server.d.ts +9 -19
  186. package/dist/esnext/streaming.server.js +2 -11
  187. package/dist/esnext/types.d.ts +40 -40
  188. package/dist/esnext/types.js +1 -1
  189. package/dist/esnext/utilities/apiRoutes.d.ts +8 -4
  190. package/dist/esnext/utilities/apiRoutes.js +6 -4
  191. package/dist/esnext/utilities/devtools.d.ts +1 -1
  192. package/dist/esnext/utilities/devtools.js +3 -3
  193. package/dist/esnext/utilities/flattenConnection/flattenConnection.d.ts +1 -0
  194. package/dist/esnext/utilities/flattenConnection/flattenConnection.js +13 -6
  195. package/dist/esnext/utilities/graphql-tracker.js +7 -9
  196. package/dist/esnext/utilities/hash.d.ts +2 -2
  197. package/dist/esnext/utilities/hash.js +29 -6
  198. package/dist/esnext/utilities/image_size.d.ts +24 -3
  199. package/dist/esnext/utilities/image_size.js +53 -31
  200. package/dist/esnext/utilities/index.d.ts +2 -2
  201. package/dist/esnext/utilities/index.js +2 -2
  202. package/dist/esnext/utilities/isBrowser/index.d.ts +1 -0
  203. package/dist/esnext/utilities/isBrowser/index.js +1 -0
  204. package/dist/esnext/utilities/isBrowser/isBrowser.d.ts +4 -0
  205. package/dist/esnext/utilities/isBrowser/isBrowser.js +6 -0
  206. package/dist/esnext/utilities/isServer/isServer.js +2 -2
  207. package/dist/esnext/utilities/load_script.js +1 -1
  208. package/dist/esnext/utilities/log/index.d.ts +1 -1
  209. package/dist/esnext/utilities/log/index.js +1 -1
  210. package/dist/esnext/utilities/log/log-cache-api-status.js +3 -2
  211. package/dist/esnext/utilities/log/log-cache-header.d.ts +4 -4
  212. package/dist/esnext/utilities/log/log-query-timeline.d.ts +3 -3
  213. package/dist/esnext/utilities/log/log-query-timeline.js +29 -10
  214. package/dist/esnext/utilities/log/log.d.ts +17 -11
  215. package/dist/esnext/utilities/log/log.js +28 -20
  216. package/dist/esnext/utilities/log/utils.js +1 -6
  217. package/dist/esnext/utilities/parseMetafield/index.d.ts +1 -0
  218. package/dist/esnext/utilities/parseMetafield/index.js +1 -0
  219. package/dist/esnext/utilities/parseMetafield/parseMetafield.d.ts +15 -0
  220. package/dist/esnext/utilities/{parseMetafieldValue/parseMetafieldValue.js → parseMetafield/parseMetafield.js} +28 -2
  221. package/dist/esnext/utilities/storefrontApi.js +9 -5
  222. package/dist/esnext/utilities/template.js +1 -2
  223. package/dist/esnext/utilities/web-api-polyfill.js +6 -0
  224. package/dist/esnext/version.d.ts +1 -1
  225. package/dist/esnext/version.js +1 -1
  226. package/dist/node/framework/cache/in-memory.js +3 -3
  227. package/dist/node/framework/middleware.d.ts +1 -1
  228. package/dist/node/framework/middleware.js +3 -4
  229. package/dist/node/framework/plugin.d.ts +4 -3
  230. package/dist/node/framework/plugin.js +5 -2
  231. package/dist/node/framework/plugins/vite-plugin-client-imports.js +1 -1
  232. package/dist/node/framework/plugins/vite-plugin-hydrogen-config.js +70 -64
  233. package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.d.ts +1 -1
  234. package/dist/node/framework/plugins/vite-plugin-hydrogen-middleware.js +3 -4
  235. package/dist/node/framework/plugins/vite-plugin-hydrogen-rsc.js +6 -14
  236. package/dist/node/framework/plugins/vite-plugin-hydrogen-suppress-warnings.d.ts +3 -0
  237. package/dist/node/framework/plugins/vite-plugin-hydrogen-suppress-warnings.js +21 -0
  238. package/dist/node/framework/plugins/vite-plugin-hydrogen-virtual-files.d.ts +1 -1
  239. package/dist/node/framework/plugins/vite-plugin-hydrogen-virtual-files.js +6 -4
  240. package/dist/node/framework/types.d.ts +5 -0
  241. package/dist/node/{foundation/Analytics → framework}/types.js +0 -0
  242. package/dist/node/shared-types.d.ts +26 -0
  243. package/dist/node/shared-types.js +5 -0
  244. package/dist/node/utilities/web-api-polyfill.js +6 -0
  245. package/package.json +34 -26
  246. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +275 -60
  247. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.development.server.js +119 -64
  248. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.browser.production.min.server.js +33 -32
  249. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.development.server.js +241 -75
  250. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-writer.node.production.min.server.js +38 -35
  251. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite.development.js +9 -8
  252. package/vendor/react-server-dom-vite/cjs/react-server-dom-vite.production.min.js +3 -3
  253. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js +3 -9
  254. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +276 -61
  255. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.browser.server.js +119 -64
  256. package/vendor/react-server-dom-vite/esm/react-server-dom-vite-writer.node.server.js +241 -75
  257. package/vendor/react-server-dom-vite/esm/react-server-dom-vite.js +9 -8
  258. package/vendor/react-server-dom-vite/package.json +1 -1
  259. package/client.d.ts +0 -1
  260. package/client.js +0 -1
  261. package/config.d.ts +0 -1
  262. package/config.js +0 -1
  263. package/dist/esnext/components/DevTools.client.d.ts +0 -1
  264. package/dist/esnext/components/DevTools.client.js +0 -129
  265. package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.d.ts +0 -8
  266. package/dist/esnext/components/ProductProvider/ProductOptionsProvider.client.js +0 -12
  267. package/dist/esnext/components/ProductProvider/ProductProvider.client.d.ts +0 -24
  268. package/dist/esnext/components/ProductProvider/ProductProvider.client.js +0 -34
  269. package/dist/esnext/components/ProductProvider/context.d.ts +0 -29
  270. package/dist/esnext/components/ProductProvider/index.d.ts +0 -2
  271. package/dist/esnext/components/ProductProvider/index.js +0 -2
  272. package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.server.d.ts +0 -2
  273. package/dist/esnext/foundation/Analytics/ServerAnalyticsRoute.server.js +0 -33
  274. package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetrics.server.d.ts +0 -1
  275. package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetrics.server.js +0 -24
  276. package/dist/esnext/framework/CachingStrategy/index.d.ts +0 -10
  277. package/dist/esnext/framework/CachingStrategy/index.js +0 -96
  278. package/dist/esnext/framework/Hydration/Html.d.ts +0 -11
  279. package/dist/esnext/framework/Hydration/ServerComponentResponse.server.js +0 -42
  280. package/dist/esnext/framework/Hydration/rsc.d.ts +0 -8
  281. package/dist/esnext/framework/Hydration/rsc.js +0 -100
  282. package/dist/esnext/framework/cache-sub-request.d.ts +0 -17
  283. package/dist/esnext/framework/config.d.ts +0 -6
  284. package/dist/esnext/framework/config.js +0 -6
  285. package/dist/esnext/framework/runtime.d.ts +0 -13
  286. package/dist/esnext/framework/runtime.js +0 -27
  287. package/dist/esnext/hooks/useParsedMetafields/index.d.ts +0 -1
  288. package/dist/esnext/hooks/useParsedMetafields/index.js +0 -1
  289. package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.d.ts +0 -21
  290. package/dist/esnext/hooks/useParsedMetafields/useParsedMetafields.js +0 -21
  291. package/dist/esnext/hooks/useProduct/index.d.ts +0 -1
  292. package/dist/esnext/hooks/useProduct/index.js +0 -1
  293. package/dist/esnext/hooks/useProduct/useProduct.d.ts +0 -52
  294. package/dist/esnext/hooks/useProduct/useProduct.js +0 -43
  295. package/dist/esnext/utilities/isClient/index.d.ts +0 -1
  296. package/dist/esnext/utilities/isClient/index.js +0 -1
  297. package/dist/esnext/utilities/isClient/isClient.d.ts +0 -4
  298. package/dist/esnext/utilities/isClient/isClient.js +0 -6
  299. package/dist/esnext/utilities/parseMetafieldValue/index.d.ts +0 -1
  300. package/dist/esnext/utilities/parseMetafieldValue/index.js +0 -1
  301. package/dist/esnext/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +0 -6
  302. package/dist/node/components/Image/Image.d.ts +0 -84
  303. package/dist/node/components/Image/Image.js +0 -89
  304. package/dist/node/components/Image/index.d.ts +0 -2
  305. package/dist/node/components/Image/index.js +0 -5
  306. package/dist/node/constants.d.ts +0 -7
  307. package/dist/node/constants.js +0 -10
  308. package/dist/node/entry-server.d.ts +0 -35
  309. package/dist/node/entry-server.js +0 -571
  310. package/dist/node/foundation/Analytics/Analytics.client.d.ts +0 -3
  311. package/dist/node/foundation/Analytics/Analytics.client.js +0 -32
  312. package/dist/node/foundation/Analytics/Analytics.server.d.ts +0 -1
  313. package/dist/node/foundation/Analytics/Analytics.server.js +0 -70
  314. package/dist/node/foundation/Analytics/ClientAnalytics.d.ts +0 -25
  315. package/dist/node/foundation/Analytics/ClientAnalytics.js +0 -100
  316. package/dist/node/foundation/Analytics/ServerAnalyticsRoute.server.d.ts +0 -2
  317. package/dist/node/foundation/Analytics/ServerAnalyticsRoute.server.js +0 -37
  318. package/dist/node/foundation/Analytics/const.d.ts +0 -9
  319. package/dist/node/foundation/Analytics/const.js +0 -12
  320. package/dist/node/foundation/Analytics/hook.d.ts +0 -1
  321. package/dist/node/foundation/Analytics/hook.js +0 -11
  322. package/dist/node/foundation/Analytics/types.d.ts +0 -5
  323. package/dist/node/foundation/Analytics/utils.d.ts +0 -1
  324. package/dist/node/foundation/Analytics/utils.js +0 -12
  325. package/dist/node/foundation/AnalyticsErrorBoundary.client.d.ts +0 -4
  326. package/dist/node/foundation/AnalyticsErrorBoundary.client.js +0 -14
  327. package/dist/node/foundation/Redirect/Redirect.client.d.ts +0 -5
  328. package/dist/node/foundation/Redirect/Redirect.client.js +0 -18
  329. package/dist/node/foundation/Router/BrowserRouter.client.d.ts +0 -14
  330. package/dist/node/foundation/Router/BrowserRouter.client.js +0 -159
  331. package/dist/node/foundation/ServerPropsProvider/ServerPropsProvider.d.ts +0 -40
  332. package/dist/node/foundation/ServerPropsProvider/ServerPropsProvider.js +0 -90
  333. package/dist/node/foundation/ServerPropsProvider/index.d.ts +0 -2
  334. package/dist/node/foundation/ServerPropsProvider/index.js +0 -6
  335. package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +0 -23
  336. package/dist/node/foundation/ServerRequestProvider/ServerRequestProvider.js +0 -158
  337. package/dist/node/foundation/ServerRequestProvider/index.d.ts +0 -1
  338. package/dist/node/foundation/ServerRequestProvider/index.js +0 -17
  339. package/dist/node/foundation/ShopifyProvider/types.d.ts +0 -13
  340. package/dist/node/foundation/ShopifyProvider/types.js +0 -2
  341. package/dist/node/foundation/session/session.d.ts +0 -27
  342. package/dist/node/foundation/session/session.js +0 -43
  343. package/dist/node/foundation/ssr-interop.d.ts +0 -29
  344. package/dist/node/foundation/ssr-interop.js +0 -39
  345. package/dist/node/foundation/useNavigate/useNavigate.d.ts +0 -13
  346. package/dist/node/foundation/useNavigate/useNavigate.js +0 -18
  347. package/dist/node/foundation/useServerProps/use-server-props.d.ts +0 -21
  348. package/dist/node/foundation/useServerProps/use-server-props.js +0 -40
  349. package/dist/node/framework/CachingStrategy/index.d.ts +0 -10
  350. package/dist/node/framework/CachingStrategy/index.js +0 -108
  351. package/dist/node/framework/Hydration/Html.js +0 -94
  352. package/dist/node/framework/Hydration/ServerComponentRequest.server.d.ts +0 -58
  353. package/dist/node/framework/Hydration/ServerComponentRequest.server.js +0 -150
  354. package/dist/node/framework/Hydration/ServerComponentResponse.server.d.ts +0 -26
  355. package/dist/node/framework/Hydration/ServerComponentResponse.server.js +0 -49
  356. package/dist/node/framework/Hydration/rsc.d.ts +0 -8
  357. package/dist/node/framework/Hydration/rsc.js +0 -103
  358. package/dist/node/framework/cache-sub-request.js +0 -95
  359. package/dist/node/framework/cache.d.ts +0 -17
  360. package/dist/node/framework/cache.js +0 -135
  361. package/dist/node/framework/config.d.ts +0 -6
  362. package/dist/node/framework/config.js +0 -11
  363. package/dist/node/framework/runtime.d.ts +0 -13
  364. package/dist/node/framework/runtime.js +0 -35
  365. package/dist/node/storefront-api-types.d.ts +0 -6405
  366. package/dist/node/storefront-api-types.js +0 -1766
  367. package/dist/node/streaming.server.d.ts +0 -26
  368. package/dist/node/streaming.server.js +0 -33
  369. package/dist/node/types.d.ts +0 -105
  370. package/dist/node/types.js +0 -2
  371. package/dist/node/utilities/apiRoutes.d.ts +0 -37
  372. package/dist/node/utilities/apiRoutes.js +0 -157
  373. package/dist/node/utilities/bot-ua.d.ts +0 -4
  374. package/dist/node/utilities/bot-ua.js +0 -65
  375. package/dist/node/utilities/defer.d.ts +0 -6
  376. package/dist/node/utilities/defer.js +0 -18
  377. package/dist/node/utilities/error.d.ts +0 -1
  378. package/dist/node/utilities/error.js +0 -10
  379. package/dist/node/utilities/fetch.d.ts +0 -9
  380. package/dist/node/utilities/fetch.js +0 -37
  381. package/dist/node/utilities/flattenConnection/flattenConnection.d.ts +0 -6
  382. package/dist/node/utilities/flattenConnection/flattenConnection.js +0 -15
  383. package/dist/node/utilities/flattenConnection/index.d.ts +0 -1
  384. package/dist/node/utilities/flattenConnection/index.js +0 -5
  385. package/dist/node/utilities/hash.d.ts +0 -2
  386. package/dist/node/utilities/hash.js +0 -11
  387. package/dist/node/utilities/html-encoding.d.ts +0 -1
  388. package/dist/node/utilities/html-encoding.js +0 -12
  389. package/dist/node/utilities/image_size.d.ts +0 -12
  390. package/dist/node/utilities/image_size.js +0 -68
  391. package/dist/node/utilities/index.d.ts +0 -12
  392. package/dist/node/utilities/index.js +0 -33
  393. package/dist/node/utilities/isClient/index.d.ts +0 -1
  394. package/dist/node/utilities/isClient/index.js +0 -5
  395. package/dist/node/utilities/isClient/isClient.d.ts +0 -4
  396. package/dist/node/utilities/isClient/isClient.js +0 -10
  397. package/dist/node/utilities/isServer/index.d.ts +0 -1
  398. package/dist/node/utilities/isServer/index.js +0 -5
  399. package/dist/node/utilities/isServer/isServer.d.ts +0 -4
  400. package/dist/node/utilities/isServer/isServer.js +0 -11
  401. package/dist/node/utilities/load_script.d.ts +0 -3
  402. package/dist/node/utilities/load_script.js +0 -27
  403. package/dist/node/utilities/log/index.d.ts +0 -4
  404. package/dist/node/utilities/log/index.js +0 -18
  405. package/dist/node/utilities/log/log-cache-api-status.d.ts +0 -1
  406. package/dist/node/utilities/log/log-cache-api-status.js +0 -17
  407. package/dist/node/utilities/log/log-cache-header.d.ts +0 -10
  408. package/dist/node/utilities/log/log-cache-header.js +0 -35
  409. package/dist/node/utilities/log/log-query-timeline.d.ts +0 -12
  410. package/dist/node/utilities/log/log-query-timeline.js +0 -88
  411. package/dist/node/utilities/log/log.d.ts +0 -22
  412. package/dist/node/utilities/log/log.js +0 -74
  413. package/dist/node/utilities/log/utils.d.ts +0 -3
  414. package/dist/node/utilities/log/utils.js +0 -21
  415. package/dist/node/utilities/matchPath.d.ts +0 -10
  416. package/dist/node/utilities/matchPath.js +0 -58
  417. package/dist/node/utilities/measurement.d.ts +0 -3
  418. package/dist/node/utilities/measurement.js +0 -103
  419. package/dist/node/utilities/parse.d.ts +0 -1
  420. package/dist/node/utilities/parse.js +0 -13
  421. package/dist/node/utilities/parseMetafieldValue/index.d.ts +0 -1
  422. package/dist/node/utilities/parseMetafieldValue/index.js +0 -5
  423. package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.d.ts +0 -6
  424. package/dist/node/utilities/parseMetafieldValue/parseMetafieldValue.js +0 -40
  425. package/dist/node/utilities/storefrontApi.d.ts +0 -4
  426. package/dist/node/utilities/storefrontApi.js +0 -26
  427. package/dist/node/utilities/suspense.d.ts +0 -12
  428. package/dist/node/utilities/suspense.js +0 -64
  429. package/dist/node/utilities/template.d.ts +0 -9
  430. package/dist/node/utilities/template.js +0 -27
  431. package/dist/node/utilities/timing.d.ts +0 -7
  432. package/dist/node/utilities/timing.js +0 -18
  433. package/dist/node/utilities/video_parameters.d.ts +0 -47
  434. package/dist/node/utilities/video_parameters.js +0 -27
  435. package/dist/node/version.d.ts +0 -1
  436. package/dist/node/version.js +0 -4
  437. package/entry-client.d.ts +0 -1
  438. package/entry-client.js +0 -1
  439. package/entry-server.d.ts +0 -1
  440. package/entry-server.js +0 -1
  441. package/middleware.d.ts +0 -1
  442. package/middleware.js +0 -1
  443. package/plugin.d.ts +0 -1
  444. package/plugin.js +0 -1
  445. package/web-polyfills.js +0 -1
@@ -3,16 +3,12 @@ import { ClientAnalytics } from './ClientAnalytics';
3
3
  export function Analytics({ analyticsDataFromServer, }) {
4
4
  useEffect(() => {
5
5
  const urlParams = new URLSearchParams(window.location.search);
6
- if (urlParams.has('utm_source')) {
7
- ClientAnalytics.pushToPageAnalyticsData({
8
- id: urlParams.get('utm_id'),
9
- source: urlParams.get('utm_source'),
10
- campaign: urlParams.get('utm_campaign'),
11
- medium: urlParams.get('utm_medium'),
12
- content: urlParams.get('utm_content'),
13
- term: urlParams.get('utm_term'),
14
- }, 'utm');
15
- }
6
+ addUTMData(urlParams, 'id');
7
+ addUTMData(urlParams, 'source');
8
+ addUTMData(urlParams, 'campaign');
9
+ addUTMData(urlParams, 'medium');
10
+ addUTMData(urlParams, 'content');
11
+ addUTMData(urlParams, 'term');
16
12
  ClientAnalytics.pushToPageAnalyticsData(analyticsDataFromServer);
17
13
  ClientAnalytics.publish(ClientAnalytics.eventNames.PAGE_VIEW, true);
18
14
  if (analyticsDataFromServer.publishEventsOnNavigate) {
@@ -20,9 +16,15 @@ export function Analytics({ analyticsDataFromServer, }) {
20
16
  ClientAnalytics.publish(eventName, true);
21
17
  });
22
18
  }
23
- return function cleanup() {
24
- ClientAnalytics.resetPageAnalyticsData();
25
- };
26
19
  }, [analyticsDataFromServer]);
27
20
  return null;
28
21
  }
22
+ function addUTMData(urlParams, key) {
23
+ if (urlParams.has(`utm_${key}`)) {
24
+ ClientAnalytics.pushToPageAnalyticsData({
25
+ utm: {
26
+ [key]: urlParams.get(`utm_${key}`),
27
+ },
28
+ });
29
+ }
30
+ }
@@ -3,29 +3,20 @@ import { useServerAnalytics } from './hook';
3
3
  import { Analytics as AnalyticsClient } from './Analytics.client';
4
4
  import { useServerRequest } from '../ServerRequestProvider';
5
5
  import AnalyticsErrorBoundary from '../AnalyticsErrorBoundary.client';
6
- const DELAY_KEY = 'analytics-delay';
6
+ import { wrapPromise } from '../../utilities';
7
+ const DELAY_KEY_1 = 'analytics-delay-1';
8
+ const DELAY_KEY_2 = 'analytics-delay-2';
7
9
  export function Analytics() {
8
10
  const cache = useServerRequest().ctx.cache;
9
11
  // If render cache is empty, create a 50 ms delay so that React doesn't resolve this
10
12
  // component too early and potentially cause a mismatch in hydration
11
- if (cache.size === 0 && !cache.has(DELAY_KEY)) {
12
- let result;
13
- let promise;
14
- cache.set(DELAY_KEY, () => {
15
- if (result !== undefined) {
16
- return result;
17
- }
18
- if (!promise) {
19
- promise = new Promise((resolve) => {
20
- setTimeout(() => {
21
- result = true;
22
- resolve(true);
23
- }, 50);
24
- });
25
- }
26
- throw promise;
27
- });
13
+ if (cache.size === 0 && !cache.has(DELAY_KEY_1)) {
14
+ analyticsDelay(cache, DELAY_KEY_1, 50);
28
15
  }
16
+ // If this delay is created, execute it
17
+ cache.has(DELAY_KEY_1) && cache.get(DELAY_KEY_1).read();
18
+ // clean up this key so that it won't be saved to the preload cache
19
+ cache.delete(DELAY_KEY_1);
29
20
  // Make sure all queries have returned before rendering the Analytics server component
30
21
  cache.forEach((cacheFn) => {
31
22
  if (cacheFn && typeof cacheFn === 'function') {
@@ -34,7 +25,23 @@ export function Analytics() {
34
25
  throw result;
35
26
  }
36
27
  });
37
- const analyticsData = useServerAnalytics();
28
+ // If all queries has returned (could be from cached queries),
29
+ // delay Analytic component by another 1ms (put this component
30
+ // to the end of the render queue) so that other scheduled
31
+ // render work can be processed by React's concurrent render first
32
+ if (cache.size > 1 && !cache.has(DELAY_KEY_2)) {
33
+ analyticsDelay(cache, DELAY_KEY_2, 1);
34
+ }
35
+ cache.has(DELAY_KEY_2) && cache.get(DELAY_KEY_2).read();
36
+ cache.delete(DELAY_KEY_2);
38
37
  return (React.createElement(AnalyticsErrorBoundary, null,
39
- React.createElement(AnalyticsClient, { analyticsDataFromServer: analyticsData })));
38
+ React.createElement(AnalyticsClient, { analyticsDataFromServer: useServerAnalytics() })));
39
+ }
40
+ function analyticsDelay(cache, delayKey, delay) {
41
+ const delayPromise = wrapPromise(new Promise((resolve) => {
42
+ setTimeout(() => {
43
+ resolve(true);
44
+ }, delay);
45
+ }));
46
+ cache.set(delayKey, delayPromise);
40
47
  }
@@ -1,10 +1,11 @@
1
1
  import type { Subscriber, SubscriberFunction } from './types';
2
- declare function pushToPageAnalyticsData(data: any, namespace?: string): void;
2
+ declare function pushToPageAnalyticsData(data: any): void;
3
3
  declare function getPageAnalyticsData(): any;
4
4
  declare function resetPageAnalyticsData(): void;
5
- declare function publish(eventname: string, guardDup?: boolean, payload?: any): void;
5
+ declare function publish(eventname: string, guardDup?: boolean, payload?: {}): void;
6
6
  declare function subscribe(eventname: string, callbackFunction: SubscriberFunction): Subscriber;
7
7
  declare function pushToServer(init?: RequestInit, searchParam?: string): Promise<Response>;
8
+ declare function hasSentFirstPageView(): Boolean;
8
9
  export declare const ClientAnalytics: {
9
10
  pushToPageAnalyticsData: typeof pushToPageAnalyticsData;
10
11
  getPageAnalyticsData: typeof getPageAnalyticsData;
@@ -21,5 +22,6 @@ export declare const ClientAnalytics: {
21
22
  DISCOUNT_CODE_UPDATED: string;
22
23
  PERFORMANCE: string;
23
24
  };
25
+ hasSentFirstPageView: typeof hasSentFirstPageView;
24
26
  };
25
27
  export {};
@@ -1,9 +1,10 @@
1
- import { getNamedspacedEventname } from './utils';
1
+ import { getNamedspacedEventname, mergeDeep } from './utils';
2
2
  import { eventNames } from './const';
3
3
  import { EVENT_PATHNAME } from '../../constants';
4
4
  import { META_ENV_SSR } from '../ssr-interop';
5
5
  const subscribers = {};
6
6
  let pageAnalyticsData = {};
7
+ let isFirstPageViewSent = false;
7
8
  const guardDupEvents = {};
8
9
  const USAGE_ERROR = 'ClientAnalytics should only be used within the useEffect callback or event handlers';
9
10
  function isInvokedFromServer() {
@@ -13,15 +14,10 @@ function isInvokedFromServer() {
13
14
  }
14
15
  return false;
15
16
  }
16
- function pushToPageAnalyticsData(data, namespace) {
17
+ function pushToPageAnalyticsData(data) {
17
18
  if (isInvokedFromServer())
18
19
  return;
19
- if (namespace) {
20
- pageAnalyticsData[namespace] = Object.assign({}, pageAnalyticsData[namespace] || {}, data);
21
- }
22
- else {
23
- pageAnalyticsData = Object.assign({}, pageAnalyticsData, data);
24
- }
20
+ pageAnalyticsData = mergeDeep(pageAnalyticsData, data);
25
21
  }
26
22
  function getPageAnalyticsData() {
27
23
  if (isInvokedFromServer())
@@ -33,12 +29,10 @@ function resetPageAnalyticsData() {
33
29
  return;
34
30
  pageAnalyticsData = {};
35
31
  }
36
- function publish(eventname, guardDup = false, payload) {
32
+ function publish(eventname, guardDup = false, payload = {}) {
37
33
  if (isInvokedFromServer())
38
34
  return;
39
35
  const namedspacedEventname = getNamedspacedEventname(eventname);
40
- const subs = subscribers[namedspacedEventname];
41
- const combinedPayload = Object.assign({}, pageAnalyticsData, payload);
42
36
  // De-dup events due to re-renders
43
37
  if (guardDup) {
44
38
  const eventGuardTimeout = guardDupEvents[namedspacedEventname];
@@ -46,15 +40,19 @@ function publish(eventname, guardDup = false, payload) {
46
40
  clearTimeout(eventGuardTimeout);
47
41
  }
48
42
  const namespacedTimeout = setTimeout(() => {
49
- publishEvent(subs, combinedPayload);
43
+ publishEvent(namedspacedEventname, mergeDeep(pageAnalyticsData, payload));
50
44
  }, 100);
51
45
  guardDupEvents[namedspacedEventname] = namespacedTimeout;
52
46
  }
53
47
  else {
54
- publishEvent(subs, combinedPayload);
48
+ publishEvent(namedspacedEventname, mergeDeep(pageAnalyticsData, payload));
55
49
  }
56
50
  }
57
- function publishEvent(subs, payload) {
51
+ function publishEvent(eventname, payload) {
52
+ const subs = subscribers[eventname];
53
+ if (!isFirstPageViewSent && eventname === eventNames.PAGE_VIEW) {
54
+ isFirstPageViewSent = true;
55
+ }
58
56
  if (subs) {
59
57
  Object.keys(subs).forEach((key) => {
60
58
  subs[key](payload);
@@ -86,6 +84,9 @@ function pushToServer(init, searchParam) {
86
84
  },
87
85
  }, init));
88
86
  }
87
+ function hasSentFirstPageView() {
88
+ return isFirstPageViewSent;
89
+ }
89
90
  export const ClientAnalytics = {
90
91
  pushToPageAnalyticsData,
91
92
  getPageAnalyticsData,
@@ -94,4 +95,5 @@ export const ClientAnalytics = {
94
95
  subscribe,
95
96
  pushToServer,
96
97
  eventNames,
98
+ hasSentFirstPageView,
97
99
  };
@@ -0,0 +1,4 @@
1
+ import type { ResolvedHydrogenConfig } from '../../types';
2
+ export declare function ServerAnalyticsRoute(request: Request, { hydrogenConfig }: {
3
+ hydrogenConfig: ResolvedHydrogenConfig;
4
+ }): Promise<Response>;
@@ -0,0 +1,36 @@
1
+ import { log } from '../../utilities/log';
2
+ export async function ServerAnalyticsRoute(request, { hydrogenConfig }) {
3
+ const requestHeader = request.headers;
4
+ const requestUrl = request.url;
5
+ const serverAnalyticsConnectors = hydrogenConfig.serverAnalyticsConnectors;
6
+ if (requestHeader.get('Content-Length') === '0') {
7
+ serverAnalyticsConnectors?.forEach((connector) => {
8
+ connector.request(requestUrl, request.headers);
9
+ });
10
+ }
11
+ else if (requestHeader.get('Content-Type') === 'application/json') {
12
+ Promise.resolve(request.json())
13
+ .then((data) => {
14
+ serverAnalyticsConnectors?.forEach((connector) => {
15
+ connector.request(requestUrl, requestHeader, data, 'json');
16
+ });
17
+ })
18
+ .catch((error) => {
19
+ log.warn('Fail to resolve server analytics: ', error);
20
+ });
21
+ }
22
+ else {
23
+ Promise.resolve(request.text())
24
+ .then((data) => {
25
+ serverAnalyticsConnectors?.forEach((connector) => {
26
+ connector.request(requestUrl, requestHeader, data, 'text');
27
+ });
28
+ })
29
+ .catch((error) => {
30
+ log.warn('Fail to resolve server analytics: ', error);
31
+ });
32
+ }
33
+ return new Response(null, {
34
+ status: 200,
35
+ });
36
+ }
@@ -0,0 +1,3 @@
1
+ export declare const PerformanceMetricsServerAnalyticsConnector: {
2
+ request(requestUrl: string, requestHeader: Headers, data?: any, contentType?: string): void;
3
+ };
@@ -0,0 +1,27 @@
1
+ import { log } from '../../../../utilities/log';
2
+ export const PerformanceMetricsServerAnalyticsConnector = {
3
+ request(requestUrl, requestHeader, data, contentType) {
4
+ const url = new URL(requestUrl);
5
+ if (url.search === '?performance' && contentType === 'json') {
6
+ const initTime = new Date().getTime();
7
+ fetch('https://monorail-edge.shopifysvc.com/v1/produce', {
8
+ method: 'post',
9
+ headers: {
10
+ 'content-type': 'text/plain',
11
+ 'x-forwarded-for': requestHeader.get('x-forwarded-for') || '',
12
+ 'user-agent': requestHeader.get('user-agent') || '',
13
+ },
14
+ body: JSON.stringify({
15
+ schema_id: 'hydrogen_buyer_performance/2.0',
16
+ payload: data,
17
+ metadata: {
18
+ event_created_at_ms: initTime,
19
+ event_sent_at_ms: new Date().getTime(),
20
+ },
21
+ }),
22
+ }).catch((err) => {
23
+ log.error(err);
24
+ });
25
+ }
26
+ },
27
+ };
@@ -0,0 +1,3 @@
1
+ export declare const ShopifyServerAnalyticsConnector: {
2
+ request(requestUrl: string, requestHeader: Headers, data?: any, contentType?: string): void;
3
+ };
@@ -0,0 +1,21 @@
1
+ import { log } from '../../../../utilities/log';
2
+ export const ShopifyServerAnalyticsConnector = {
3
+ request(requestUrl, requestHeader, data, contentType) {
4
+ const url = new URL(requestUrl);
5
+ if (url.search === '?shopify' && contentType === 'json') {
6
+ data.events.forEach((event) => {
7
+ event.payload.client_ip_address = requestHeader.get('x-forwarded-for');
8
+ event.payload.client_user_agent = requestHeader.get('user-agent');
9
+ });
10
+ fetch('https://monorail-edge.shopifysvc.com/unstable/produce_batch', {
11
+ method: 'post',
12
+ headers: {
13
+ 'content-type': 'text/plain',
14
+ },
15
+ body: JSON.stringify(data),
16
+ }).catch((err) => {
17
+ log.error(err);
18
+ });
19
+ }
20
+ },
21
+ };
@@ -0,0 +1,3 @@
1
+ export declare function ShopifyAnalyticsClient({ cookieDomain }: {
2
+ cookieDomain: string;
3
+ }): null;
@@ -0,0 +1,190 @@
1
+ import { useEffect } from 'react';
2
+ import { parse, stringify } from 'worktop/cookie';
3
+ import { ClientAnalytics } from '../../index';
4
+ import { buildUUID, addDataIf } from './utils';
5
+ import { SHOPIFY_S, SHOPIFY_Y } from './const';
6
+ const longTermLength = 60 * 60 * 24 * 360 * 2; // ~2 year expiry
7
+ const shortTermLength = 60 * 30; // 30 mins
8
+ const myShopifyDomain = 'myshopify.com';
9
+ const oxygenDomain = 'myshopify.dev';
10
+ let isInit = false;
11
+ let microSessionCount = 0;
12
+ export function ShopifyAnalyticsClient({ cookieDomain }) {
13
+ useEffect(() => {
14
+ try {
15
+ // Find Shopify cookies
16
+ const cookieData = parse(document.cookie);
17
+ const shopifyYCookie = cookieData[SHOPIFY_Y] || buildUUID();
18
+ const shopifySCookie = cookieData[SHOPIFY_S] || buildUUID();
19
+ /**
20
+ * Set user and session cookies and refresh the expiry time
21
+ */
22
+ updateCookie(SHOPIFY_Y, shopifyYCookie, longTermLength, cookieDomain);
23
+ updateCookie(SHOPIFY_S, shopifySCookie, shortTermLength, cookieDomain);
24
+ ClientAnalytics.pushToPageAnalyticsData({
25
+ shopify: {
26
+ pageId: buildUUID(),
27
+ userId: shopifyYCookie,
28
+ sessionId: shopifySCookie,
29
+ },
30
+ });
31
+ microSessionCount = 0;
32
+ // TODO: Fix with useEvent when ready
33
+ // RFC: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
34
+ if (!isInit) {
35
+ isInit = true;
36
+ const eventNames = ClientAnalytics.eventNames;
37
+ ClientAnalytics.subscribe(eventNames.PAGE_VIEW, trackPageView);
38
+ // On a slow network, the pageview event could be already fired before
39
+ // we subscribed to the pageview event
40
+ if (ClientAnalytics.hasSentFirstPageView()) {
41
+ trackPageView(ClientAnalytics.getPageAnalyticsData());
42
+ }
43
+ }
44
+ }
45
+ catch (err) {
46
+ // Do nothing
47
+ }
48
+ });
49
+ return null;
50
+ }
51
+ function updateCookie(cookieName, value, maxage, cookieDomain) {
52
+ const cookieString = stringify(cookieName, value, {
53
+ maxage,
54
+ domain: getCookieDomain(cookieDomain),
55
+ secure: process.env.NODE_ENV === 'production',
56
+ samesite: 'Lax',
57
+ path: '/',
58
+ });
59
+ document.cookie = cookieString;
60
+ return cookieString;
61
+ }
62
+ function getCookieDomain(cookieDomain) {
63
+ const hostname = location.hostname;
64
+ if (hostname.indexOf(myShopifyDomain) !== -1) {
65
+ return `.${hostname.split('.').slice(-3).join('.')}`;
66
+ }
67
+ else if (hostname.indexOf(cookieDomain) !== -1) {
68
+ return `.${cookieDomain}`;
69
+ }
70
+ else {
71
+ return '';
72
+ }
73
+ }
74
+ function trackPageView(payload) {
75
+ microSessionCount += 1;
76
+ try {
77
+ sendToServer(storefrontPageViewSchema(payload));
78
+ }
79
+ catch (error) {
80
+ console.error(`Error Shopify analytics: ${ClientAnalytics.eventNames.PAGE_VIEW}`, error);
81
+ }
82
+ }
83
+ function storefrontPageViewSchema(payload) {
84
+ return {
85
+ schema_id: 'trekkie_storefront_page_view/1.4',
86
+ payload: buildStorefrontPageViewPayload(payload),
87
+ metadata: {
88
+ event_created_at_ms: Date.now(),
89
+ },
90
+ };
91
+ }
92
+ function buildStorefrontPageViewPayload(payload) {
93
+ const location = document.location;
94
+ const shopify = payload.shopify;
95
+ let formattedData = {
96
+ appClientId: '6167201',
97
+ hydrogenSubchannelId: shopify.storefrontId,
98
+ isPersistentCookie: shopify.isPersistentCookie,
99
+ uniqToken: shopify.userId,
100
+ visitToken: shopify.sessionId,
101
+ microSessionId: shopify.pageId,
102
+ microSessionCount,
103
+ url: location.href,
104
+ path: location.pathname,
105
+ search: location.search,
106
+ referrer: document.referrer,
107
+ title: document.title,
108
+ shopId: stripGId(shopify.shopId),
109
+ currency: shopify.currency,
110
+ contentLanguage: shopify.acceptedLanguage,
111
+ };
112
+ formattedData = addDataIf({
113
+ isMerchantRequest: isMerchantRequest(),
114
+ }, formattedData);
115
+ formattedData = addDataIf({
116
+ pageType: shopify.pageType,
117
+ }, formattedData);
118
+ if (shopify.resourceId) {
119
+ try {
120
+ formattedData = addDataIf({
121
+ resourceType: getResourceType(shopify.resourceId),
122
+ resourceId: stripGId(shopify.resourceId),
123
+ }, formattedData);
124
+ }
125
+ catch (err) {
126
+ // do nothing
127
+ }
128
+ }
129
+ formattedData = addDataIf({
130
+ customerId: shopify.customerId,
131
+ }, formattedData);
132
+ return formattedData;
133
+ }
134
+ function isMerchantRequest() {
135
+ const hostname = location.hostname;
136
+ if (hostname.indexOf(oxygenDomain) !== -1 || hostname === 'localhost') {
137
+ return true;
138
+ }
139
+ return false;
140
+ }
141
+ function stripGId(text) {
142
+ return parseInt(text.substring(text.lastIndexOf('/') + 1));
143
+ }
144
+ function getResourceType(text) {
145
+ return text
146
+ .substring(0, text.lastIndexOf('/'))
147
+ .replace(/.*shopify\//, '')
148
+ .toLowerCase();
149
+ }
150
+ const BATCH_SENT_TIMEOUT = 500;
151
+ let batchedData = [];
152
+ let batchedTimeout;
153
+ function sendToServer(data) {
154
+ batchedData.push(data);
155
+ if (batchedTimeout) {
156
+ clearTimeout(batchedTimeout);
157
+ batchedTimeout = null;
158
+ }
159
+ batchedTimeout = setTimeout(() => {
160
+ const batchedDataToBeSent = {
161
+ events: batchedData,
162
+ metadata: {
163
+ event_sent_at_ms: Date.now(),
164
+ },
165
+ };
166
+ batchedData = [];
167
+ batchedTimeout = null;
168
+ // Send to server
169
+ try {
170
+ fetch('/__event?shopify', {
171
+ method: 'post',
172
+ headers: {
173
+ 'cache-control': 'no-cache',
174
+ 'Content-Type': 'application/json',
175
+ },
176
+ body: JSON.stringify(batchedDataToBeSent),
177
+ });
178
+ }
179
+ catch (error) {
180
+ // Fallback to client-side
181
+ fetch('https://monorail-edge.shopifysvc.com/unstable/produce_batch', {
182
+ method: 'post',
183
+ headers: {
184
+ 'content-type': 'text/plain',
185
+ },
186
+ body: JSON.stringify(batchedDataToBeSent),
187
+ });
188
+ }
189
+ }, BATCH_SENT_TIMEOUT);
190
+ }
@@ -0,0 +1,3 @@
1
+ export declare function ShopifyAnalytics({ cookieDomain }: {
2
+ cookieDomain?: string;
3
+ }): JSX.Element;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { parse } from 'worktop/cookie';
3
+ import AnalyticsErrorBoundary from '../../../AnalyticsErrorBoundary.client';
4
+ import { useServerRequest } from '../../../ServerRequestProvider';
5
+ import { useServerAnalytics } from '../../hook';
6
+ import { useShop } from '../../../useShop';
7
+ import { SHOPIFY_S, SHOPIFY_Y } from './const';
8
+ import { ShopifyAnalyticsClient } from './ShopifyAnalytics.client';
9
+ export function ShopifyAnalytics({ cookieDomain }) {
10
+ const { storeDomain } = useShop();
11
+ const request = useServerRequest();
12
+ const cookies = parse(request.headers.get('Cookie') || '');
13
+ const domain = cookieDomain || storeDomain;
14
+ useServerAnalytics({
15
+ shopify: {
16
+ storefrontId: globalThis.Oxygen?.env?.SHOPIFY_STOREFRONT_ID || '0',
17
+ acceptedLanguage: request.headers.get('Accept-Language')?.replace(/-.*/, '') || 'en',
18
+ isPersistentCookie: !!cookies[SHOPIFY_S] || !!cookies[SHOPIFY_Y],
19
+ },
20
+ });
21
+ return (React.createElement(AnalyticsErrorBoundary, null,
22
+ React.createElement(ShopifyAnalyticsClient, { cookieDomain: domain })));
23
+ }
@@ -0,0 +1,28 @@
1
+ export declare const SHOPIFY_Y = "_shopify_y";
2
+ export declare const SHOPIFY_S = "_shopify_s";
3
+ export declare const ShopifyAnalyticsConstants: {
4
+ pageType: {
5
+ article: string;
6
+ blog: string;
7
+ captcha: string;
8
+ cart: string;
9
+ collection: string;
10
+ customersAccount: string;
11
+ customersActivateAccount: string;
12
+ customersAddresses: string;
13
+ customersLogin: string;
14
+ customersOrder: string;
15
+ customersRegister: string;
16
+ customersResetPassword: string;
17
+ giftCard: string;
18
+ home: string;
19
+ listCollections: string;
20
+ forbidden: string;
21
+ notFound: string;
22
+ page: string;
23
+ password: string;
24
+ product: string;
25
+ policy: string;
26
+ search: string;
27
+ };
28
+ };
@@ -0,0 +1,51 @@
1
+ export const SHOPIFY_Y = '_shopify_y';
2
+ export const SHOPIFY_S = '_shopify_s';
3
+ // Shopify analytics constants
4
+ const article = 'article';
5
+ const blog = 'blog';
6
+ const captcha = 'captcha';
7
+ const cart = 'cart';
8
+ const collection = 'collection';
9
+ const customersAccount = 'customers/account';
10
+ const customersActivateAccount = 'customers/activate_account';
11
+ const customersAddresses = 'customers/addresses';
12
+ const customersLogin = 'customers/login';
13
+ const customersOrder = 'customers/order';
14
+ const customersRegister = 'customers/register';
15
+ const customersResetPassword = 'customers/reset_password';
16
+ const giftCard = 'gift_card';
17
+ const home = 'index';
18
+ const listCollections = 'list-collections';
19
+ const forbidden = '403';
20
+ const notFound = '404';
21
+ const page = 'page';
22
+ const password = 'password';
23
+ const product = 'product';
24
+ const policy = 'policy';
25
+ const search = 'search';
26
+ export const ShopifyAnalyticsConstants = {
27
+ pageType: {
28
+ article,
29
+ blog,
30
+ captcha,
31
+ cart,
32
+ collection,
33
+ customersAccount,
34
+ customersActivateAccount,
35
+ customersAddresses,
36
+ customersLogin,
37
+ customersOrder,
38
+ customersRegister,
39
+ customersResetPassword,
40
+ giftCard,
41
+ home,
42
+ listCollections,
43
+ forbidden,
44
+ notFound,
45
+ page,
46
+ password,
47
+ product,
48
+ policy,
49
+ search,
50
+ },
51
+ };
@@ -0,0 +1,3 @@
1
+ export declare function buildUUID(): string;
2
+ export declare function hexTime(): string;
3
+ export declare function addDataIf(keyValuePairs: Record<string, string | number | Boolean>, formattedData: any): any;