DEV Community

Tomoya Nakano
Tomoya Nakano

Posted on

Sync Shopify Customer's Metafield to Klaviyo's profile

Hi, I would like to introduce the way to sync Shopify customer Metafield to Klaviyo profile.

What is Metafield

Metafield is additional information you can add to Shopify objects like products and collections.
If you don't familiar with it, please check this article.

What is Klaviyo

Klaviyo is a Marketing Automation Platform that can send emails and SMS to your customers.
You can make segments by custom properties like location or activities(added to cart and so on...) and send emails to them.
if you know more about klaviyo please check this page

What is the advantage of syncing Metafield to Profile

The advantage of syncing Metafield to Profile is that as mentioned, you can make segments by customer's metafield and Implement marketing initiatives to them.
For example In clothes shop, by adding Metafield about customer's height or weight, You cloud send mail magazine personalized for customer's body types.

How to sync

Step1: Integrate Klaviyo App to Shopify store

If you've integrated it already, please follow step2.

First of all, you have to install Klaviyo app to your shopify store. Then, install this app
Once the integration is complete, you should be able to see Klaviyo's App Embed on the Shopify theme customization page.

Please activate it.

Step2: Add Snippet

When the Klaviyo setting is activated, objects named _learnq are available in javascript.
Please check it via console.

You can use Klaviyo Identify API with the object so please add below snippet.

<script>
  var _learnq = _learnq || [];

  {% if customer %}
  _learnq.push([
    'identify',
    {
      $email: '{{ customer.email }}',
      // add Metafield here
      $birthday: '{{ customer.metafields.namespace.birthday.value }}'
    },
  ]);
  {% endif %}
</script>
Enter fullscreen mode Exit fullscreen mode

To learn more about the Klaviyo Identify API, please visit this page.

Step3: Load Snippet

Load the snippet in theme.liquid then customer's Metafields would sync to Klaviyo.

{%- render 'klaviyo-identify' %}
Enter fullscreen mode Exit fullscreen mode

You can find the value of metafield in Klaviyo's profile page.

Profile parameters

Conclusion

You can implelement powerful marketing automation by integrating customer's Metafield with Klaviyo.

If you use Klaviyo for your store's marketing, Please consider using Metafield and integrate it with Klaviyo.

Top comments (2)

Collapse
 
jfxmedia profile image
Jesse Foster

@tomoyanakano

So your article is as close to anything I’ve found on the web about pushing Metafields to Klaviyo, but my case is slightly different, maybe you have advice on if it’s possible.

I need to pass up the products metafields and specifically only one metafield with namespace.key: “product.shipping_timeframe” to the Placed Order event in Klaviyo, and this wouldn’t be on customer but on products right? Since it is a products metafield, would it have to change to product? This would need to show this metafield inside the placed order event. The way I have the code now, I did get the "product.metafields.product.shipping_timeframe" metafield to send up with Viewed Product and Added to Cart, in Klaviyo, but Placed Order is a shopify event I think (has shopify icon in klaviyo vs viewed product and added to cart has Custom Icon).

This is what I have, would you make any changes? Again this is trying to push metafields about a product, to klaviyo, so that I can see the metafield value inside of the Placed Order event from Shopify.

<script>
  var _learnq = _learnq || [];

  _learnq.push([
    'identify',
    {
      $email: '{{ customer.email }}',
      $birthday: '{{ customer.metafields.namespace.birthday.value }}',
      'Shipping Timeframe:' '{{ product.metafields.product.shipping_timeframe }}'
    },
  ]);
</script>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
racedev profile image
Brian Horner - RACE

Obviously this is a way to enrich profiles in Klaviyo, but it requires the user to be logged in and browsing our website before this sync occurs. Is there a way to trigger a mass profile update based on the metafields configured in this snippet without the user browsing our site? (I guess an import of profile properties would do it, but that would need to be stored in a custom field in Klaviyoo I think?)