Integrations / Platforms / Magento 2 / Personalization

Personalization strengthens your search: it adds a personal layer to the overall relevance and experience of a user. Taking personal preferences into account can drive conversion by guiding users to your products that they like.

Starting at version 2 and higher, you can configure Personalization from the back office of your Magento store.

This feature is only available if your Algolia plan gives you access to Personalization. Please refer to the pricing page for more details.

How to configure

You can enable and configure several events to track for Personalization by navigating to Stores > Configuration > Algolia Search > Personalization. You can track the following events:

  • View events
    • Viewed product
  • Click events
    • Product clicked
    • Product recommendation click
    • Facet clicked
  • Conversion events
    • Product added to wishlist
    • Product added to cart
    • Placed order

After you have configured the events you want to track and cleared your configuration cache, the events get sent to Algolia automatically.

How it works

We send view and click events automatically from the frontend of your store. Conversion events are sent from the backend using Magento’s default dispatched events.

Personalization requires a userToken for all events you track, and for your search to personalize the results. Our extension automatically handles this token. For first time non-logged in users, we use an anonymous userToken.

When a customer logs into their account, we generate a userToken based on their email and customer ID. We store this token in a cookie named aa-search, which will persist for a year. We only update this cookie when a customer logs in again.

How to track custom Personalization events

You can add custom events for Personalization by leveraging the afterInsightsBindEvents frontend event. This hook exposes the algoliaInsights object, which allows you to append events to the list of pre-configured events.

There are three methods available in the algoliaInsights object that you can use to add a new Personalization event:

  • trackClick
  • trackView
  • trackConversion

Each method requires an object with specific formatting for insights. You can easily create events in the correct format by using the buildEventData method on the algoliaInsights object. To create a personalization event in the correct format, buildEventData requires an eventName, objectID and indexName.

The following code snippet shows how to add a custom click event using the afterInsightsBindEvents hook:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
algolia.registerHook('afterInsightsBindEvents', function(algoliaInsights) {
    
    var selectors = document.querySelectorAll('.class-selector');
    selectors.forEach(function (e) {
        e.addEventListener('click', function (event) {

            // selector in this example has an data-objectid attribute
            // with the objectID as the value
            var objectId = this.dataset.objectid;

            // use the buildEventData function to format event data
            var eventData = algoliaInsights.buildEventData(
                'Clicked Event Name', // eventName
                objectId, // objectID
                algoliaConfig.indexName + '_products' // indexName
            );

            algoliaInsights.trackClick(eventData);

            // Available methods
            // algoliaInsights.tractView(eventData);
            // algoliaInsights.trackConversion(eventData);
        });
    });

});
Did you find this page helpful?