Skip to content

An fix currency empty before cart - #3931

Open
andguy95 wants to merge 5 commits into
previewfrom
an-fix-currency-empty-before-cart
Open

An fix currency empty before cart#3931
andguy95 wants to merge 5 commits into
previewfrom
an-fix-currency-empty-before-cart

Conversation

@andguy95

@andguy95 andguy95 commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

TL;DR: Initialize Shopify analytics with the active market currency before consent can replay buffered events. This prevents analytics from failing on a fresh session until the shopper adds an item to the cart.

Before

ShopifyScripts rendered before window.Shopify.currency.active was initialized. Accepting consent could therefore produce a missing-currency analytics error. Adding an item to the cart appeared to fix the issue because cart tracking synchronized the currency later.

After

Both storefront templates resolve localization.country.currency.isoCode under the active Storefront API market context and pass it to ShopifyScripts as i18n.currency during initial rendering. A configured USD fallback covers API failures and mock mode.

What this changes

  • Resolves the active market currency in the React Router root loader and passes the loader-derived i18n to ShopifyScripts.
  • Extends the Next.js cached shop lookup with localization currency and passes the resolved i18n through its client wrapper.
  • Avoids introducing a required Next.js currency environment variable.
  • Documents that shop.paymentSettings.currencyCode is the shop currency, not necessarily the active market presentment currency.
  • Treats cart currency updates as later synchronization rather than initial analytics setup.
  • Updates and synchronizes the template-generation and packaged analytics skills with the same guidance.

Developer impact

Includes a patch changeset for @shopify/hydrogen. This hardens the packaged analytics guidance and starter templates without adding exports or changing a public runtime contract.

UX impact

Analytics can send consent-replayed events on a fresh storefront session without requiring the shopper to modify their cart first.

Risk

  • If the localization lookup fails or exceeds the Next.js lookup timeout, analytics uses the configured fallback currency.
  • Market-aware storefronts should keep the localization query under the same country and language context as their catalog requests.

How to Test

  1. Start either storefront template and open it in a fresh browser session with an empty cart.
  2. Before accepting consent, confirm window.Shopify.currency.active matches the active market currency.
  3. Accept analytics consent without adding an item to the cart.
  4. Confirm window.Shopify.currency.active is unchanged and no missing-currency analytics error appears in the console.
  5. Confirm the buffered analytics event produces a Monorail request.

@andguy95
andguy95 requested a review from fredericoo August 6, 2026 23:38
@andguy95
andguy95 marked this pull request as ready for review August 6, 2026 23:38
@andguy95
andguy95 requested a review from a team as a code owner August 6, 2026 23:38
}

function getLocalizationCurrency(data: LocalizationData | null | undefined): string {
return data?.localization?.country?.currency?.isoCode ?? SHOP_FALLBACK.currency;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know SHOP_FALLBACK was already in here but it feels weird to me. Shouldn't we just bail on analytics if we don't have the right information?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's required – if not pass undefined

but yes fail before hardcoding something that may not be accurate

@frandiox frandiox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I thought currency became optional in analytics?

I guess most shops will hardcode it to their only currency, or query currency early also for their own markets support (e.g. dropdown with currencies etc). I wonder if this kind of decision should be part of the skills 🤔

@andguy95

Copy link
Copy Markdown
Collaborator Author

Yea, we made currency is optional in the Hydrogen config. I don't think it makes sense to turn it back to required just because analytics needs it

I'm checking if the analytics side can make currency optional too. If it can't, the skill felt like the more pragmatic approach. Document it as basically required so bootstrapped storefronts resolve it, pass it along, and have a fallback.

@andguy95
andguy95 force-pushed the an-fix-currency-empty-before-cart branch from 7c03625 to 04c9a70 Compare August 11, 2026 19:21
@andguy95 andguy95 added the gsd:50917 New Hydrogen label Aug 12, 2026
@frandiox

Copy link
Copy Markdown
Contributor

@andguy95 What if we just make currency a requirement when you publish a related event, instead of populating that field automatically?

I'm not familiar with the analytics events, but I think they follow web pixel standards? Those seem to use price: MoneyV2, so can't we just ask to receive that when publishing the event? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants