hydrogen
hydrogen copied to clipboard
Analytics: product_added_to_cart event not recorded for some storefronts
What is the location of your example repository?
We have implemented the latest Shopify Analytics similar to what was done here: https://github.com/Shopify/hydrogen
Which package or tool is having this issue?
Hydrogen
What version of that package or tool are you using?
2024.4.2
What version of Remix are you using?
"@remix-run/react": "^2.9.2",
Steps to Reproduce
Our implementation of Hydrogen uses different Shopify stores for various markets that we operate in. Our main US store is where our site is deployed (through the Hydrogen
Sales Channel) and all of our other stores use the Headless
Sales Channel to get Storefront API access.
We create and use the Storefront Client conditionally in server.ts
based on the locale path variable. A generic implementation of this looks like the following:
/**
* Create Hydrogen's Storefront clients.
*/
const storeLocale = getStoreLocale(i18n);
let storefront: Storefront;
if (storeLocale === StoreLocale.CA) {
// The CA Store using the Headless Sales Channel
storefront = createStorefrontClient({
cache,
waitUntil,
i18n,
publicStorefrontToken: env.PUBLIC_STOREFRONT_API_TOKEN_CA,
privateStorefrontToken: env.PRIVATE_STOREFRONT_API_TOKEN_CA,
storeDomain: `https://${env.PUBLIC_STORE_DOMAIN_CA}`,
storefrontApiVersion: env.PUBLIC_STOREFRONT_API_VERSION,
storefrontHeaders: getStorefrontHeaders(request),
storefrontId: env.PUBLIC_STOREFRONT_ID,
}).storefront;
} else {
// The main US Store using Hydrogen's Storefront API
storefront = createStorefrontClient({
cache,
waitUntil,
i18n,
publicStorefrontToken: env.PUBLIC_STOREFRONT_API_TOKEN_US,
privateStorefrontToken: env.PRIVATE_STOREFRONT_API_TOKEN_US,
storeDomain: `https://${env.PUBLIC_STORE_DOMAIN_US}`,
storefrontApiVersion: env.PUBLIC_STOREFRONT_API_VERSION,
storefrontHeaders: getStorefrontHeaders(request),
storefrontId: env.PUBLIC_STOREFRONT_ID,
}).storefront;
}
Notice that many of the ENV
variables change based on locale, but only one instance of PUBLIC_STOREFRONT_ID
exists (generated by the Hydrogen
Sales Channel, so it is currently used for ALL of our stores...
When adding products to the cart, the product_added_to_cart
event consistently fires for ALL of our Shopify stores, but those events are not being recorded in Shopify stores using the Headless
Sales Channel for Storefront API access.
Main US store using the Hydrogen
Sales Channel:
CA store using the Headless
Sales Channel:
Expected Behavior
We expect to see Add to Cart
sessions in ALL of our Shopify Admin Analytics dashboards (ie for ALL of our stores)
Actual Behavior
We are only seeing Add to Cart
sessions for our main US store. This Storefront is where our Oxygen/Hydrogen deployment happens and is using credentials from the Hydrogen
Sales Channel.
All other stores using the Headless
Sales Channel for Storefront API access fire the product_added_to_cart
event, but there are zero Add to Cart
sessions recorded for those stores (other analytics seem to be coming through normally)