How to connect Klaviyo with Shopify metafields

Learn how to sync data from Shopify customer metafields to Klaviyo with this quick code solution and use it to drive targeted email campaigns
Froonze
December 22, 2023

By now, you are probably already familiar with one of Shopify's most powerful new features: customer metafields. This tool lets you gather additional customer details that you can use to segment your customers and drive targeted email campaigns. For instance, you can create campaigns for customers with specific product preferences, or those within an age range, or with unique needs, or owners of pets of a particular race. The possibilities are limitless once you collect the data.

For this additional information to play a relevant role in your marketing campaigns, you must first make sure the data is properly synced with your Marketing Automation Platform. In this guide we'll explain you how to connect Klaviyo with Shopify metafields, to complement the existing integration that syncs in real time your store's orders, customers, and subscribers.

How to connect Klaviyo with Shopify metafields: Step-by-Step Guide

This code solution will push the data in Shopify metafields to Klaviyo custom properties when the customers access the shop. Hence ideally you can add the code before or at the same time that you start collecting the data. Because collecting data most likely requires the customers to log into the shop, so the data will sync at that moment.

  • Step 1. Install Klaviyo app in your Shopify store
  • Step 2. Go to your Shopify admin and navigate to Online Store > Themes. Find the theme you want to edit and click on Customize. In the ditor, enable Klaviyo's App Embed, named Klaviyo Onsite Javascript
  • Step 3. Navigate again to your Shopify admin and navigate to Online Store > Themes. Find the same theme, click on the Three points icon > Edit code.
  • Step 4. Search for the main layout theme.liquid and open it.
  • Step 5. Locate the closing </body> tag in the right-hand side panel and insert the next script immediately above it. Replace klaviyo_property for the property in Klaviyo you want to sync the data to (it can be a new or an old property), and namespace and key for the namespace and key of the existing customer metafield definition in Shopify. Add as many different properties and metafields as you need.
  • Step 6. Save and it's done. When customers log in the data in the metafields should be now pushed to Klaviyo custom properties.

{%- if customer -%} <script> var _learnq = _learnq || []; _learnq.push([ 'identify', { $email: '{{ customer.email }}', // add Klaviyo properties and Shopify metafields klaviyo_property: '{{ customer.metafields.namespace.key.value }}', klaviyo_property2: '{{ customer.metafields.namespace2.key2.value }}' }, ]); </script> {% endif %}

code theme.liquid Shopify Klaviyo

Is there a no-code solution?

For a no-code solution you would need to resort to third party apps that can both collect customer data and automatically push it to Klaviyo. This is also perhaps a more convenient way for business looking to have more structured workflows, enabling data pushes during specific events like registration or surveys.

If you are not familiar with code or wish to have a more integral solution, you should try our Custom Forms plugin. This plugin allows you to create custom registration and profile forms to collect additional information from your customers. This additional information is already saved in Shopify customer metafields, where you can use it to segment your customers (since Shopify segments admit conditions based on metafields). And it can also be pushed to Klaviyo at the same time that the forms are submitted thanks to the available integration.

Learn more about this plugin here: Custom Forms: collect all data you need from your customers

Froonze Customer Accounts Concierge
Get the app today
Turn the account page into a beautiful portal with
Froonze Customer Accounts Concierge
  • 200+