---
title: getTrackingValues
description: >-
  Retrieves user session tracking values for analytics and marketing from the
  browser environment.
api_version: 2026-04
source_url:
  html: >-
    https://shopify.dev/docs/api/hydrogen-react/latest/utilities/gettrackingvalues
  md: >-
    https://shopify.dev/docs/api/hydrogen-react/latest/utilities/gettrackingvalues.md
---

# 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.

## get​Tracking​Values()

Retrieves user session tracking values for analytics and marketing from the browser environment.

### Returns

* **TrackingValues**

### TrackingValues

* consent

  Represents the consent given by the user or the default region consent configured in Admin

  ```ts
  string
  ```

* uniqueToken

  Identifier for the unique user. Equivalent to the deprecated \_shopify\_y cookie

  ```ts
  string
  ```

* visitToken

  Identifier for the current visit. Equivalent to the deprecated \_shopify\_s cookie

  ```ts
  string
  ```

Examples

### Examples

* #### Example code

  ##### Description

  I am the default example

  ##### JavaScript

  ```jsx
  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,
      }),
    });
  }
  ```

  ##### TypeScript

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

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

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

***

## Related

[- useShopifyCookies](https://shopify.dev/docs/api/hydrogen-react/2026-04/hooks/useshopifycookies)

[- getShopifyCookies](https://shopify.dev/docs/api/hydrogen-react/2026-04/utilities/getshopifycookies)

***
