Skip to content
English
  • There are no suggestions because the search field is empty.

How to identify users on Shopify

Identify Users on Shopify Stores

Learn how to automatically identify customers on your Shopify store when they log in, complete a purchase, or subscribe to your newsletter.

What this enables: When a visitor becomes a customer (logs in, purchases, or subscribes), Lytical will link their anonymous browsing history to their real identity. You'll see their name and email in the Identified Users report, and can track them across multiple devices and sessions.

Prerequisites

  • Lytical tracking code installed on your Shopify store
  • Access to your Shopify theme files (Online Store → Themes → Edit code)

Choose Your Integration Points

Shopify customers can be identified at several points. We recommend implementing all that apply to your store:

Integration Point When It Fires Scope
Logged-in Customers Every page load when customer is logged in Site-wide
Order Confirmation After checkout completion Thank you page
Newsletter Signup When visitor subscribes to email list Site-wide
Account Registration When visitor creates an account Registration page

Method 1: Logged-in Customers (Recommended)

This identifies customers whenever they're logged in to their account. Add this to your theme's theme.liquid file, just before the closing </body> tag.

Why this is recommended: Catches returning customers automatically on every page load. Works even if they didn't purchase in this session.

{% if customer %}
<script>
if (typeof lyt !== 'undefined') {
lyt.identify('{{ customer.email | escape }}', {
email: '{{ customer.email | escape }}',
name: '{{ customer.name | escape }}',
phone: '{{ customer.phone | escape }}',
shopify_customer_id: '{{ customer.id }}',
orders_count: {{ customer.orders_count | default: 0 }},
total_spent: '{{ customer.total_spent | money_without_currency }}',
source: 'shopify_account'
});
}
</script>
{% endif %}

Where to add this code

  1. Go to Online Store → Themes → Edit code
  2. Open Layout → theme.liquid
  3. Find the closing </body> tag
  4. Paste the code just before it
  5. Click Save

Method 2: Order Confirmation

This identifies customers when they complete a purchase, even if they checked out as a guest. Add this to your Order status page scripts in Shopify settings.

<script>
if (typeof lyt !== 'undefined') {
lyt.identify('{{ order.email | escape }}', {
email: '{{ order.email | escape }}',
name: '{{ order.billing_address.first_name | escape }} {{ order.billing_address.last_name | escape }}',
phone: '{{ order.billing_address.phone | escape }}',
city: '{{ order.billing_address.city | escape }}',
country: '{{ order.billing_address.country | escape }}',
shopify_order_id: '{{ order.id }}',
order_number: '{{ order.order_number }}',
order_total: '{{ order.total_price | money_without_currency }}',
source: 'shopify_purchase'
});
}
</script>

Where to add this code

  1. Go to Settings → Checkout
  2. Scroll down to Order status page → Additional scripts
  3. Paste the code in the text area
  4. Click Save

Tip: This script runs on the "Thank you" page after checkout. It captures guest checkouts too — customers don't need an account to be identified.

Why Order Confirmation and not Add to Cart or Checkout Started?

Add to Cart: We don't have the customer's email yet — they're still anonymous.

Checkout Started: Shopify checkout is hosted on checkout.shopify.com (a different domain). Shopify does not allow custom JavaScript anywhere in the checkout flow — the Order Status page is the only exception.

Accelerated Checkouts: Shop Pay, PayPal, Apple Pay, Google Pay, and Amazon Pay are even more restrictive — customers complete payment on third-party domains like shop.app where we have zero access.

The Order Confirmation page is the only guaranteed touchpoint where the customer is back on your domain, the purchase is complete, we have their email, and we can run scripts.

Good news: If the customer is logged in, Method 1 identifies them on every page — including when they add to cart. Only guest checkouts wait until order confirmation.

Method 3: Newsletter Signup

This identifies visitors when they subscribe to your newsletter or email list. Add this to your theme.liquid file, before the closing </body> tag.

<script>
document.addEventListener('submit', function(e) {
var form = e.target;

// Check if it's a Shopify newsletter form
if (form.action && form.action.includes('/contact#contact_form') &&
form.querySelector('input[name="contact[tags]"][value*="newsletter"]')) {

var email = form.querySelector('input[type="email"]');
if (email && email.value && typeof lyt !== 'undefined') {
lyt.identify(email.value, {
email: email.value,
source: 'shopify_newsletter'
});
}
}

// Alternative: Check for common newsletter form classes
if (form.classList.contains('newsletter-form') ||
form.classList.contains('klaviyo-form') ||
form.id === 'newsletter-form') {

var emailInput = form.querySelector('input[type="email"]');
if (emailInput && emailInput.value && typeof lyt !== 'undefined') {
lyt.identify(emailInput.value, {
email: emailInput.value,
source: 'shopify_newsletter'
});
}
}
});
</script>

Note: Newsletter form markup varies by theme. You may need to adjust the selectors (.newsletter-form, etc.) to match your theme's form classes. Inspect your newsletter form in browser DevTools to find the correct selector.

