Solved

Best Practices for Displaying User's Last 3 Searches

  • 31 January 2024
  • 2 replies
  • 32 views

Hi there,

I'm currently working on enhancing the user experience for our fashion marketplace and am looking to implement a feature that displays a user’s last 3 searches. I would appreciate any insights or examples on how to effectively set this up within Customer.io.

Specifically, I'm curious about how to efficient ways to track and store the last 3 searches per user.

To give some more context, we capture every search request (e.g. “Nike”, “Adidas”, “Reebok”) and I’d like to, in the people attribute, save that as e.g. “Last search 1: Nike, Last search 2: Adidas etc. However, when there is a 4th search, the 1st one drops off (making it dynamic).

The idea is that we can then display “your last 3 searches” in broadcasts.

I would assume that you would need to update the person with each event that happens but if someone has any idea on the correct liquid to use that would be amazing.

Cheers,

icon

Best answer by ami-jones 1 February 2024, 12:19

View original

2 replies

Hi @aidanb 

I believe the best way to implement this is through Collections. However, if that it is not possible you can do the ff. below:

  1. Capture Search Events: Whenever a user performs a search, you should trigger a custom event in Customer.io.

  2. Update Last 3 Searches Attribute: In the same event, you need to update a custom attribute that keeps track of the last 3 searches. You can use Liquid to manipulate this attribute:

    • {% assign lastSearches = customer.last_searches | default: "" | split: ", " %} {% assign newSearch = "Last search " | append: lastSearches.size | append: ": Nike" %} {% assign lastSearches = lastSearches | push: newSearch | slice: -3, 3 | join: ", " %} {% update_attributes "last_searches": lastSearches %}

      This does the following:

    • Initializes an array lastSearches to store previous searches.
    • Creates a new search string based on the search count.
    • Appends the new search to the array and limits it to the last 3 searches.
    • Updates the custom attribute last_searches with the updated list.
  3. Display Last 3 Searches in Broadcasts: When you send broadcasts, you can use Liquid to display the last 3 searches for each user:

    • Your Last 3 Searches: {{ customer.last_searches | default: "No searches yet." }}

      This Liquid code will display the user's last 3 searches or a default message if there are no searches yet.

  4. Handle Edge Cases: Ensure that your Liquid logic handles cases where there might be fewer than 3 searches or if there are no searches at all.

By implementing this logic, you'll be able to dynamically track and display the last 3 searches for each user in your broadcasts.

Thanks @ami-jones - I'll give that a go!

Reply