Quick Use Cases
In this article, you can find use cases that can be implemented within 10 minutes. They have been compiled by our Support which based them on the most commonly asked questions.
Time and day when your customer is most active
Time of a day
Find out at which time of the day are your customers most active.
Firstly, create an expression for the event session_start (we’ll name it hour_for_session_start_expression
):
floor (timestamp/3600)%24
. The timestamp from the session_start is in seconds. When we divide it by 3600 we get hours. With the modulo %24 and the floor function, we get the exact hour.
Secondly, create customer aggregate: most common
> session_start
> hour_for_session_start_expression
.
For each customer, you’ll have an hour, when they are most active on your site!
The initial expression will be calculated in UTC, and to adjust it to your timezone, you should add or subtract the timezone shift. For example, for UTC+1, the expression will be:
floor ((timestamp/3600)+1)%24
.
Day of a week
Find out on which day of a week are your customers most active.
Firstly, create an expression for the event session_start (we’ll name it weekday_for_session_start_expression
):
floor((((timestamp/3600)-72)%168)/24
. The timestamp from the session_start
is in seconds. When we divide it by 3600 we get hours. Then we subtract 72 hours because the Unix timestamp begins on 1. January 1970 which was Thursday and we need the first our to start on Monday. Modulo %168 will give us the current weekday in hours. Finally, the division by 24 with and the floor function will create a range from 0 to 6, where 0 is Sunday, 1 is Monday... and 6 is Saturday.
Secondly, once this expression is done, create customer aggregate: most common
> session_start
> weekday_for_session_start_expression
. Now we know which day of the week is the most popular among our customers!
The initial expression will be calculated in UTC, and to adjust it to your timezone, you should add or subtract the timezone shift. For example, for UTC+1, the expression will be:
floor(((((timestamp/3600)-72)+1)%168)/24)
Appending values from one list to another
Bloomreach Engagement currently doesn’t allow append to list automatically. It only allows replacing the value with some other value. What is possible to do, though, is to replace the whole value with a new list, because jinja personalization allows appending to list in the output. To append to a customer’s attribute, it is needed to send a webhook to Bloomreach Engagement rest API (as set attribute only allows string data type).
There can be another issue, and that is when an on-event scenario is triggered multiple times at the same time for a single customer. The scenario would try to replace the value two times, but in both cases, the list would be incomplete (as both webhooks would use the same original value for the list, and don’t know about the other value). e.g. if customer’s current attribute is [“a”, “b”] and there are two events, one to append “c” and another append “d”, one webhook would send [“a”, “b”, “c”], and the other would send [“a, “b”, “d”], and the latter value received will be stored. To work around this problem, it’s advised to create distinct values aggregate for the event values for the last 1 minute. This would return us to our specific case list of [“c”, “d”]. Once we have this list, we can use {% for %} cycle to append individual values to the list in the jinja in the webhook, and get the resulting list [“a”, “b”, “c”, “d”] as is intended.
Jinja
{% set items = customer.items or [] %}
{% for item in aggregates[‘aggregate_id’] %} {% if item not in items %}
{% append item to items %}
{% endif %}
Updated about 1 year ago