Estimated time to implement: 15 minutes, difficulty: 2/10
In this example, we’ll demonstrate how to use customer events to track product views form the storefront.
Make sure you’ve followed the instructions on how to install developer tools in order to include our lightweight API for your usage.
When customers view products on your store, they will visit the product template. For most storefronts this will be located at
templates/product.liquid. Find your product template, then add this code to the top of it:
Login as a customer on your storefront, then view a product. Then, navigate to Customer Fields and view your customer in the directory. Inside the “Events” card underneath the customer’s data in the left-hand pane, you should see an event titled “Viewed product” along with the handle and title of the product viewed when you click the event. It should look something like this:
You can hook this event up to anything! With our latest Zapier integration, you can set up a Zap to be triggered whenever a custom event is emitted. Many use-cases await – for example, you could feed all of the
Viewed product events into a chart that depicts the interest of all your products side-by-side.
You’re good to go! Now you can track the products that your customers view, all with 9 lines of code.