Before you start
You need your TextYess organization ID. Find it in the Developers section.Install the script
1
Add the script to every page
Put this code in the You can push commands before the script loads. The script runs them when it loads.
<head> of every page, for example in the root layout. Replace YOUR_ORGANIZATION_ID with your organization ID.If your storefront has a Content Security Policy, add
https://cdn.textyess.com to script-src and https://pixel.textyess.com to connect-src. In Hydrogen, add them to createContentSecurityPolicy. The policy also blocks the inline init script. Give it your page’s nonce (in Hydrogen, useNonce()), or put its two lines in a script file that the policy allows.2
Send the shopper's consent
The script sends nothing and sets no cookie until the shopper allows analytics and marketing.If your storefront loads Shopify’s Customer Privacy API (For iubenda, see Consent from iubenda.
window.Shopify.customerPrivacy), the script reads the consent there. Do nothing more.If your storefront uses another consent banner, push the shopper’s choice to the script. Push it on each page load when the banner has a saved choice. Push it again each time the shopper changes the choice.3
Send the events
Push one command each time the shopper does one of these actions. The next section gives the fields of each command.In React, push
product_viewed from an effect that runs once for each product that the page shows. Push product_added_to_cart after the cart accepts the add.Commands
The script accepts the values of the Shopify Storefront API as they are:
- Ids are Shopify ids. A Storefront API id (
gid://shopify/Product/123) and the number (123) both work. A SKU or a handle is not a Shopify id: the script ignores the event and writes a warning in the browser console. - Prices are a number, a decimal string (
"19.90"), or aMoneyV2object. Sendpriceas the price of one unit. For a cart add, the script sends the price of all the units added, as the Shopify pixel does. When you send aMoneyV2, the script reads the currency from it. imageis an image URL or anImageobject.urlis the address of the current page when you do not send one.
- A search starts a search automation only when it has a
resultsCountof 1 or more andproductIds. - A condition on the cart total needs
cartTotal: the total of the whole cart after the add.
Consent from iubenda
iubenda keeps one choice for each purpose. Purpose 4 is measurement, which TextYess reads as analytics. Purpose 5 is marketing. iubenda calls itsonPreferenceExpressedOrNotNeeded callback on each page that has a saved choice, and each time the shopper changes the choice.
Add this code to the onPreferenceExpressedOrNotNeeded callback of your iubenda configuration. Keep the code that the callback already has.
dataLayer, you can do this in Google Tag Manager instead. For example, the callback pushes { event: "iubenda_preferences", preferences: preference.purposes }:
- Create a Data Layer Variable
DLV - preferencesforpreferences. - Create a Custom HTML tag with the code below. Fire it on a Custom Event trigger with the event name
iubenda_preferences.
Install with Google Tag Manager
If your storefront already pushes GA4 ecommerce events to thedataLayer, you can install everything in Google Tag Manager. Each item of these events must carry the Shopify product id. GA4’s item_id is usually the SKU, which is not a Shopify id.
- Create a Custom HTML tag with the code of the first step. Fire it on “Initialization - All Pages”.
- Create a Custom HTML tag that pushes the
consentcommand. Fire it on thedataLayerevent of your consent banner. For iubenda, use the tag in Consent from iubenda. - Create a Data Layer Variable
DLV - ecommerceforecommerce, andDLV - search_termforsearch_term. - Create a Custom HTML tag with the code below. Fire it on a Custom Event trigger with the event name
^(view_item|add_to_cart|search)$and “Use regex matching”.
item.shopify_id with the item field that holds the Shopify product id in your dataLayer.
GA4’s search event has no results, and its add_to_cart event has no cart total. With this tag, TextYess records the searches and the cart adds, but a search starts no search automation, and a condition on the cart total does not match. If your dataLayer has these values, add resultsCount and productIds to search_submitted, and cartTotal to product_added_to_cart.
Make sure that it works
- Open your storefront in a normal browser and accept the consent banner.
- Open the developer tools of the browser. In the Network tab, filter on
pixel.textyess.com. - Open a product page. Make sure that a
product-viewedrequest goes out with the status 200. - If no request goes out, read the console. The script writes its warnings with the prefix
[TextYess].
TextYess refuses requests from automated browsers, such as headless Chrome. They get the status 403, so do this check in a normal browser.
What the script does not do
- It sends no checkout events. The TextYess Shopify pixel sends them from the Shopify checkout.
- It sets one cookie,
_textyess_cid, on the main domain of your store. The checkout pixel uses the same cookie. The script sets it only after the shopper’s consent. - It makes no request to your storefront or to Shopify.