1. Home
  2. Campaign Management
  3. How to use templating for campaign personalisation

How to use templating for campaign personalisation

With templating engine, you can personalize your campaign content. Engine works on data available in user’s profile, user events, session level data available on current page/screen browsed by user and data from user’s current journey(if the campaign belongs to a journey).

Two ways of creating personalized campaigns

Through UI

Campaigns content can be personalized by using the personalization/templating icon available with every input element on the UI as shown below.

pasted image 0

Once you click on the icon a dropdown shows up with all the data available which can be used for templating. For example,

pasted image 0 (1)

In the example above user clicks on First Name from the  dropdown which gets placed as {{user[‘system’][‘first_name’]}} in the Subject input box. This will  help you with all kind of templating unless you want to use conditional or looping constructs. We will talk more about how to use conditional or looping constructs in templating later in the document.

Through Expression

Although it is recommended to use Personalization Icon available on UI for templating but one can directly type in the expression too to create personalized campaigns.

An example of templating user data :  

Hello{{user[‘system’][‘first_name’]}}

A user with a profile attribute first_name = Martin will get the following message:

Hello Martin

Or

An example of templating using event data :

Hello {{user[‘system’][‘first_name’]}}, Here is your latest purchase details done on {{event.custom[‘purchase_done’].custom[‘purchase_date’]}}

The user with a profile attribute first_name = Martin and have done the event purchase_done with attribute purchase_date will get the following message.

Hello Martin, Here is your latest purchase details done on 08/16/2016 04:16:16PM.

In the below sections we will discuss more about the different types of data available for templating, how to write expression manually, how to use conditional and looping constructs and when to use WYSIWYG and RAW mode for templating.

Templating Using User Profile Data

One can use user profile attributes to create personalized campaigns.

For example:

Hello{{user[‘system’][‘first_name’]}}

A user with a profile attribute first_name = Martin will get the following message:

Hello Martin

While writing expressions manually to use user’s profile data for templating one should take care of few things as mentioned below:

Expression:

{{user[‘ATTRIBUTE_CATEGORY‘][‘ATTRIBUTE_NAME‘]}}

 

  • The expression should start with double opening curly braces{{ and ends with double closing curly braces }}. This stands true for any other expression too.
  • user is a reserved keyword and an identifier to use user’s profile data for templating.  
  • Attribute_Category is the name of the category an attribute belongs to. The two possible values are system and custom. If expressions uses values other than these will not be identified as a valid templating expressions and will remain as it is in the final content generated.More about these categories and the attributes available in these categories are explained later in the document.
  • Attribute_Name is the name of the attribute whose value will replace the expression in the final generated content. For example :

Hello{{user[‘system’][‘first_name’]}} will result in Hello Martin for the user with profile attribute first_name = Martin.

Note: Expressions without Attribute_Name will not be identified as templating expressions and will remain as it is in the final content generated e.g.  Hello{{user[‘system’]}}.

Attributes available in user profile to user for templating

The user profile attributes are comprised of two types called  System Attributes and Custom Attributes.

System attributes are the attributes which WebEngage understands and have reserved namespace.

Below are all the system attributes available for templating.

 

Attribute Description
cuid User Id to identify the user uniquely
first_name First Name of the user
last_name Last Name of the user
gender Gender
birth_date Date of Birth
email Email address
phone Phone
company Company name the user works in
county County
region Region
city City

Custom attributes are mostly the business attributes e.g. user’s current_plan which tells about the current plan the user is subscribed to.

Example of using custom attributes in templating:  

Hello {{user[‘system’][‘first_name’]}}, You have successfully upgraded to  {{user[‘custom’][‘current_plan’]}} plan.

A user with a profile attribute first_name = Martin and current_plan = Premium  will get the following message:

Hello Martin, You have successfully upgraded to Premium plan.

Note: As of now, WebEngage only supports attributes with values of type String, Number, Boolean or Date only. Attributes with value as an Array or nested Object  will be supported in future.

Templating Using Events Data

You can create personalised campaigns based on the data available in all the events that a user performs.

For example:

Hello {{user[‘system’][‘first_name’]}}, Here is your latest purchase details done on {{event.custom[‘purchase_done’].custom[‘purchase_date’]}}.  

All the users who have done the event purchase_done with attribute purchase_date will get the following message.

Hello Martin, Here is your latest purchase details done on 08/16/2016 04:16:16PM.
Although using personalization icon pasted image 0 (2)

is the easiest way to use event’s  data for templating  but while writing expressions manually one should take care of few things as mentioned below:

Expression:

