Menu
 

Advanced: Merging structured data in to an email

Using Customer Attributes with an Array

Imagine you’re a microblogging platform. Each customer has a list of “people like them”. Every email you send, you merge in people like them.

1. Update a customer with a list of people like them

Example in Javascript

_cio.identify({
  id:               "user_123",
  similar_people:   [ "JaimeLannister", "TyrionLannister", "CerseiLannister"]
});

2. Loop Through Your Data

When customer.io has this data, you can loop through in the email using Liquid syntax to display the items. Note: Not all Liquid features are currently available in Customer.io, and Customer.io-specific reference documentation is forthcoming.

In the customer.io email editor

{% for person in customer.similar_people %}
  {{ person }}<br/>
{% endfor %}

That’s it! You might want to pass more data and do things like link to their profile, or have a picture of them.

Event data in transactional emails

Event data is available in transactional emails only

Let’s use a simple example for a user who purchased several items. You want to send a receipt with a list of the items.

Note: When doing this, set your transactional email to “Confirm First”. This will allow you to experiment with the layout and content without having to send out the email each time.

1. Send the list of items

You’ll need to pass an array of items.

Example in Ruby

customerio.track ( user_id, "purchased",
 :items => [
    {:name => "toothpaste", :price => "3"},
    {:name => "dental floss", :price => "2.97"}
  ]
)

2. Loop Through Your Data

When customer.io has this data, you can loop through in the email using Liquid syntax to display the items.

In the customer.io email editor

{% for item in event.items %}
  {{ item.name }} - {{ item.price }} <br/>
{% endfor %}

This will loop through your data and output the items that were passed in with the “purchased” event. Even though the event is named “purchased”, you still use the notation event to reference it in Customer.io