Weblayer use cases
Weblayer use cases
Show a weblayer with the last visited product
Use this setup to show a weblayer on your home page featuring the product a customer last viewed.
Requirements
- A product catalog with the following columns:
item_id,picture_url,link_url,price, andavailable. - Event tracking: the
view_itemevent tracked on every product page visit, with anitem_idproperty matching the catalog'sitem_id.
Create an aggregate that returns last(view_item) → item_id. In the personalization panel, find your aggregate and use catalog lookup personalization:
{% set item = catalogs.products.item_by_id(aggregates['0102030405example']) %}- Replace
0102030405examplewith the actual recommendation ID.
To check item availability and render values from the catalog:
{% if item and item.available == "true" %}
{{ item.picture_url }}
{{ item.link_url }}
{{ item.price }}
{% endif %}Show a weblayer on a specific day
To show a weblayer only on a specific day of the week, use either an expression or JavaScript.
Using an expression: Create an expression that evaluates the current day of the week.
(floor((((((now() / 86400) - 4) / 7)) - floor(((((now() / 86400) - 4) / 7)))) * 7)) + 1- The expression divides the current Unix timestamp into weeks, extracts the fractional part to get the position within the week, and scales it to a value between 1 and 7 — where 1 is Monday and 7 is Sunday.
In the Audience settings, add a customer filter where this expression equals the target day. For example, to show the weblayer on Fridays, set the expression to equal 5.
Using JavaScript: Add custom JavaScript to the weblayer to control when it renders. The example below limits display to Sundays:
var today = new Date(Date.now());
var day = today.getDay()
if (day === 0){
//show banner
console.log("Sunday")
} else {
//do not show banner
console.log("Not Sunday")
}Unlike the expression above,
getDay()uses a different numbering convention — 0 is Sunday and 6 is Saturday.
Updated about 2 hours ago
