Segment
On this page
If you already have integrated Segment on your website and are sending events to Segment, you can configure your Segment dashboard to redirect the events to Algolia.
There are two steps to integrate Segment with Algolia:
- Enable the “Algolia” destination on your Segment dashboard.
- Add extra Algolia-related data to events sent to Segment.
The Algolia connector for Segment is in public beta, and handles e-commerce related events. Please reach out to contact@algolia.com if you want to track events that aren’t yet supported.
Supported events
Not all events from Segment are redirected to Algolia.
The following events, complying with Segment E-commerce Events Spec v2, are redirected:
- Product List Viewed
- Product List Filtered
- Product Clicked
- Product Added
- Product Viewed
- Order Completed
Enable “Algolia” destination on your Segment dashboard
On your source, click the “Add Destination” button.
From the destination catalog, search for and add “Algolia”.
Once added to your source, click the settings button with the gear icon.
Copy your Application ID and Search-Only API Key from your Algolia dashboard and paste there.
Add extra Algolia-related data to the Segment events
With Segment integrated, you probably have code that looks something like the following to send events to Segment:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
analytics.track('Product Clicked', {
product_id: '507f1f77bcf86cd799439011',
sku: 'G-32',
category: 'Games',
name: 'Monopoly: 3rd Edition',
brand: 'Hasbro',
variant: '200 pieces',
price: 18.99,
quantity: 1,
coupon: 'MAYDEALS',
position: 3,
url: 'https://www.example.com/product/path',
image_url: 'https://www.example.com/product/path.jpg'
});
Algolia requires some fields that aren’t a part of the regular Segment E-commerce Events Spec v2. Which fields are required depends on which e-commerce event is being sent. The supported events page indicates which fields are required for each event.
Renaming events
If you’re already sending events which names don’t respect the specification, you need to rename them for them to work with Algolia. If you can’t edit your code directly, you can do it in Segment.
In Segment, go to the destination settings and click Rename Events.
There, you can set your current event names on the left column, and the new ones on the right.
Using Algolia Personalization with Segment
If you pass a userId
to Segment (by using analytics.identify()
), you may want to pass the same identifier to Algolia to allow personalized search results. All you need to do is pass the userToken
parameter with your search.
1
2
3
4
5
6
index.search('query', {
userToken: 'user-1',
enablePersonalization: true
}).then(({ hits }) => {
console.log(hits);
})