Gathers client browser values commonly used for analytics
import * as React from 'react';
import {useEffect} from 'react';
import {getClientBrowserParameters} from '@shopify/hydrogen-react';
export default function App({Component, pageProps}) {
useEffect(() => {
getClientBrowserParameters();
});
return <Component {...pageProps} />;
}
import * as React from 'react';
import {useEffect} from 'react';
import {getClientBrowserParameters} from '@shopify/hydrogen-react';
export default function App({Component, pageProps}) {
useEffect(() => {
getClientBrowserParameters();
});
return <Component {...pageProps} />;
}
If executed on server, this method will return empty string for each field.
export function getClientBrowserParameters(): ClientBrowserParameters { if (errorIfServer('getClientBrowserParameters')) { return { uniqueToken: '', visitToken: '', url: '', path: '', search: '', referrer: '', title: '', userAgent: '', navigationType: '', navigationApi: '', }; } const [navigationType, navigationApi] = getNavigationType(); const cookies = getShopifyCookies(document.cookie); return { uniqueToken: cookies[SHOPIFY_Y], visitToken: cookies[SHOPIFY_S], url: location.href, path: location.pathname, search: location.search, referrer: document.referrer, title: document.title, userAgent: navigator.userAgent, navigationType, navigationApi, }; }
Navigation api: `'PerformanceNavigationTiming' | 'performance.navigation'`. Use `getClientBrowserParameters()` to collect this value.
Navigation type: `'navigate' | 'reload' | 'back_forward' | 'prerender' | 'unknown'`. Use `getClientBrowserParameters()` to collect this value.
Value of `window.location.pathname`. Use `getClientBrowserParameters()` to collect this value.
Value of `window.document.referrer`. Use `getClientBrowserParameters()` to collect this value.
Value of `window.location.search`. Use `getClientBrowserParameters()` to collect this value.
Value of `document.title`. Use `getClientBrowserParameters()` to collect this value.
Shopify unique user token: Value of `_shopify_y` cookie. Use `getClientBrowserParameters()` to collect this value.
Value of `window.location.href`. Use `getClientBrowserParameters()` to collect this value.
Value of `navigator.userAgent`. Use `getClientBrowserParameters()` to collect this value.
Shopify session token: Value of `_shopify_s` cookie. Use `getClientBrowserParameters()` to collect this value.