Skip to main content

Google Analytics (GA4) events from the Size Hub are not arriving on a headless storefront: how to pass cookie consent

If you added your GA4 Measurement ID to the Size Hub but no Measmerize events show up in Google Analytics, the Size Hub probably never received your shoppers' cookie consent. This article explains why, and how to pass the consent choice to the Size Hub fr

⚠️ Developer article. This change is made in your storefront code, so it is for your development team or agency. Your team owns the integration and Measmerize can't make this change for you.

Symptoms

  • Your GA4 Measurement ID (format G-XXXXXXXXXX) is set for the Size Hub, and your storefront shows the Size Hub button.

  • No Measmerize events appear in GA4 (Realtime, DebugView or the Events report), for example button_with_recommendation_show or page_recommendation_view.

  • No Measmerize requests to Google Analytics show in your browser's network tab on a product page.

  • Your storefront is headless (for example Hydrogen) and uses its own cookie banner, or a consent tool the Size Hub doesn't support.

If you run several stores with one GA4 property each (for example one per region), the symptom is the same on each store.

Why it happens

The Size Hub only sends analytics events after the shopper agrees to analytics cookies. Until it receives a consent choice, analytics stays off.

It reads that choice automatically from two places:

  • Common consent tools such as OneTrust, Cookiebot and Didomi.

  • Shopify's consent object, on standard Shopify themes.

On a headless storefront, neither may be available. If your banner isn't a supported consent tool and Shopify's consent object isn't on the page, the Size Hub sees no consent and keeps analytics off. Your Measurement ID is already in place. It just isn't used until consent arrives.

How to fix it

Pass the shopper's choice from your own consent logic to the Size Hub, using the global object window.measmerize.

1. Call the matching function for each consent category

The shopper...

Call

What it does

Accepts analytics cookies

window.measmerize.tracking.enableAnalytics()

Turns on GA4 events, including to your Measurement ID

Accepts analytics cookies

window.measmerize.tracking.enableCustom()

Turns on Measmerize's event tracking

Accepts functional or preference cookies

window.measmerize.cookies.enableFunctional()

Remembers the shopper's measurements between visits

Rejects or withdraws analytics consent

window.measmerize.tracking.disableAnalytics() and window.measmerize.tracking.disableCustom()

Turns the matching tracking off

Rejects or withdraws functional consent

window.measmerize.cookies.disableFunctional()

Stops remembering measurements

2. Call them at the right time

  • On every product page where the Size Hub loads, with the shopper's current choice.

  • Again whenever the shopper changes their choice.

If window.measmerize isn't available yet when your code runs, wait for the measmerize.script.ready event on the measmerize-script element, then make the calls.

// Illustrative: replace the consent values with your own consent logic.
function applyMeasmerizeConsent({ analytics, functional }) {
if (analytics) {
window.measmerize.tracking.enableAnalytics();
window.measmerize.tracking.enableCustom();
} else {
window.measmerize.tracking.disableAnalytics();
window.measmerize.tracking.disableCustom();
}

if (functional) {
window.measmerize.cookies.enableFunctional();
} else {
window.measmerize.cookies.disableFunctional();
}
}

Check it worked

  1. Open a product page on your storefront and accept analytics cookies in your banner.

  2. Open your browser's network tab and look for requests to Google Analytics that carry your Measurement ID.

  3. In GA4, open Realtime or DebugView and look for Measmerize events such as button_with_recommendation_show and page_recommendation_view. They show in the Events report after GA4 processes them.

  4. Reject analytics cookies, reload the page, and confirm the events stop.

Common problems

Still not working?

Email [email protected] with your store URL, the product URL you're testing, and your Measurement ID.

Related articles

Did this answer your question?