Dynamic Variables - Customize your notification by dynamic content
This is in follow up to our post on custom variables targeting which lets you target notifications by any rules or logic defined within your notifications.
Problem:
What if you want to populate the content within your notification by the custom variable present on the page. A common use case that arises is if you know the user's name and in your notification, you want to greet him by that name. How do you do that with Connecto ?
Solution:
To solve this problem, we support Dynamic Variables that can be setup in two easy steps:
1. Send Dynamic Variables and Values to Connecto from the page
If you have read our previous post, this is the same way you define custom variables. So custom variables are nothing but dynamic variables.
var _TConnecto = _TConnecto || {}; _TConnecto.licenseKey = 'YOUR_LICENSE_KEY'; _TConnecto.initConnecto = function() { _TConnecto.addVariable("signedUpForCourseA", "yes"); _TConnecto.addVariable("signedUpInLastWeek", "yes"); }; ...
2. Turn on dynamic content for the notification
Within your Edit Notification -> Edit Visuals -> Advanced Options -> Other Options, you can turn on Dynamic Variable(s) like these
3. Use dynamic variables in Notification Text
- Lets say you start of this boring notification
- You add the following dynamic variables to your page
_TConnecto.initConnecto = function() { _TConnecto.addVariable("name", "Dave"); };
and change your notification content to use the variable name.
And voila, your notification is now personalized.
Not only this you can have variables present in any of the theme variables like 'Target URL', 'Form fields' etc.
How does it work and what all is possible ?
We want to thank the guys at Mustache to make it possible. Essentially you can do everything with your dynamic variables that you can do with Mustache.
Variable Replace: Simple variable replacement by key value pairs. So if you add custom variables like ('k1', 'v1'). Any occurence of {{k1}} in the notification will be replaced by 'v1'.
Conditional text: Render something if a variable is present and something else if not. Say for some users, you don't know the name and the name variable is empty string or not present. You can fallback to 'there'.
- Listing: If you use array custom variables like
_TConnecto.addVariable('message', ['May', 'the', 'force', 'be', 'with', 'you']);
You can use mustache to enlist the elements.
will render to
And thats it folks. Hope you find this blog post useful and you use our dynamic variables feature.