You can send events from your back end to the Algolia Insights API, which can be helpful in these cases:
To send events as they occur, consider sending them from your front end.
Provide accurate timestamps for events
If you send historical events or send events in batches,
it’s important to associate each event with an accurate timestamp.
If you don’t provide a timestamp, all events use the current timestamp.
The timestamp is expressed as miliseconds since the Unix epoch (Unix time).
For more information, see the API reference for the timestamp
parameter.
Sending historical data
To accelerate the data collection, you can send events from the last four days to Algolia.
This allows you to use Algolia features like Click and Conversion Analytics, Personalization, and Recommend sooner.
To make fewer API calls, consider sending historical events in batches.
- You can only send historical events to Algolia Insights from the last four days.
- For click and conversion events, the timestamp must be within one hour of the
corresponding search event.
Sending events in batches
If you don’t want to send user events as they occur,
you can send multiple events in batches with the send-events
method of the Insights API client, or the REST API directly.
If you want to send events from a JavaScript back end,
use the search insights library version 2.2.0 or newer,
or the REST API directly.
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
27
28
29
30
31
32
33
| $insights = Algolia\AlgoliaSearch\InsightsClient::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
$response = $insights->sendEvents(array(
array(
'eventType' => 'click',
'eventName' => 'Product Clicked',
'index' => 'products',
'userToken' => 'user-123456',
'objectIDs' => array('9780545139700', '9780439784542'),
'timestamp' => 1654160209291,
'queryID' => '43b15df305339e827f0ac0bdc5ebcaa7'
),
array(
'eventType' => 'view',
'eventName' => 'Product Detail Page Viewed',
'index' => 'products',
'userToken' => 'user-123456',
'objectIDs' => array('9780545139700', '9780439784542'),
'timestamp' => 1654160209291
),
array(
'eventType' => 'conversion',
'eventName' => 'Product Purchased',
'index' => 'products',
'userToken' => 'user-123456',
'objectIDs' => array('9780545139700', '9780439784542'),
'timestamp' => 1654160209291,
'queryID' => '43b15df305339e827f0ac0bdc5ebcaa7'
),
));
|
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
27
28
29
30
31
32
33
34
35
| require 'algoliasearch'
insights = Algolia::Insights.new('YourApplicationID', 'YourSearchOnlyAPIKey')
insights.user('user-123456').send_events(
[
{
eventType: 'click',
eventName: 'Product Clicked',
index: 'products',
userToken: 'user-123456',
timestamp: 1654160209303,
objectIDs: ['9780545139700', '9780439784542'],
queryID: '43b15df305339e827f0ac0bdc5ebcaa7',
positions: [7, 6]
},
{
eventType: 'view',
eventName: 'Product Detail Page Viewed',
index: 'products',
userToken: 'user-123456',
timestamp: 1654160209303,
objectIDs: ['9780545139700', '9780439784542']
},
{
eventType: 'conversion',
eventName: 'Product Purchased',
index: 'products',
userToken: 'user-123456',
timestamp: 1654160209303,
objectIDs: ['9780545139700', '9780439784542'],
queryID: '43b15df305339e827f0ac0bdc5ebcaa7'
}
]
)
|
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
27
28
29
30
31
32
33
34
35
36
37
38
| // This example requires search-insights.js version 2.2.0 or newer
// For older versions of search-insights.js, see the 'REST API' example
const aa = require('search-insights')
aa('init', {
appId: 'YourApplicationID',
apiKey: 'YourSearchOnlyAPIKey'
})
aa('sendEvents', [
{
eventType: 'click',
eventName: 'Product Clicked',
index: 'products',
userToken: 'user-123456',
timestamp: 1654160209282,
objectIDs: ['9780545139700', '9780439784542'],
queryID: '43b15df305339e827f0ac0bdc5ebcaa7',
positions: [7, 6]
},
{
eventType: 'view',
eventName: 'Product Detail Page Viewed',
index: 'products',
userToken: 'user-123456',
objectIDs: ['9780545139700', '9780439784542'],
timestamp: 1654160209282
},
{
eventType: 'conversion',
eventName: 'Product Purchased',
index: 'products',
userToken: 'user-123456',
objectIDs: ['9780545139700', '9780439784542'],
timestamp: 1654160209282,
queryID: '43b15df305339e827f0ac0bdc5ebcaa7'
}
])
|
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
27
28
29
30
31
32
33
34
35
36
37
| from algoliasearch.insights_client import InsightsClient
insights = InsightsClient.create(
"YourApplicationID", "YourSearchOnlyAPIKey",
)
insights.send_events(
[
{
"eventType": "click",
"eventName": "Product Clicked",
"index": "products",
"userToken": "user-123456",
"timestamp": 1654160209299,
"objectIDs": ["9780545139700", "9780439784542"],
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7",
"positions": [7, 6]
},
{
"eventType": "view",
"eventName":"Product Detail Page Viewed",
"index": "products",
"userToken": "user-123456",
"timestamp": 1654160209299,
"objectIDs": ["9780545139700", "9780439784542"]
},
{
"eventType": "conversion",
"eventName": "Product Purchased",
"index": "products",
"userToken": "user-123456",
"timestamp": 1654160209299,
"objectIDs": ["9780545139700", "9780439784542"]
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7"
}
]
)
|
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| let insightsClient = InsightsClient(appID: "YourApplicationID", apiKey: "YourSearchOnlyAPIKey")
let eventClick: InsightsEvent = .click(name: "Product Clicked",
indexName: "products",
userToken: "user-123456",
queryID: "43b15df305339e827f0ac0bdc5ebcaa7",
objectIDsWithPositions: [
("9780545139700", 7),
("9780439784542", 6)
],
timestamp: 1654160209361
)
let eventView: InsightsEvent = .view(name: "Product Detail Page Viewed",
indexName: "products",
userToken: "user-123456",
objectIDs: [
"9780545139700",
"9780439784542"
],
timestamp: 1654160209361
)
let eventConversion: InsightsEvent = .conversion(name: "Product Purchased",
indexName: "products",
userToken: "user-123456",
queryID: "43b15df305339e827f0ac0bdc5ebcaa7",
objectIDs: [
"9780545139700",
"9780439784542"
],
timestamp: 1654160209361
)
let events = [eventClick, eventView, eventConversion]
insightsClient.sendEvents(events) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}
|
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
27
28
29
30
31
32
33
34
35
| var insights = new InsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey"
);
var events = new List<InsightsEvent>(){
new InsightsEvent(
EventType = "click",
UserToken = "user-123456",
EventName = "Product Clicked",
Index = "products",
ObjectIDs = new List<string>{ "9780545139700", "9780439784542" },
Positions = new List<uint> { 17, 19 },
QueryID = "43b15df305339e827f0ac0bdc5ebcaa7",
Timestamp = 1654160209264;
),
new InsightsEvent(
EventType = "view",
UserToken = "user-123456",
EventName = "Product Detail Page Viewed",
Index = "products",
ObjectIDs = new List<string>{ "9780545139700", "9780439784542" },
Timestamp = 1654160209264;
),
new InsightsEvent(
EventType = "conversion",
UserToken = "user-123456",
EventName = "Product Detail Page Viewed",
Index = "products",
ObjectIDs = new List<string>{ "9780545139700", "9780439784542" },
QueryID = "43b15df305339e827f0ac0bdc5ebcaa7",
)
};
insights.sendEventsAsync(events);
|
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
27
28
29
30
31
32
33
34
35
36
37
| InsightsClient insights = DefaultInsightsClient.create(
"YourApplicationID",
"YourSearchOnlyAPIKey"
);
InsightsEvent eventClick =
new InsightsEvent()
.setEventType("click")
.setUserToken("user-123456")
.setEventName("Product Clicked")
.setIndex("products")
.setObjectIDs(Arrays.asList("9780545139700", "9780439784542"))
.setPositions(Arrays.asList(17L,19L))
.setQueryID("43b15df305339e827f0ac0bdc5ebcaa7")
.setTimestamp(1654160209275L);
InsightsEvent eventView =
new InsightsEvent()
.setEventType("view")
.setUserToken("user-123456")
.setEventName("Product Detail Page Viewed")
.setIndex("products")
.setObjectIDs(Arrays.asList("9780545139700", "9780439784542"))
.setTimestamp(1654160209275L);
InsightsEvent eventConversion =
new InsightsEvent()
.setEventType("conversion")
.setUserToken("user-123456")
.setEventName("Product Purchased")
.setIndex("products")
.setObjectIDs(Arrays.asList("9780545139700", "9780439784542"))
.setQueryID("43b15df305339e827f0ac0bdc5ebcaa7");
List<InsightsEvent> events = Arrays.asList(eventClick, eventView, eventConversion);
insights.sendEventsAsync(events);
);
|
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
27
28
29
30
31
32
33
| client := insights.NewClient("YourApplicationID", "YourAPIKey")
events := []insights.Event{
{
EventType: "click",
EventName: "Product Clicked",
Index: "products",
UserToken: "user-123456",
Timestamp: time.Unix(1654160209269, 0),
ObjectIDs: []string{"9780545139700", "9780439784542"},
Positions: []int{7, 6},
QueryID: "43b15df305339e827f0ac0bdc5ebcaa7"
},
{
EventType: "view",
EventName: "Product Detail Page Viewed",
Index: "products",
UserToken: "user-123456",
Timestamp: time.Unix(1654160209269, 0),
ObjectIDs: []string{"9780545139700", "9780439784542"}
},
{
EventType: "conversion",
EventName: "Product Purchased",
Index: "products",
UserToken: "user-123456",
Timestamp: time.Unix(1654160209269, 0),
ObjectIDs: []string{"9780545139700", "9780439784542"},
QueryID: "43b15df305339e827f0ac0bdc5ebcaa7"
},
}
res, err := client.SendEvents(events)
|
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
27
28
29
30
31
32
33
34
35
| client.execute {
val eventClick = InsightsEvent(
eventType = "click",
eventName = "Product Clicked",
index = "products",
userToken = "user-123456",
objectIDs = Some(Seq("9780545139700", "9780439784542")),
positions = Some(Seq(7, 6)),
queryID = Some("43b15df305339e827f0ac0bdc5ebcaa7"),
timestamp = Some(1654160209309L)
)
val eventView = InsightsEvent(
eventType = "view",
eventName = "Product Detail Page Viewed",
index = "products",
userToken = "user-123456",
objectIDs = Some(Seq("9780545139700", "9780439784542")),
timestamp = Some(1654160209309L)
)
val eventConversion = InsightsEvent(
eventType = "click",
eventName = "Product Clicked",
index = "products",
userToken = "user-123456",
objectIDs = Some(Seq("9780545139700", "9780439784542")),
positions = Some(Seq(7, 6)),
queryID = Some("43b15df305339e827f0ac0bdc5ebcaa7"),
timestamp = Some(1654160209309L)
)
send events Seq(eventClick, eventView, eventConversion)
}
}
|
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
27
28
29
30
31
32
33
| val insights = ClientInsights(
applicationID = ApplicationID("YourApplicationID"),
apiKey = APIKey("YourSearchOnlyAPIKey")
)
val eventClick = InsightsEvent.Click(
eventName = EventName("Product Clicked"),
indexName = IndexName("products"),
userToken = UserToken("user-123456"),
timestamp = 1654160209256L,
queryID = QueryID("43b15df305339e827f0ac0bdc5ebcaa7"),
resources = InsightsEvent.Resources.ObjectIDs(listOf(ObjectID("9780545139700"), ObjectID("9780439784542"))),
positions = listOf(7, 6)
)
val eventView = InsightsEvent.View(
eventName = EventName("Product Detail Page Viewed"),
indexName = IndexName("products"),
userToken = UserToken("user-123456"),
timestamp = 1654160209256L,
resources = InsightsEvent.Resources.ObjectIDs(listOf(ObjectID("9780545139700"), ObjectID("9780439784542"))),
)
val eventConversion = InsightsEvent.Conversion(
eventName = EventName("Product Purchased"),
indexName = IndexName("products"),
userToken = UserToken("user-123456"),
timestamp = 1654160209256L,
queryID = QueryID("43b15df305339e827f0ac0bdc5ebcaa7"),
resources = InsightsEvent.Resources.ObjectIDs(listOf(ObjectID("9780545139700"), ObjectID("9780439784542"))),
)
insights.sendEvents(events = listOf(eventClick, eventView, eventConversion))
|
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
27
28
29
30
31
32
33
34
35
36
| curl -X POST \
https://insights.algolia.io/1/events \
-H 'x-algolia-api-key: YourSearchOnlyAPIKey' \
-H 'x-algolia-application-id: YourApplicationID' \
-H 'Content-Type: application/json' \
-d '{
"events": [
{
"eventType": "click",
"eventName": "Product Clicked",
"index": "products",
"userToken": "user-123456",
"timestamp": 1645617796953,
"objectIDs": ["9780545139700", "9780439784542"],
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7",
"positions": [7, 6]
},
{
"eventType": "view",
"eventName":"Product Detail Page Viewed",
"index": "products",
"userToken": "user-123456",
"timestamp": 1645617796953,
"objectIDs": ["9780545139700", "9780439784542"]
},
{
"eventType": "conversion",
"eventName": "Product Purchased",
"index": "products",
"userToken": "user-123456",
"timestamp": 1645617796953,
"objectIDs": ["9780545139700", "9780439784542"],
"queryID": "43b15df305339e827f0ac0bdc5ebcaa7"
}
]
}'
|
Sending events with Algolia’s API clients
You need to install an additional package for JavaScript, iOS, and Android.
For installation instructions, see these dedicated pages:
Initialize the Insights client
1
2
3
4
| $insights = Algolia\AlgoliaSearch\InsightsClient::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
|
1
| insights = Algolia::Insights::Client.create('YourApplicationID', 'YourSearchOnlyAPIKey')
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| const aa = require('search-insights');
// or
import aa from 'search-insights';
aa('init', {
appId: 'YourApplicationID',
apiKey: 'YourSearchOnlyAPIKey',
});
// Since search-insights@2.0.0, cookie is not used for anonymous user token.
// If you wish to continue, you can pass `useCookie: true`.
aa('init', {
appId: 'YourApplicationID',
apiKey: 'YourSearchOnlyAPIKey',
useCookie: true,
})
|
1
2
3
4
| insights = InsightsClient.create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
)
|
1
2
3
4
5
| Insights.register(
appId: "YourApplicationID",
apiKey: "YourSearchOnlyAPIKey",
userToken: "user-123456"
)
|
1
2
3
4
| var insights = new InsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey"
);
|
1
2
3
4
| InsightsClient insights = DefaultInsightsClient.create(
"YourApplicationID",
"YourSearchOnlyAPIKey"
);
|
1
2
3
4
5
| client := insights.NewClient(
"YourApplicationID",
"YourSearchOnlyAPIKey"
)
userClient := client.User("user-123456")
|
1
| val client = new AlgoliaClient("YourApplicationID", "YourSearchOnlyAPIKey")
|
1
2
3
4
| val client = ClientInsights(
applicationID = ApplicationID("YourApplicationID"),
apiKey = APIKey("YourSearchOnlyAPIKey")
)
|
To send events, you need to use an API key with the search
acl
Retrieving the queryID
If you want to send events from your back end, you need the queryID
for events related to Algolia queries.
The queryID
allows you to connect the user event with the search query.
With the queryID
, you can analyze which search queries lead to search results that users often click.
To retrieve the queryID
, perform a search with the clickAnalytics
parameter set to true
.
1
2
3
| $res = $index->search('query', [
'clickAnalytics' => true
]);
|
1
2
3
| results = index.search('query', {
clickAnalytics: true
})
|
1
2
3
4
5
| index.search('query', {
clickAnalytics: true
}).then(({ hits }) => {
console.log(hits);
});
|
1
2
3
4
| res = index.search(
'query',
{'clickAnalytics': True}
)
|
1
2
3
4
5
6
7
8
| let query = Query("query")
.set(\.clickAnalytics, to: true)
index.search(query: query) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}
|
1
2
3
4
5
| index.Search(
new Query("query") {
ClickAnalytics = true
}
);
|
1
2
3
4
| index.search(
new Query("query")
.setClickAnalytics(true)
);
|
1
2
3
4
| index.Search(
"query",
opt.ClickAnalytics(false),
)
|
After setting the clickAnalytics
parameter to true, the queryID
is returned in the API response.
The queryID
is unique for every search.
In a search-as-you-type implementation, every keystroke sends a search request. Consequently each keystroke has its own queryID
.
For accurate Click and Conversion Analytics, always use the latest queryID
with the API clients.
Not all conversion events originate from a search results page where you can access the required parameters,
including the queryID
and the indexName
.
For example, a user could add an item to the shopping cart from a product detail page.
In this case, you need to track the parameters manually.
User interactions related to querying Algolia have a queryID
parameter.
You can send these events when users interact with search results, category pages, or related items from an Algolia index.
Use the appropriate API methods to send events performed after a search:
In the following example, a user searched for an item and clicked on a search result.
The API client sends a click event with the name Product Clicked
.
1
2
3
4
5
6
7
8
9
10
11
12
| $insights = Algolia\AlgoliaSearch\InsightsClient::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
$insights->user("user-123456")->clickedObjectIDsAfterSearch(
'Product Clicked',
'products',
['9780545139700'],
[7],
'cba8245617aeace44'
);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
| require 'algoliasearch'
insights = Algolia::Insights.new(
'YourApplicationID', 'YourSearchOnlyAPIKey'
)
insights.user('user-123456').clicked_object_ids_after_search(
'Product Clicked', # event name
'products', # index name
['9780545139700'], # array of objectIDs
[7], # array of positions
'cba8245617aeace44' # queryID
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| // This requires installing the search-insights separate library:
// https://github.com/algolia/search-insights.js
// https://www.npmjs.com/package/search-insights
const aa = require('search-insights')
aa('init', {
appId: 'YourApplicationID',
apiKey: 'YourSearchOnlyAPIKey'
})
aa('clickedObjectIDsAfterSearch', {
userToken: 'user-123456',
eventName: 'Product Clicked',
index: 'products',
queryID: 'cba8245617aeace44',
objectIDs: ['9780545139700'],
positions: [7],
})
|
1
2
3
4
5
6
7
8
9
10
11
12
13
| from algoliasearch.insights_client import InsightsClient
insights = InsightsClient.create(
"YourApplicationID", "YourSearchOnlyAPIKey",
)
insights.user("user-123456").clicked_object_ids_after_search(
"Product Clicked", # event name
"products", # index name
["9780545139700"], # list of objectIDs
[7], # list of positions
"cba8245617aeace44", # queryID
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
| Insights.register(
appId: "YourApplicationID",
apiKey: "YourSearchOnlyAPIKey",
userToken: "user-123456"
)
Insights.shared?.clickedAfterSearch(
eventName: "Product Clicked",
indexName: "products",
objectIDs: ["9780545139700"],
positions: [7],
queryID: "cba8245617aeace44"
)
|
1
2
3
4
5
6
7
8
9
10
11
12
| var insights = new InsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey"
).User("user-123456");
insights.ClickedObjectIDsAfterSearch(
"Product Clicked",
"products",
new List<string> { "9780545139700" },
new List<uint> { 7 },
"cba8245617aeace44"
);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
| AsyncUserInsightsClient insights = new AsyncInsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
client
).user("user-123456");
insights.clickedObjectIDsAfterSearch(
"Product Clicked",
"products",
Arrays.asList("9780545139700"),
new ArrayList<>(Arrays.asList(7l)),
"cba8245617aeace44"
);
|
1
2
3
4
5
6
7
8
9
10
11
12
| client := insights.NewClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
).User("user-123456")
res, err := client.ClickedObjectIDsAfterSearch(
"Product Clicked",
"products",
[]string{"9780545139700"},
[]int{7},
"cba8245617aeace44",
)
|
1
2
3
4
5
6
7
8
9
10
| client.execute {
send event ClickedObjectIDsAfterSearch(
"user-123456",
"Product Clicked",
"products",
Seq("9780545139700"),
Seq(7),
"cba8245617aeace44"
)
}
|
1
2
3
4
5
6
7
8
9
| val userToken = UserToken("user-123456")
clientInsights.User(userToken).clickedObjectIDsAfterSearch(
indexName = IndexName("products"),
eventName = EventName("Product Clicked"),
objectIDs = listOf(ObjectID("9780545139700")),
positions = listOf(7),
queryID = QueryID("cba8245617aeace44")
)
|
You need to enter the following parameters:
-
userToken
:
a unique identifier for the user, for example, user-123456
.
-
eventname
:
the name of the event, for example, Product Clicked
.
-
indexname
:
the Algolia index from where the clicked search results are from, for example, products
.
-
objectids
:
a list with IDs that identify the clicked results, for example, [9780545139700]
.
-
positions
:
a list with the clicked results’ positions in the search results, for example, [7]
.
-
queryid
:
an identifier for the last search request.
For more information, see Retrieving the queryID.
In the following example, a user added two products to their wishlist.
The API client sends a conversion event with the name Product Wishlisted
.
1
2
3
4
5
6
7
8
9
10
11
| $insights = Algolia\AlgoliaSearch\InsightsClient::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
$insights->user("user-123456")->convertedObjectIDsAfterSearch(
'Product Wishlisted',
'products',
['9780545139700', '9780439785969'],
'cba8245617aeace44'
);
|
1
2
3
4
5
6
7
8
9
10
11
12
| require 'algoliasearch'
insights = Algolia::Insights.new(
'YourApplicationID', 'YourSearchOnlyAPIKey'
)
insights.user('user-123456').converted_object_ids_after_search(
'Product Wishlisted', # event name
'products', # index name
['9780545139700', '9780439785969'], # array of objectIDs
'cba8245617aeace44' # queryID
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| // This requires installing the search-insights separate library
// https://github.com/algolia/search-insights.js
// https://www.npmjs.com/package/search-insights
const aa = require('search-insights')
aa('init', {
appId: 'YourApplicationID',
apiKey: 'YourSearchOnlyAPIKey'
})
aa('convertedObjectIDsAfterSearch', {
userToken: 'user-123456',
index: 'products',
eventName: 'Product Wishlisted',
queryID: 'cba8245617aeace44',
objectIDs: ['9780545139700', '9780439785969']
})
|
1
2
3
4
5
6
7
8
9
10
11
12
| from algoliasearch.insights_client import InsightsClient
insights = InsightsClient.create(
"YourApplicationID", "YourSearchOnlyAPIKey",
)
insights.user("user-123456").converted_object_ids_after_search(
"Product Wishlisted", # event name
"products", # index name
["9780545139700", "9780439785969"], # list of objectIDs
"cba8245617aeace44", # queryID
)
|
1
2
3
4
5
6
7
8
9
10
11
12
| Insights.register(
appId: "YourApplicationID",
apiKey: "YourSearchOnlyAPIKey",
userToken: "user-123456"
)
Insights.shared?.convertedAfterSearch(
eventName: "Product Wishlisted",
indexName: "products",
objectIDs: ["9780545139700", "9780439785969"],
queryID: "cba8245617aeace44"
)
|
1
2
3
4
5
6
7
8
9
10
11
| var insights = new InsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey"
).User("user-123456");
insights.ConvertedObjectIDsAfterSearch(
"Product Wishlisted",
"products",
new List<string> { "9780545139700", "9780439785969" },
"cba8245617aeace44"
);
|
1
2
3
4
5
6
7
8
9
10
11
12
| AsyncUserInsightsClient insights = new AsyncInsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
client
).user("user-123456");
insights.convertedObjectIDsAfterSearch(
"Product Wishlisted",
"products",
Arrays.asList("9780545139700", "9780439785969"),
"cba8245617aeace44"
);
|
1
2
3
4
5
6
7
8
9
10
11
| client := insights.NewClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
).User("user-123456")
res, err := client.ConvertedObjectIDsAfterSearch(
"Product Wishlisted",
"products",
[]string{"9780545139700", "9780439785969"},
"cba8245617aeace44",
)
|
1
2
3
4
5
6
7
8
9
| client.execute {
send event ConvertedObjectIDsAfterSearch(
"user-123456",
"Product Wishlisted",
"products",
Seq("9780545139700", "9780439785969"),
"cba8245617aeace44"
)
}
|
1
2
3
4
5
6
7
8
| val userToken = UserToken("user-123456")
clientInsights.User(userToken).clickedObjectIDsAfterSearch(
indexName = IndexName("products"),
eventName = EventName("Product Wishlisted"),
objectIDs = listOf(ObjectID("9780545139700"), ObjectID("9780439785969")),
queryID = QueryID("cba8245617aeace44")
)
|
You don’t need to provide the positions
parameter for conversion events.
Otherwise, provide the same parameters as for click events.
You can send user events that aren’t directly connected to querying an Algolia index.
These events can be used to enable Algolia’s Personalization and Recommend features. For example, if users browse a category page, you can send a Filter Viewed
event.
Events that aren’t connected to querying an Algolia index don’t have a queryID
parameter.
You should send these events to Algolia Insights, even if you don’t plan on using Personalization or Recommend right away.
You can send these events unrelated to Algolia queries:
The events viewedFilters
and clickedFilters
require a filters
parameter instead of the objectIDs
parameter.
Send view events
In the following example, a user viewed a category page corresponding to the filter category:best-sellers
.
A Category Page Viewed
event is sent.
1
2
3
4
5
6
7
8
9
10
| $insights = Algolia\AlgoliaSearch\InsightsClient::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
$insights->user("user-123456")->viewedFilters(
'Category Page Viewed',
'products',
['category:best-sellers']
);
|
1
2
3
4
5
6
7
8
9
10
11
| require 'algoliasearch'
insights = Algolia::Insights.new(
'YourApplicationID', 'YourSearchOnlyAPIKey'
)
insights.user('user-123456').viewed_filters(
'Category Page Viewed', # event name
'products', # index name
['category:best-sellers'] # array of applied filters
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| // This requires installing the search-insights separate library
// https://github.com/algolia/search-insights.js
// https://www.npmjs.com/package/search-insights
const aa = require('search-insights')
aa('init', {
appId: 'YourApplicationID',
apiKey: 'YourSearchOnlyAPIKey'
})
aa('viewedFilters', {
userToken: 'user-123456',
index: 'products',
eventName: 'Category Page Viewed',
filters: [ 'category:best-sellers' ]
})
|
1
2
3
4
5
6
7
8
9
10
11
| from algoliasearch.insights_client import InsightsClient
insights = InsightsClient(
"YourApplicationID", "YourSearchOnlyAPIKey",
)
insights.user('user-123456').viewed_filters(
"Category Page Viewed", # event name
"products", # index name
["category:best-sellers"], # list of applied filters
)
|
1
2
3
4
5
6
7
8
9
10
11
| Insights.register(
appId: "YourApplicationID",
apiKey: "YourSearchOnlyAPIKey",
userToken: "user-123456"
)
Insights.shared?.viewed(
eventName: "Category Page Viewed",
indexName: "products",
filters: ["category:best-sellers"]
)
|
1
2
3
4
5
6
7
8
9
10
| var insights = new InsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey"
).User("user-123456");
insights.ViewedFilters(
"Category Page Viewed",
"products",
new List<string> { "category:best-sellers" }
);
|
1
2
3
4
5
6
7
8
9
10
11
| AsyncUserInsightsClient insights = new AsyncInsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
client
).user("user-123456");
insights.viewedFilters(
"Category Page Viewed",
"products",
Arrays.asList("category:best-sellers")
);
|
1
2
3
4
5
6
7
8
9
10
| client := insights.NewClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
).User("user-123456")
res, err := client.ViewedFilters(
"Category Page Viewed",
"products",
[]string{"category:best-sellers"},
)
|
1
2
3
4
5
6
7
8
| client.execute {
send event ViewedFilters(
"user-123456",
"Category Page Viewed",
"products",
Seq("category:best-sellers)
)
}
|
1
2
3
4
5
6
7
| val userToken = UserToken("user-123456")
clientInsights.User(userToken).viewedFilters(
indexName = IndexName("products"),
eventName = EventName("Category Page Viewed"),
filters = listOf(Filter.Facet(Attribute("category"), "best-sellers"))
)
|
In the following example, a user clicked on a product without searching for it, for example, on a product detail page.
A Product Clicked
event is sent.
1
2
3
4
5
6
7
8
9
10
| $insights = Algolia\AlgoliaSearch\InsightsClient::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
$insights->user("user-123456")->clickedObjectIDs(
'Product Clicked',
'products',
['9780545139700']
);
|
1
2
3
4
5
6
7
8
9
10
11
| require 'algoliasearch'
insights = Algolia::Insights.new(
'YourApplicationID', 'YourSearchOnlyAPIKey'
)
insights.user('user-123456').clicked_object_ids(
'Product Clicked', # event name
'products', # index name
['9780545139700'] # array of objectIDs
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| // This requires installing the search-insights separate library:
// https://github.com/algolia/search-insights.js
// https://www.npmjs.com/package/search-insights
const aa = require('search-insights')
aa('init', {
appId: 'YourApplicationID',
apiKey: 'YourSearchOnlyAPIKey'
})
aa('clickedObjectIDs', {
userToken: 'user-123456',
index: 'products',
eventName: 'Product Clicked',
objectIDs: ['9780545139700'],
})
|
1
2
3
4
5
6
7
8
9
10
11
| from algoliasearch.insights_client import InsightsClient
insights = InsightsClient.create(
"YourApplicationID", "YourSearchOnlyAPIKey",
)
insights.user("user-123456").clicked_object_ids(
"Product Clicked", # event name
"products", # index name
["9780545139700"], # list of objectIDs
)
|
1
2
3
4
5
6
7
8
9
10
11
| Insights.register(
appId: "YourApplicationID",
apiKey: "YourSearchOnlyAPIKey",
userToken: "user-123456"
)
Insights.shared?.clicked(
eventName: "Product Clicked",
indexName: "products",
objectIDs: ["9780545139700"]
)
|
1
2
3
4
5
6
7
8
9
10
| var insights = new InsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey"
).User("user-123456");
insights.ClickedObjectIDs(
"Product Clicked",
"products",
new List<string> { "9780545139700" }
);
|
1
2
3
4
5
6
7
8
9
10
11
| AsyncUserInsightsClient insights = new AsyncInsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
client
).user("user-123456");
insights.clickedObjectIDs(
"Product Clicked",
"products",
Arrays.asList("9780545139700")
);
|
1
2
3
4
5
6
7
8
9
10
| client := insights.NewClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
).User("user-123456")
res, err := client.ClickedObjectIDs(
"Product Clicked",
"products",
[]string{"9780545139700"},
)
|
1
2
3
4
5
6
7
8
| client.execute {
send event ClickedObjectIDs(
"user-123456",
"Product Clicked",
"products",
Seq("9780545139700")
)
}
|
1
2
3
4
5
6
7
| val userToken = UserToken("user-123456")
clientInsights.User(userToken).clickedObjectIDs(
indexName = IndexName("products"),
eventName = EventName("Product Clicked"),
objectIDs = listOf(ObjectID("9780545139700"))
)
|
In the following example, a user purchased a product without performing a search first.
A conversion event Product Purchased
is sent.
1
2
3
4
5
6
7
8
9
10
| $insights = Algolia\AlgoliaSearch\InsightsClient::create(
'YourApplicationID',
'YourSearchOnlyAPIKey'
);
$insights->user("user-123456")->convertedObjectIDs(
'Product Purchased',
'products',
['9780545139700']
);
|
1
2
3
4
5
6
7
8
9
10
11
| require 'algoliasearch'
insights = Algolia::Insights.new(
'YourApplicationID', 'YourSearchOnlyAPIKey'
)
insights.user('user-123456').converted_object_ids(
'Product Purchased', # event name
'products', # index name
['9780545139700'] # array of objectIDs
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| // This requires installing the search-insights separate library:
// https://github.com/algolia/search-insights.js
// https://www.npmjs.com/package/search-insights
const aa = require('search-insights')
aa('init', {
appId: 'YourApplicationID',
apiKey: 'YourSearchOnlyAPIKey'
})
aa('convertedObjectIDs', {
userToken: 'user-123456',
index: 'products',
eventName: 'Product Purchased',
objectIDs: ['9780545139700'],
})
|
1
2
3
4
5
6
7
8
9
10
11
| from algoliasearch.insights_client import InsightsClient
insights = InsightsClient.create(
"YourApplicationID", "YourSearchOnlyAPIKey",
)
insights.user("user-123456").converted_object_ids(
"Product Purchased", # event name
"products", # index name
["9780545139700"] # list of objectIDs
)
|
1
2
3
4
5
6
7
8
9
10
11
| Insights.register(
appId: "YourApplicationID",
apiKey: "YourSearchOnlyAPIKey",
userToken: "user-123456"
)
Insights.shared?.converted(
eventName: "Product Purchased",
indexName: "products",
objectIDs: ["9780545139700"]
)
|
1
2
3
4
5
6
7
8
9
10
| var insights = new InsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey"
).User("user-123456");
insights.ConvertedObjectIDs(
"Product Purchased",
"products",
new List<string> { "9780545139700" }
);
|
1
2
3
4
5
6
7
8
9
10
11
| AsyncUserInsightsClient insights = new AsyncInsightsClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
client
).user("user-123456");
insights.convertedObjectIDs(
"Product Purchased",
"products",
Arrays.asList("9780545139700")
);
|
1
2
3
4
5
6
7
8
9
10
| client := insights.NewClient(
"YourApplicationID",
"YourSearchOnlyAPIKey",
).User("user-123456")
res, err := client.ConvertedObjectIDs(
"Product Purchased",
"products",
[]string{"9780545139700"},
)
|
1
2
3
4
5
6
7
8
| client.execute {
send event ConvertedObjectIDs(
"user-123456",
"Product Purchased",
"products",
Seq("9780545139700")
)
}
|
1
2
3
4
5
6
7
| val userToken = UserToken("user-123456")
clientInsights.User(userToken).convertedObjectIDs(
indexName = IndexName("products"),
eventName = EventName("Product Purchased"),
objectIDs = listOf(ObjectID("9780545139700"))
)
|