Simple Email Marketing
Home > Have a question? We're here to help. > Account how-to > How to use dynamic content > Dynamic content from custom API events

Dynamic content from custom API events


Access to the Event API is available only to Emma Plus and Enterprise customers.

In addition to personalizing a campaign's content using information stored in contact fields, you can customize automated campaigns based on custom API events. This gives you the ability to send super-targeted emails that can be personalized down to things like a contact’s specific purchase or appointment details. Head here for more information about triggering automated workflows using custom API events

Dynamic content with custom API events works similarly to personalization and the same operators from dynamic content can be used. You can find more info and a list of operators here.
The key difference between personalization based on contact information and personalization based on event attributes shared via the event API is a simple formatting distinction: while contact field personalization tags are prefixed with “member” - for instance, [% member:city %] - personalization based on event attributes (keys) are prefixed with “event”, such as [% event:purchase_amount %]. You must be familiar with the format of the events that you are sending to the event API in order to personalize your content using their key names.

An example:
The following example listens to an event for a “survey completion.”
The name of this survey (shared on the event as “survey_name”) is “Customer Satisfaction Survey,” and the message will be altered slightly based on whether or not a customer has indicated that they are satisfied (a reply of “7” or higher), or somewhat less than satisfied (a reply of “6” or less). Customer replies to this question are shared in the value for the key “overall_satisfaction.”

Thank you for taking our [% event:survey_name %]! [% if event:overall_satisfaction > “6”%] Please don’t ever hesitate to get in touch if there’s something you’d like to see from us! [% elif event:overall_satisfaction < “7” %] We never want you to be anything less than thrilled with our service, and we want to make things right. Please call us at 555.555.5555 if there’s anything at all that we can do to make things better for you. [% endif %]

Dynamic content using items in an order and other nested attributes

Not all data from events shared with the Emma Event API will be neatly paired into top-level key/value pairs. Some event data is nested, meaning that one attribute (such as “line_items” in an order completed from an ecommerce platform) contains multiple related attributes (such as the item ids, names, prices and other related attributes).

Here is an example of the “line_items” data from such an order: 

"line_items": [


        "id": 998327818,

        "variant_id": 59284621,

        "title": “Slim Short Sleeve Linen Shirt”,

        "quantity": 1,

        "price": “68.00",

        "sku": “SLSSLNSHRT”,

        "variant_title": “white”,

        “size”: medium,

        "product_id": 632910392,

        "requires_shipping": true,

        "taxable": true,

        "gift_card": false,

        "name": “Slim Short Sleeve Linen Shirt - White“,


        "tax_lines": [


            "title": "State Tax",

            "price": “6.12”,

            "rate": 0.09



        "id": 789327523,

        "variant_id": 89137513,

        "title": “Slim Mens Chino”,

        "quantity": 1,

        "price": “79.00",

        "sku": “SLMNCHNO”,

        "variant_title": “green”,

        “size”: 32W32L,

        "product_id": 948517351,

        "requires_shipping": true,

        "taxable": true,

        "gift_card": false,

        "name": “Slim Short Sleeve Linen Shirt - White“,


It’s common for marketers to want to use line items from an order and other nested sets of data in the content of their email. This could be used to tell users what they’ve left in their cart, to ask them to leave reviews on items that were purchased in a completed order, etc. This is possible using Emma’s dynamic content feature using an operator known as a for loop. A 'for loop' gives users the ability to look (or “loop”) over the individual attributes contained within a set of similar items (such as “line_items” in the above example), and to insert a piece of content into their email message for every item found within the set. 

An example:
Let’s say that we wanted to insert a piece of content that would include the title, quantity and price of all items that were included within an order. It’s likely that this order contained multiple items, so we want them all to appear within the email, one after the other. Using a 'for loop', we would say that we wanted to search the event data for a specific attribute (“line_items” in this case), and we wanted to identify all nested attributes of that parent attribute as something consistent (we’ll say “item” here). At that point, we can use the attributes of that item to personalize the message. So the snippet below would produce a series of product descriptions (quantity, item title and price).

[% foreach context:event:line_items as item %]
[% context:item:quantity %], [% context:item:title %], [% context:item:price %]
[% endforeach %]

Counting items in a cart and more

In addition to showing all items in an order (or other list), it’s possible to dynamically include the number of items in that list. For example, if you wanted to send an abandoned cart message that told users how many items had been left in their cart, you could do so using the following snippet:

[% length value=[% context:event:line_items %] %]

This gets really interesting if you want to show different messages based on how many items appear in a list. It’s possible that you’d format your message differently based on whether a customer had abandoned one item in their cart or multiple items.
This snippet will display the text “This is a test” if a customer has left more than one item in their cart, for example.

[% if [% length value=[% context:event:line_items %] %] > “1” %] This is a test [% endif %]


Last modified



This page has no classifications.


Emma phone support will be unavailable on November XX, between the hours of XX:XX and XX:XX. You can still contact support using the link above and we will respond as soon as we can.

App status

App status