> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Click and conversion events

> Send click and conversion events from your Salesforce B2C commerce store.

export const SearchQuery = () => <Tooltip tip="The text users enter into a search box. In the Search API, this corresponds to the query parameter. A search query is often used with filters, facets, and other parameters, but these aren't part of the query text itself.">
    search query
  </Tooltip>;

The integration can capture different [events](/doc/guides/sending-events) and enable advanced [search features](/doc/guides/sending-events/concepts/event-types#events-by-features).
Events are sent by the frontend cartridges:

* **SFRA** sites emit events from the `int_algolia_sfra` cartridge.
* **SiteGenesis** sites emit events from the `int_algolia_controllers` cartridge.

Find statistics about these events in the [Algolia dashboard](https://dashboard.algolia.com).

Sending events enables you to use these features:

* [Search analytics](/doc/guides/search-analytics/overview)
* [Revenue analytics](/doc/guides/search-analytics/concepts/metrics#revenue)
* [A/B Testing](/doc/guides/ab-testing/what-is-ab-testing)
* [NeuralSearch](/doc/guides/ai-relevance/neuralsearch/get-started)
* [Algolia Recommend](/doc/guides/algolia-recommend/overview)
* [Personalization](/doc/guides/personalization/classic-personalization/what-is-personalization)
* [Dynamic Re-Ranking](/doc/guides/algolia-ai/re-ranking)
* [Query Categorization](/doc/guides/algolia-ai/query-categorization)

## Default events

By default, Algolia captures every keystroke in the search box to provide detailed [analytics](/doc/guides/search-analytics/overview).
The cartridge can also capture `view`, `click`, and `conversion` events when users add a product to their cart or complete a purchase.

To start capturing events, select **Enable insights events** in the integration's Business Manager module (**Business Manager > Merchant Tools > Algolia > Algolia**).
Event behavior depends on the cartridge you use.

<Info>
  You can also enable basic click and view events on InstantSearch and Autocomplete-powered pages and components such as search results, category landing pages,
  or the search box with an [Algolia dashboard setting](https://dashboard.algolia.com/events/settings).
  However, since this doesn't enable additional conversion events triggered on pages such as the product detail page or the cart,
  you should use the Salesforce B2C cartridge-specific setting on the Business Manager.
</Info>

### SFRA

When enabled, the SFRA cartridge sends the following events:

* [`view`](/doc/libraries/search-insights/viewed-object-ids) and [`click`](/doc/libraries/search-insights/clicked-object-ids-after-search),
  sent from Autocomplete, category pages,
  and the search results page.
* [`addedToCartObjectIDsAfterSearch`](/doc/libraries/search-insights/added-to-cart-object-ids-after-search),
  sent when products are added to the cart.
* [`purchasedObjectIDsAfterSearch`](/doc/libraries/search-insights/purchased-object-ids-after-search),
  sends a `purchase` event, with the relevant purchased product IDs when users reach the order confirmation page.

#### Keep track of users and search queries for conversion events

To provide better insights,
the conversion events sent should ideally contain
a [persistent `userToken`](/doc/guides/sending-events/concepts/usertoken#persistent-user-token) and the ID of the <SearchQuery /> that led to them.
The SFRA cartridge has mechanisms to keep track of those.

##### Query ID

If the cartridge can get the `queryID` of the search that triggered a conversion event, it's sent in the event payload.

* For **add-to-cart** events, there are two options:

  * If the action is performed from the [Quickview](https://developer.salesforce.com/docs/commerce/sfra/guide/sfra-feature-list.html#quickview-capabilities), the `queryID` comes from the underlying InstantSearch instance.
  * If users click a search result, leading to the product page, the cartridge adds a `queryID` to the query string URL and uses it when a user adds the product to their cart.
* Since **purchase** events don't relate to a search, you must store each user's query IDs in their [browser's local storage](/doc/guides/sending-events/guides/queryid#track-the-queryid-in-cookies-or-local-storage) until the order confirmation page. The cartridge will only do this if a user has agreed to it, using [SFRA's system for tracking consent](https://developer.salesforce.com/docs/commerce/sfra/guide/b2c-sfra-consent-tracking.html).

##### User token and authenticated user token

The cartridge uses the SFCC default `dwanonymous_` cookie to [set the `userToken`](/doc/libraries/search-insights/set-user-token) on insights events.
For authenticated users, it also relies on the [session object](https://developer.salesforce.com/docs/commerce/b2c-commerce/guide/b2c-function-reference.html#object-dwsystemsession) to retrieve and [set the `authenticatedUserToken`](/doc/libraries/search-insights/set-authenticated-user-token).

### SiteGenesis

When enabled, the SiteGenesis cartridge sends the following events:

* `view` and `click`, sent from Autocomplete, category pages, and the search results page.
* `addedToCartObjectIDsAfterSearch`, sent when products are added to the cart.

To implement additional events such as **purchase**, refer to the [Insights client documentation](/doc/libraries/search-insights).

### PWA Kit

If your frontend is built with the PWA Kit, implement events with [React InstantSearch](/doc/guides/building-search-ui/events/react).
