When implementing purchase conversion events, it’s common for a customer to add products originating from different searches (i.e. attributed to different queryIDs). This raises the question: which queryID should you assign to the purchase event?
The answer is, all of them. You can pass all the queryIDs in the objectData
field.
Example Scenario
Consider a cart with three different products:
- Two products added from two different searches
- One product added from a request unrelated to Algolia (eg. from the homepage)
In such cases, where the purchase event needs to track multiple queryIDs because the products added to the cart come from different searches/requests, you can use the objectData
field to pass the relevant queryIDs.
For the example above, objectData
would look like this:
objectData: [
{
queryID: 'queryID-1',
price: 19.99,
discount: 3.99,
quantity: 2
}, // these products were added following a search
{
queryID: 'queryID-2',
price: 59.99,
discount: 10,
quantity: 1
} // this product was added following a different search
{
price: 19.99,
discount: 0,
quantity: 1
} // this product was added from the homepage
],
Note, the objectData
array must be the same length as the objectIDs
array.
You can store the queryIDs by either passing through the data from your add-to-cart events to local/session storage or save the queryIDs as part of your cart object.
You can find more information of keeping track of queryIDs here.