get Shopify Cookies
Parses cookie string and returns Shopify cookies. For tracking values, consider using getTrackingValues instead, which reads from modern Shopify cookies.
Gets the values of _shopify_y and _shopify_s cookies from the provided cookie string. If the Shopify cookies doesn't exist, this method will return an empty string for each missing cookie.
Anchor to getShopifyCookies-parametersParameters
- stringstringrequiredrequired
ShopifyCookiesShopifyCookies
ShopifyCookies
Shopify cookies names
- _shopify_s
Shopify session token: Value of `_shopify_s` cookie.
string - _shopify_y
Shopify unique user token: Value of `_shopify_y` cookie.
string
Shopify cookies names
- stringstringrequiredrequired
Shopify session token: Value of
cookie.- stringstringrequiredrequired
Shopify unique user token: Value of
cookie.
Examples
import * as React from 'react';
import {useEffect} from 'react';
import {getShopifyCookies} from '@shopify/hydrogen-react';
export default function App({Component, pageProps}) {
useEffect(() => {
getShopifyCookies(document.cookie);
});
return <Component {...pageProps} />;
}
Examples
Example code
Description
I am the default example
JavaScript
import * as React from 'react'; import {useEffect} from 'react'; import {getShopifyCookies} from '@shopify/hydrogen-react'; export default function App({Component, pageProps}) { useEffect(() => { getShopifyCookies(document.cookie); }); return <Component {...pageProps} />; }TypeScript
import * as React from 'react'; import {useEffect} from 'react'; import {getShopifyCookies} from '@shopify/hydrogen-react'; export default function App({Component, pageProps}) { useEffect(() => { getShopifyCookies(document.cookie); }); return <Component {...pageProps} />; }
Was this page helpful?