Method 4: Account Registration

This identifies visitors when they create a new account. Add this to your theme's customers/register.liquid template or your theme.liquid file.

<script>
document.addEventListener('submit', function(e) {
var form = e.target;

// Check if it's a Shopify registration form
if (form.action && form.action.includes('/account')) {
var email = form.querySelector('input[type="email"], input[name="customer[email]"]');
var firstName = form.querySelector('input[name="customer[first_name]"]');
var lastName = form.querySelector('input[name="customer[last_name]"]');

if (email && email.value && typeof lyt !== 'undefined') {
var name = '';
if (firstName && firstName.value) name += firstName.value;
if (lastName && lastName.value) name += ' ' + lastName.value;

lyt.identify(email.value, {
email: email.value,
name: name.trim(),
source: 'shopify_registration'
});
}
}
});
</script>

Complete Implementation

For the best coverage, combine Methods 1, 2, and 3 (or 4). Here's a complete snippet you can add to your theme.liquid file:

{% comment %} Lytical: Identify logged-in customers {% endcomment %}
{% if customer %}
<script>
if (typeof lyt !== 'undefined') {
lyt.identify('{{ customer.email | escape }}', {
email: '{{ customer.email | escape }}',
name: '{{ customer.name | escape }}',
phone: '{{ customer.phone | escape }}',
shopify_customer_id: '{{ customer.id }}',
orders_count: {{ customer.orders_count | default: 0 }},
total_spent: '{{ customer.total_spent | money_without_currency }}',
source: 'shopify_account'
});
}
</script>
{% endif %}

{% comment %} Lytical: Identify newsletter signups and registrations {% endcomment %}
<script>
document.addEventListener('submit', function(e) {
var form = e.target;
if (!form.action) return;

var email, name, source;

// Newsletter forms
if (form.action.includes('/contact') ||
form.classList.contains('newsletter-form') ||
form.classList.contains('klaviyo-form')) {
var emailInput = form.querySelector('input[type="email"]');
if (emailInput && emailInput.value) {
email = emailInput.value;
source = 'shopify_newsletter';
}
}

// Registration forms
if (form.action.includes('/account')) {
var emailInput = form.querySelector('input[type="email"], input[name="customer[email]"]');
var firstName = form.querySelector('input[name="customer[first_name]"]');
var lastName = form.querySelector('input[name="customer[last_name]"]');

if (emailInput && emailInput.value) {
email = emailInput.value;
source = 'shopify_registration';
if (firstName || lastName) {
name = [(firstName && firstName.value) || '', (lastName && lastName.value) || '']
.filter(Boolean).join(' ');
}
}
}

// Send identify call
if (email && typeof lyt !== 'undefined') {
var traits = { email: email, source: source };
if (name) traits.name = name;
lyt.identify(email, traits);
}
});
</script>

Captured Fields

Depending on the integration point, these fields are captured:

Field Source Storage
email All methods Identity email + identifier
name Account, Order, Registration Identity name
phone Account, Order Identity phone
shopify_customer_id Account Custom property
orders_count Account Custom property
total_spent Account Custom property
order_total Order Custom property
source All methods Custom property

Viewing Identified Users

Once customers are identified, you can view them in Lytical:

  1. Go to Analytics in the left sidebar
  2. Click Identified Users under the Data section
  3. You'll see a list of all identified customers with their email, devices, sessions, and pageviews
  4. Click on any customer to see their profile, Shopify data (orders count, total spent), and complete browsing history

Third-Party Apps

Klaviyo Forms

If you're using Klaviyo for email popups and forms, add this script to your theme.liquid:

<script>
// Listen for Klaviyo form submissions
window.addEventListener('klaviyoForms', function(e) {
if (e.detail.type === 'submit') {
var email = e.detail.metaData.$email;
if (email && typeof lyt !== 'undefined') {
lyt.identify(email, {
email: email,
name: e.detail.metaData.$first_name || '',
source: 'klaviyo_form'
});
}
}
});
</script>

Privy, Justuno, or Other Popup Tools

Most popup tools fire JavaScript events when forms are submitted. Check your tool's documentation for the event name, then follow a similar pattern to the Klaviyo example above.

Troubleshooting

Customers aren't appearing in Identified Users

  • Verify the Lytical tracking code loads before the identify script
  • Check browser DevTools → Console for JavaScript errors
  • Make sure the Liquid variables are outputting data (check page source)
  • For order confirmation, verify the script is in Settings → Checkout → Additional scripts

Testing the integration

  1. Log in to a test customer account on your store
  2. Browse a few pages
  3. Wait 1-2 minutes, then check the Identified Users page in Lytical
  4. You should see your test customer with their browsing history attached

Newsletter form not detected

Newsletter forms vary widely between themes. Inspect your form element in browser DevTools to find its class name or ID, then update the selectors in the script. Look for form.classList.contains('your-class') or form.id === 'your-id'.

Need help? If you're having trouble with the integration, reach out to our support team and we'll help you get it set up.