Search through more than a hundred articles on every aspect of

Dawid Tyburek
Written by Dawid Tyburek

Events - rendering in emails

Add information to your email messages that could be potentially key to your users


This guide is written in a way that is understandable to everyone, including users not familiar with coding or Django framework.

After reading this article, you'll know how to send 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. 

Use cases

  • Let's say you have a Loyalty Scheme 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.

How to put event attributes in email messages

Create a new email message. Here is how:

  • Write the content of your message and leave space for the list of "Event attributes" that you want to provide. 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=100 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 this text, change the variables, and paste it as you would the standard text of the email. Once delivered to the receiver, it will turn into dynamic user data.

Let's go through the lines of this code:

{% events 'event_name' for_last_days=7 count=100 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 100, and there are 120 events in that time, the receiver will only get 100. If you enter 100, and there are only 90 events performed, the receiver will get 90. 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 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.