Email with the products most frequently visited by a customer

Published November 20, 2020
Modules
Difficulty

It is worth remembering how important it is to analyze what users view on the website, what subpages they visit and how much time they spend there. Behavioral data is the basis for creating a specific marketing strategy and appropriate personalization.

Remember that even if the users do not add anything to the basket, they can be reminded of the products they most often visited by sending them a personalized email.

Example of use - Electronic industry

A client from the electronics industry decided to make use of information about the products customers viewed. However, instead of sending them the products they viewed recently, they were sent most viewed products in general.

Screenshot presenting personalized email with top products
Email with top products

If the customers were on the site but did not add anything to the cart, after the session ended, they would receive an email with the products they visited more than once - ordered from the most to the least frequently visited.

Prerequisites


To implement this use case, you have to:

Process


To create an email with products most frequently visited, perform the steps in the following order:

  1. Prepare the aggregate.
  2. Prepare the workflow.

Prepare the aggregate


  1. Go to Analytics > Aggregates > Create new
  2. Choose the type of aggregate: Last Multi and size:100.
  3. Choose event page.visit with product:retailer_part_no parameter.
  4. It is important that the aggregate includes ALL occurrences. To do it, check the box - Consider all occurrences of the event parameter.
  5. Save your aggregate.
`Screenshot presenting aggregate with recently viewed product`
The aggregate with recently viewed product

Prepare the workflow


  1. Go to Automation icon Automation > Workflows > New workflow.

  2. Add an Profile Event as a trigger node.

  3. Select the session.end event.

    `Screenshot presenting using trigger`
    Configuration of the Profile Event node
  4. Click Delay to define the duration of delay - after the session ends, the system waits for the time defined in the Delay node before the email is sent.

    `Screenshot presenting delay`
    Configuration of the Delay node
    Note: Remember that event session.end appears 30 minutes after the last user activity on the website.
  5. Add the Generate Event node. It generates an event on the customer’s profile. In this case, the event will contain ID of the most frequently viewed products by a customer.

    1. In the Event name, enter the name, for example topvisited.products.
    2. In the Label field, enter the label that will be shown in the customer’s profile, for example, Top visited products.
    3. In the Body, enter the Jinjava code available below. Replace AGGREGATE_HASH with the hash of the aggregate you in the previous step. As a result you will analyze the products that the user has viewed, sort them in order of the most frequently viewed to the least viewed (products that have been viewed at least two times) and return them to the userโ€™s card in this event.
    `Screenshot presenting sending Profile Event`
    Generate Event
    Note: An event created in this way will return all the products that the user saw at least twice within the time specified in your aggregate. The event with parameter will be returned in the form of the sku listed after the decimal point, e.g.: top: sku1, sku2, sku3.
    CHECK JINJA CODE

        { 
        "top": 
        "{% set skus = [] %} 
        {% set counter = [] %} 
        {% set skusTmp = [] %} 
        {% set skuDict = [] %} 
        {% set sortDict = [] %} 
        {% aggregate AGGREGATE_HASH %} 
        {% for sku in aggregate_result|unique %}{% set k = [] %}{% for tmp in aggregate_result %}{% if sku == tmp %}{% do k.append('+') %}{% endif %}{% endfor %}{% do skuDict.append({'sku':sku,'counter':k|length }) %}{% endfor %}{% endaggregate %}{% for dictItem in skuDict %}{% do counter.append(dictItem.counter)%}{% endfor %}{% set sortCounter = counter|sort() %}{% for count in sortCounter %}{% for dictItem in skuDict %}{% if dictItem.counter == count && dictItem.sku in skusTmp == false %}{% do skusTmp.append(dictItem.sku) %}{% do sortDict.append(dictItem) %}{% endif %}{% endfor %}{% endfor %}{% set top = [] %}{% set len = sortDict|length + 1 %} {% for i in range(len) %}{% set ind = sortDict|length - i %}{% set item = sortDict[ind] %}{% if sortDict[ind].counter > 1 %}{% do top.append(sortDict[ind].sku) %}{% endif %}{% endfor %}{{ top|join(',')|trim }}" 
        } 
       

    `Screenshot presenting effect after implementing jinjava`
    Effect after implementing jinjava
  6. Add Profile Event Filter. This node allows you to wait for the event sent in the previous node. When the event appears on the customer’s profile, it will be possible to refer to its parameters in the next node - here in send.email, you will refer to the “Top” parameter via {{event.params.top}}

    `Screenshot presenting Profile Event Filter`
    Configuration of the Profile Event Filter node
  7. Add the Send Email node. In the message template, we can use {{event.params.top}} which will return the “top” parameter of the last event we sent. For example, sku1, sku2, sku3 which can then be converted into an array using the | split (’,’) function and use in the template structure.

       {% set topProducts = event.params.top %} 
       {% set skus = topProducts|split(',') %} 
       
  8. Save your workflow.

Results:

`Screenshot presenting automation`
Workflow module
Important:

It will result in an array:

skus = [sku1, sku2, sku3] which we can then use to build a template - we can, for example, download items from the product catalog and simply display them in our email or download similiar recommendations for the most viewed item (skus [0])

Note: Based on this workflow, you can also extract the user’s favorite brand (by creating an aggregate that collects the brand parameter transferred in page visits, adding products to the cart or transactions).

Read more


๐Ÿ˜•

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

๐Ÿ˜‰

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

Close modal icon Placeholder alt for modal to satisfy link checker