Skip to main content

getTrackingValues

Retrieves user session tracking values for analytics and marketing from the browser environment. It reads from server-timing headers in Storefront API responses and falls back to deprecated cookies for backward compatibility.

Anchor to getTrackingValues
getTrackingValues()

Retrieves user session tracking values for analytics and marketing from the browser environment. Customer Privacy API token readers are authoritative when available, including when consent denies tracking. Deprecated _shopify_y/_shopify_s cookies are read only without an API token reader. Consent comes from CTA's cache or the legacy _tracking_consent cookie.

Examples
import {getTrackingValues} from '@shopify/hydrogen-react';

export function sendCustomAnalyticsEvent(eventName) {
const {uniqueToken, visitToken} = getTrackingValues();

// Use tracking values in your custom analytics implementation
fetch('/api/analytics', {
method: 'POST',
body: JSON.stringify({
event: eventName,
uniqueToken,
visitToken,
}),
});
}


Was this page helpful?