Search through more than a hundred articles on every aspect of User.com

Dawid Tyburek
Written by Dawid Tyburek

Events - rendering in emails

Personalize email messages on the basis of users' actions.


This manual is is suitable for each user category - no matter if you have or not have any coding skills or experience with the Django framework.

The article will show you how to use event attributes in an email. Furthermore, you'll know how to limit the number of attributes sent and limit the time period for which the event will be sent. 

If you are ot familiar with the concept of the event yet, please check this article first.

Use cases

  • Let's say you have a loyalty program and for various actions or purchases you award your customers with Bonus Points. By using Event Snippet Tags you are able to send weekly summary with the amount of Bonus Points accumulated and the last actions that generated the points.

  • Once your customer submits an order/pays for the subscription on the website you want to send an email with the sum up. Here again you can use the details from the latest event occurrence.

There can be many other situations where you might want to print the event attribute details in the email message. The most important is to have a business goal behind it.

Define the event

Choose the event you want to refer to. Open the Tools > Snippet Tags > Event Tags section

There you will find the list of all events with all attributes you currently have in the system. One you pick and event from the list you can configure a snippet tag with the attributes that you want to print.

Remember, that you can remove the unnecessary attributes if you don't need them. The most important is to keep the 1st, 2nd and the last lines of the code.

Put event attributes in email messages

Create a new email message. Write the content of your message and leave space for the list of "Event attributes" depending on your design.

For example, you have an event called "event_name" that has 2 attributes: "number" and "content".

userengage('event.event_name', { number: 1, content: 2 })

Now, take a look at the basic code you need to paste into your email.

{% events 'event_name' for_last_days=7 count=5 order=1 as events %}
{% for event in events %}
  event number is equal to {{event.number}}, event content is equal to {{event.content}} <br>
{% endfor %}

All you will need to do is copy the snippet tag from the Tools > Snippet Tags > Event Tags or copy the code above and change the variables, then paste it like a standard text of the email. Once delivered to the receiver, it will turn into dynamic user data.

As an example, this is what you see in the system:

This is how the user will see the content:

Let's go through the lines of this code:

{% events 'event_name' for_last_days=7 count=5 order=1 as events %}
  • The only thing you need to pay attention to right here is:

  1. 'event_name': where you have the name of your event

  2. The value of for_last_days specifies how many days back the mechanism takes the events from (for example, 7 days: for_last_days=7)

  3. count specifies data for how many events you want to provide. For example, if you enter 5, and there are 7 events in that time, the receiver will only get 5. If you enter 5, and there are only 3 events performed, the receiver will get 3. If you don't specify, the default value will be 10.

  4. order: If you want to get the latest event occurrences first, go with "-1"; if you want the oldest occurrences first, go with "1".

  • The second line does not include any text that you want to change. Basically, it means: Write what is written before the last line of this code as many times as you have events.

{% for event in events %}
  • The third line is the key to what the user will receive. Here, you specify the structure of the text that will be repeated for every event.

event number is equal to {{event.number}}, event content is equal to {{event.content}} 
  • Everything written in double brackets will be treated as the variable. All you need to do is follow this structure: event.INSERT NAME OF THE ATTRIBUTE HERE.

  • Everything else will be text or code. Take a look at the end of this piece. It finishes with <br>, meaning that you'll make a line break at the end of each event code.

  • The last line is also of no interest to us, it marks the end of the loop.

Remember

It is always a good practice to test your email by sending it to yourself just like you would send it to your Users. This way you can check any styling or code mistakes that might have been overlooked in the creation process.

  • Create a new Email Campaign

  • Choose an already created email, prepared to your Users

  • Send it only to yourself or your Team as well to fully know how your message will behave on different email clients.

Categories: