Optimize your store’s performance with search tracking
You can measure your storefront’s search performance and improve its relevance by collecting and leveraging customer interaction data.
This guide shows you how to set up search tracking on your custom storefront using the Storefront API and Shopify analytics functionality available in Hydrogen.
What you’ll learnAnchor link to section titled "What you’ll learn"
In this tutorial, you’ll learn how to do the following tasks:
- Set up Shopify cookies.
- Extract and append search tracking parameters.
- Send analytics to Shopify.
RequirementsAnchor link to section titled "Requirements"
Step 1: Set up Shopify cookiesAnchor link to section titled "Step 1: Set up Shopify cookies"
To enable search tracking, use Hydrogen’s
useShopifyCookies hook to create and refresh required Shopify cookies. It's up to you to decide how to obtain the value for
hasUserConsent set to
true, Shopify cookies are removed.
Shopify cookies are automatically added to Storefront API queries when Hydrogen’s
createStorefrontClient utility function is used.
Step 2: Extract and append search tracking parametersAnchor link to section titled "Step 2: Extract and append search tracking parameters"
You can extract search tracking parameters from the
predictiveSearch responses using the
trackingParameters field. The following examples show how to return the tracking parameters and append them to the search result URLs.
Example of Anchor link to section titled "Example of search"
Example of Anchor link to section titled "Example of predictiveSearch"
Example of appending tracking parametersAnchor link to section titled "Example of appending tracking parameters"
The following example shows how to construct search result URLs using an array of products.
The following example shows how to construct search result URLs using an array of queries.
Step 3: Send analytics to ShopifyAnchor link to section titled "Step 3: Send analytics to Shopify"
- Customize search, filters, and product recommendations using the Shopify Search & Discovery app.