---
title: useShopifyCookies
description: Sets Shopify user and session cookies and refreshes the expiry time.
api_version: 2026-04
api_name: hydrogen
source_url:
html: 'https://shopify.dev/docs/api/hydrogen/latest/hooks/useshopifycookies'
md: 'https://shopify.dev/docs/api/hydrogen/latest/hooks/useshopifycookies.md'
---
# useShopifyCookies
Sets Shopify user and session cookies and refreshes the expiry time. Returns `true` when cookies are ready.
## useShopifyCookies(**[options](#useshopifycookies-propertydetail-options)**)
Sets the `shopify_y` and `shopify_s` cookies in the browser based on user consent for backward compatibility support.
If `fetchTrackingValues` is true, it makes a request to Storefront API to fetch or refresh Shopiy analytics and marketing cookies and tracking values. Generally speaking, this should only be needed if you're not using Hydrogen's built-in analytics components and hooks that already handle this automatically. For example, set it to `true` if you are using `hydrogen-react` only with a different framework and still need to make a same-domain request to Storefront API to set cookies.
If `ignoreDeprecatedCookies` is true, it skips setting the deprecated cookies entirely. Useful when you only want to use the newer tracking values and not rely on the deprecated ones.
### Parameters
* **options**
**UseShopifyCookiesOptions**
### Returns**boolean**
* `true` when cookies are set and ready.
### UseShopifyCookiesOptions
```ts
CoreShopifyCookiesOptions & {
/**
* If set to `false`, Shopify cookies will be removed.
* If set to `true`, Shopify unique user token cookie will have cookie expiry of 1 year.
* Defaults to false.
**/
hasUserConsent?: boolean;
/**
* The domain scope of the cookie. Defaults to empty string.
**/
domain?: string;
/**
* The checkout domain of the shop. Defaults to empty string. If set, the cookie domain will check if it can be set with the checkout domain.
*/
checkoutDomain?: string;
/**
* If set to `true`, it skips modifying the deprecated shopify_y and shopify_s cookies.
*/
ignoreDeprecatedCookies?: boolean;
}
```
### CoreShopifyCookiesOptions
* checkoutDomain
```ts
string
```
* fetchTrackingValues
```ts
boolean
```
* storefrontAccessToken
```ts
string
```
Examples
### Examples
* #### Example code
##### JavaScript
```jsx
import * as React from 'react';
import {useShopifyCookies} from '@shopify/hydrogen';
export default function App({Component, pageProps}) {
// Returns true when cookies are ready
const cookiesReady = useShopifyCookies({hasUserConsent: true});
if (!cookiesReady) {
return null;
}
return ;
}
```
##### TypeScript
```tsx
import * as React from 'react';
import {useShopifyCookies} from '@shopify/hydrogen';
export default function App({
Component,
pageProps,
}: {
Component: React.ComponentType;
pageProps: object;
}) {
// Returns true when cookies are ready
const cookiesReady = useShopifyCookies({hasUserConsent: true});
if (!cookiesReady) {
return null;
}
return ;
}
```
***
## Related
[- sendShopifyAnalytics](https://shopify.dev/docs/api/hydrogen/2026-04/utilities/sendshopifyanalytics)
[- getClientBrowserParameters](https://shopify.dev/docs/api/hydrogen/2026-04/utilities/getclientbrowserparameters)
[- getTrackingValues](https://shopify.dev/docs/api/hydrogen/2026-04/utilities/gettrackingvalues)
***