logo

Dynamic Variables,Data Layer, Segment Result – How to customize your notification by dynamic content

This is in follow up to our article 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,Data Layer,Segment Result.

Dynamic Variables

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.you will use that variable in your notification text by writing {{dynamicContentVariables.name}} .


And voila, your notification is now personalized.

Not only this you can have variables present in any of the theme variables like ‘Message’,’Thanks Message’,’Target URL’, ‘Form fields’ etc.


Data Layer

What is Data Layer?

A data layer (which can also referred to as the datalayer or data object) is a set of information that exists on the web page, hidden in the code, invisible to the human eye, but readable if you know where to look. It contains any data that you might need to pass to other systems or software.In simple words it is a user defined javascript variable in his site

1. Send Data Layer to Connecto from the page

Sending data layer is simple as dynamic variables.To send/use a data layer object in your page
have this object.

 
 var dataLayer =[]
 var _TConnecto = _TConnecto || {};
_TConnecto.licenseKey = 'YOUR_LICENSE_KEY';
_TConnecto.dataLayer = window.dataLayer ;
...

(Note:you can took dataLayer variable as array/object according to value of dataLayer using in notification changes)

2. Use Data Layer in Notification Text

To use datalayer in your notification turn on dynamic content like above mentioned in dynamic variables(Turn on Dynamic content)
using data layer is same as the dynamic variables instead of using dynamicContentVariables you use simple write dataLayer in place of dynamicContentVariables.

  • Lets say you start of this boring notification

  • lets say your datalayer is a object
  var datalayer = {name:'Dave'}

and change your notification content to use the name property of datalayer.you will use that name property in your notification text by writing {{dataLayer.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.

In case of datalayer is a array of objects.

 
var dataLayer =[ {name:'Dave',age:23}]; 
...

To change your notification content to using the name property in first object of datalayer array you will just write {{dataLayer.0.name}}.here zero indicates that index of datalayer array

And voila, your notification is now personalized.



Segment Result

Before reading this article you have to known few things

a)To use segment result you must have account in our app.connecto.io user which have account can use these segment result
b)if you have account
i)you need have basic knowledge regarding how to create segment and use it
ii)To better understand of Segment Result you need to follow up our article about target user using segments

Here we discuss the segment result usage article written based you have knowledge on above things

What is Segment Result?

If you have read our previous post about segments in that we are target users using based on users who are qualified segment.for every segment we have eval function it specifies that particular user qualified segment or not.if he qualified segment then eval function of that segment in which he qualified returns a set of events through which he qualified segment but it only returns latest event through which he qualified segment.we store eval function result in segmentResult that variable we call it as Segment Result

To Use segment result in Notification Text

First of all you need add your app.connecto.io account project ID in www.connecto.io account and then open settings->project tab in www.connecto.io

then after you can see segments of your app.connecto.io account in your www.connecto.io

after adding project ID of your app.connecto.io every thing simple like dynamic variables ,data layer.Turn on dynamic content like above mentioned in dynamic variables(Turn on Dynamic content)then after you simple use segmentResult instead of dynamicContentVariables & dataLayer in notification Text

  • Lets say you start with simple lead form notification

add a your target segment with your notification(In this example I am used segment called user seen an model but doesn’t drop lead)

here in my segmentResult I will get visited model_name in events properties. I will use variable in my notification text by writing {{segmentResult.model_name}}

if segment is qualified in your site then notification will render

How does Dynamic variable,Data Layer and Segment Result 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 that’s it folks. above things I did with dynamic variables you can do above all things with Data Layer and Segment Result.Hope you find this blog post useful and you use our dynamic variables , Data Layer and Segment Result feature.

Pro Tip: In case you want to use a dynamic image or HTML in a variable, use {{{ variableName }}} in the admin replacement instead of {{ variableName }}. This is because Mustache escapes characters like /, &, :, <, > and the extra layers of brackets unescapes them.one more thing you can use dynamic variables ,data Layer and segment Result all in one notification

7 found this helpful