How to install Beacon in Hydrogen Shopify stores
Overview
Sendlane’s Beacon tracking pixel allows you to follow your customers around your website, collecting information on page views, carts, and purchases.
Headless Shopify store users must provide the Beacon script with information about the store and its structure before data can be sent to Sendlane.
Read on to learn how to install and configure Beacon general tracking on your headless Shopify store.
In this guide
- Why do headless stores need to do additional setup to install Beacon?
- Step One: Install Beacon general tracking
- Step Two: Add store identification to Beacon
- Step Three: Implement product view tracking
- Step Four: Implement cart tracking
- Step Five: Test your Beacon installation
🚦 Before Getting Started
- Make sure you have the ability to deploy changes to your Shopify store’s headless frontend
- Read Understanding the Beacon tracking pixel
⚠️ Are you sure you have a Hydogen/headless Shopify store?
This guide is only for users with Hydogen/headless Shopify stores. If you developed a custom frontend for your store, you have a Hydogen/headless Shopify store.
If you use a Shopify theme for your store's frontend, you have a Native/non-headless Shopify store and should not use this guide to install Beacon. See How to install Beacon in Native Shopify Stores for instructions on installing Beacon.
Why do headless stores need to do additional setup to install Beacon general tracking?
The structure of traditional Shopify stores (those using a Shopify theme instead of a custom frontend) includes information about a store’s identification, views on product pages, product variant selection, and cart activity, all of which Beacon needs to provide full general tracking functionality.
Headless stores’ structure can vary widely because they are not beholden to the standardized architecture of Shopify themes. Your unique store website still provides all the information Beacon needs to function, but without the traditional theme structure to guide it, Beacon can’t recognize or find that information.
When you install Beacon on your headless store, you’ll need to grab the general tracking code from Sendlane and add a few additional properties in order to:
- Give Beacon your store’s identifier so it knows which account to send data back to in Sendlane
- Implement product view tracking so Beacon knows where your product pages and pop-up modals are
- Implement cart tracking so Beacon knows where your cart activity happens
Complete the steps below in the order they appear to ensure your Beacon installation is successful.
Step One: Install Beacon general tracking
Grab the Beacon general code from your Sendlane account page:
- Click Account
- Click Beacon
- Click Get Beacon Code
- Click Copy code
You’ll get a snippet like the following, where 1a2b3c4d5e6f
is your account’s general tracking event ID.
<script> window._Sendlane = window._Sendlane || []; </script> <script src="https://sendlane.com/scripts/pusher.js" async></script> <script> _Sendlane.push({ event_id: '1a2b3c4d5e6f' }); </script>
Install this code:
- In your store’s main template or layout file
- Ensure it loads on every page of your store
- Ensure it loads BEFORE any tracking events occur
Step Two: Add store identification to Beacon
Now that you’ve got the Beacon general tracking code where it needs to be, you need to add properties to the script to identify your platform and store name to Beacon.
Add the following lines:
window._Sendlane.platform = 'shopify'; window._Sendlane.shop = 'your-store-name.myshopify.com';
Keep shopify
as shopify
and replace your-store-name
with your Shopify store’s actual domain.
Ensure these properties are set when your store loads before product and/or cart tracking occurs.
Your final Beacon general tracking implementation should look something like this:
<script> window._Sendlane = window._Sendlane || []; </script> <script src="https://sendlane.com/scripts/pusher.js" async></script> <script> _Sendlane.push({ event_id: 'YOUR_EVENT_ID' }); </script> <script> window._Sendlane.platform = 'shopify'; window._Sendlane.shop = 'your-store-name.myshopify.com'; </script>
Step Three: Implement product tracking
To track product and variant views and abandoned views, you’ll need to set product information whenever a website visitor views a product or selects a variant.
Add the following tracking codes wherever products and their variants can be viewed:
- On product page load:
window._Sendlane.product_id = '123456789' // Replace with actual product ID
- When a variant is selected (including quick view modals):
window._Sendlane.variant_id = '987654321' // Replace with actual variant ID
Step Four: Implement cart tracking
To track added to cart and abandoned cart events, update the cartEvents property whenever cart changes occur.
Add this tracking code whenever products are added to or removed from the cart, cart quantities are updated, or cart is cleared:
window._Sendlane.cartEvents = [{ "items": [{ "product_id": "123456789", // Replace with actual product ID "variant_id": "987654321" // Replace with actual variant ID }] }]
⚠️ Ensure proper array structure
The cartEvents
array must follow the format above with a product_id
and variant_id
for each item.
Step Five: Test Beacon installation
Follow each testing procedure outlined below to ensure each piece of your Beacon general tracking implementation was successful.
General tracking:
- Open your store in Chrome
- Right click anywhere
- Click Inspect
- Open the Network tab
- Filter for sendlane
- Refresh the page
- Verify that requests are going to sendlane.com
Product tracking:
- Navigate to a product page
- Open the Console tab
- Type window._Sendlane
- Verify that the product_id is set correctly
- Select a variant
- Verify that the variant_id is set correctly
Cart tracking:
- Add an item to your cart
- Type window._Sendlane.cartEvents in the Console
- Verify that the cart’s data structure matches the example in the previous section