How to track logged in Shopify users in Klaviyo

By default, the Klaviyo and Shopify integration will record lots of events (Viewed Product, Added to Cart etc..) but only for identified users.

A user gets identified by Klaviyo when

  • They click a link in an email/sms
  • They fill in a Klaviyo signup form
  • The Klaviyo API identifies them

Unfortunately, Klaviyo does not identify and track when a user is logged in to their Shopify account, but with a snippet of code we can easily achieve this.

Track logged in users

Assuming you have already installed the Klaviyo x Shopify integration, you should be able to add the below snippet just before the closing </head> on your site in your theme.liquid file

{%  if %}
     var klaviyo = window.klaviyo || [];
      klaviyo.push(['identify', {        
        '$email': '{{}}'
{% endif %}
Code language: HTML, XML (xml)

This will identify the user to Klaviyo, place a cookie in their browser and allow Klaviyo to track their onsite behaviour (Active on Site, Viewed Product etc..).

Track when users register an account in Shopify

You might also want to track when a user completes the registration form to create an account. To do that we will use a Shopify Flow

You can download this template, and all you need to do is enter your Klaviyo Public Key. Open up the flow and click on the “Track an Event” activity and enter your Klaviyo Public Key

Set the flow live, and once a users account is enabled in Shopify, you will see it creates an event in Klaviyo

Assuming you have added the javascript to track logged in users, then on the next page load, the user will be logged in and this script will automatically let Klaviyo identify, cookie and track the user.