{{event.EVENT_CATEGORY[‘EVENT_NAME‘].ATTRIBUTE_CATEGORY[‘ATTRIBUTE_NAME‘]}}

 

  • The expression should start with double opening curly braces{{ and ends with double  closing curly braces }}. This stands true for any other expression too.
  • event is a reserved keywords and an identifier to use events data for templating.  
  • EVENT_CATEGORY is the name of the event category the event belongs to. The two possible values are system and custom. System events are the events which WebEngage tracks implicitly. Here is more about system events. Custom events are the events a business tracks while a user is browsing their website/app using APIs exposed through WebEngage SDKs e.g. tracking a user’s  add_to_cart event with all the cart details.If expressions uses values other than these event category will not be identified as a valid templating expressions and will remain as it is in the final content generated.
  • EVENT_NAME is the the name of the event.
  • Attribute_Category is the name of the category an attribute belongs to. The two possible values are system and custom. If expressions uses values other than these will not be identified as a valid templating expressions and will remain as it is in the final content generated.
  • Attribute_Name is the name of the attribute, value of which will replace the expression in the final generated content. As shown in the example above the expression {{event.custom[purchase_done’].custom[‘purchase_date’]}} gets replaced with 08/16/2016 04:16:16PM.

Note: Expressions without Attribute_Name will not be identified as templating expressions and will remain as it is in the final content generated e.g.  Hello{{user[‘system’]}}.

Attributes available in events data for templating:

The event attributes are comprised of two types called  System Attributes and Custom Attributes.

System attributes are the attributes which WebEngage tracks implicitly with every event like GEO information, OS details, Browser details, Session details etc .  More on all the system attributes available for templating are explained here. An example of using system attributes for templating:

Hello {{user[‘system’][‘first_name’]}},Thanks a lot for taking the survey ‘ {{event.system[‘survey_completed’].system[‘title’]}}’.

A user with  profile attribute first_name = Martin who submits a survey Marketing Automation Preferences Survey running on your website will get the following message:

Hello Martin, Thanks a lot for taking the survey ‘Marketing Automation Preferences Survey’.

Custom attributes are the attributes which a business tracks with the events using APIs exposed through WebEngage SDKs.  For example:

Hello {{user[‘system’][‘first_name’]}}, Your cart still has ‘{{event.custom[‘add_to_cart’].custom[‘cart_item’]}}‘, Make it yours while it’s available!

A user with  profile attribute first_name = Martin who have done an event add_to_cart with attribute cart_item will get the following message.
Your cart still has ‘Kindle Paperwhite 3G, 6″ High Resolution Display (300 ppi) with Built-in Light,…’, Make it yours while it’s available!

Templating Using Page/Screen Data

This allows to use data available on a page or on app screen while the user is browsing your website/app. Read more on how to set contextual data on a screen using  web, android and iOS SDK.

 

Templating using User’s Journey Data

Coming Soon.

Using we_parse in templates

While WebEngage doesn’t track user profile/event attributes with values other than String, Number, Boolean and Date  type but here is a workaround to still pass attributes with value as an Array or nested JSON Object and use them in templating. Pass Arrays or  nested JSON Object as string and use we_parse to parse them back in  Arrays or JSON object and then use them for templating.

For Example:

Hello {{user[‘system’][‘first_name’]}}, Here are your last purchase details :

{% set products_purchased = we_parse(event.custom[‘purchase_done’].custom[‘products_purchased’]) %};

<ul>

{% for product in products_purchased %}

<li>{{product.name}}</li>

{% endfor %}

</ul>

Thanks for the purchase. We hope to see you again soon.

A user  with a profile attribute first_name = Martin  who have recently done purchase_done event will get this message

Hello Martin, Here are your last purchase details :

  • Product A
  • Product B
  • Product C

Thanks for the purchase. We hope to see you again soon.

Using conditional logic in templates

This allows to create personalised campaigns with selectively displaying content based on certain conditions.

For example:

Hello {{user[‘system’][‘first_name’]}}, Visit us to our

{% if user[‘system’][‘location’] %}

{{user[‘system’][‘location’]}}

{% else%} nearest {% endif %} branch for any queries.

A user  with a profile attribute first_name = Martin  and location = Park Avenue will get the following message:

Hello Martin, Visit us to our Park Avenue branch for any queries.

A user  with a profile attribute first_name = Martin  but no  location defined will get the following message:

Hello Martin, Visit us to our nearest branch for any queries.

Using looping constructs in templates

This allows to create personalised campaigns by looping through all the attributes available in user profile/event data instead of typing them one by one using templating expression.

For example if you want to loop through all the custom attributes available in an event:

Hello {{user[‘system’][‘first_name’]}}, The details of your last activity done on  {{event.custom[‘activity_done’].system.[‘event_time’]}}:

{% set activity_details =   event.custom[‘activity_done’].custom%};

{% for key in activity_details%}

{{key}}: {{activity_details[key]}}</br>

{% endfor %}

A user  with a profile attribute first_name = Martin  who have recently done activity_done event will get this message

Hello Martin, The details of your last activity done on 08/16/2016 04:16:16PM are mentioned below :

Name: Search

Page: Product Search Page
Note : It is advisable to use RAW mode over WYSIWYG if you have to use we_parse, conditional or looping constructs in templating. We use Nunjucks as templating language.

 

Was this article helpful?