Attribution tokens are unique IDs generated by AI Commerce Search and returned with each search request. They enable AI Commerce Search to associate a search request with its matching search event, which allows re-ranking models to improve the quality of search responses. Attribution tokens are also required in AI Commerce Search search events for accurate reporting.

> [!NOTE]
> **Note:** Attribution tokens are only required for AI Commerce Search. They're not passed to all user events. Nor are they passed in the URL.

## How attribution tokens work

You collect the `attributionToken` from the API response of a user's search. There is a
new attribution token for every search; attribution tokens are not repeated.

> [!IMPORTANT]
> **Important:** Attribution tokens are required in search impression events, but they are not to be sent for any other events, such as click, add-to-cart, and purchase.

When AI Commerce Search serves a search or recommendation request, it returns a unique `attributionToken` in its response.

A `placements.search` response should be sent back in a search or browse user event and immediately in the event a user interacts with a product. This includes user journeys such as:

- `search` (YES) → `add-to-cart` (YES)
- `search` (YES) → `detail-page-view` (YES)
- `search` (YES) → `purchase` (NO) (The user isn't directly interacting with a product at the time of purchase in the same way as with a click or `add-to-cart`, though the purchase is still attributed to the original search.)

### Attribution token behavior

Attribution tokens are:

- **Visitor-specific** : The `attributionToken` is associated with a specific search response served to a particular \``visitorId`. Only the search event itself needs to be tagged with the token. All the subsequent non-search events are *not* to be tagged with a token.

- **Associated with events directly following search** : The `attributionToken` is particularly important for user events that represent a direct interaction with the search results of that specific search. This includes **purchase-complete events** : The purchase is still linked through the product IDs and `visitorId`.


  Note: If a single user performs multiple searches, each new search request generates an attribution token, and the subsequent search event should carry that new token. An attribution token from a previous search event is not reused for a subsequent search event, because each search initiates a new token.

### Attribution tokens in the Search API

Each response that the AI Commerce Search method returns includes a unique `attributionToken` at the end of the search response body. For example:

```json
{
  "results": [
    {
      "id": "727121",
      "product": {
...
     }
  ],
  "totalSize": 19600,
  "attributionToken": "dfB0CgwIgKrltAYQ8afX4AIQARokNjZjMGEwYjEtMDAwMC0yNjAyLTk0Y2UtNTgyNDI5Y2JkMzUwKgUxMjM0NTIkxcvzF6OAlyLo5KotmNa3LY6-nRW3t4wtwvCeFdSynRWb1rctOg5kZWZhdWx0X3NlYXJjaGgB",
  "nextPageToken": "AM1MDZiNWOyQjM4UTLlNGN50iMwYjMtADMwATLwIGMhBzY2YDJaIw-bCbxQYAt1PJgIwgExEgC"
...
```

This token **must** be included in the subsequent search event:

```json
{
"eventType": "search",
"searchQuery":"red t-shirt", 
"productDetails":[
  {"product":{"id":"727121"}}, {"product":{"id":  ...
  }
] ,
"visitorId":"GA1.1.1383176924.1721324981",
"attributionToken":"dfB0CgwIgKrltAYQ8afX4AIQARokNjZjMGEwYjEtMDAwMC0yNjAyLTk0Y2UtNTgyNDI5Y2JkMzUwKgUxMjM0NTIkxcvzF6OAlyLo5KotmNa3LY6-nRW3t4wtwvCeFdSynRWb1rctOg5kZWZhdWx0X3NlYXJjaGgB"
}
```

AI Commerce Search uses the event data to train its models. The attribution token provides a way to link the event with the request, encoding the full search request and response with the requested filters, facets, and response product IDs. Without a token present in the search events, those events are treated as if they were not from Google AI Commerce Search and the search events might be incorrectly used as if they were from another search provider.

It's fine (and expected) to have search events without tokens if they are served from another search provider, during an [A/B experiment](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/a-b-testing.md.txt) for example. However, there typically is a 1:1 mapping for search API **requests** to search **events** with tokens.

## Adverse effect of missing tokens

If the `attributionToken` isn't in the relevant subsequent user events from the same visitor, AI Commerce Search treats those events as if they did not originate from its search service.

This can lead to:

- Inaccurate model training.
- Incorrect metrics and performance analysis.
- Potential issues with achieving [higher performance tiers](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/data-quality.md.txt) (like Tier 3) that require sufficient attributable events.
- Errors reported in the [Data quality dashboard](https://console.cloud.google.com/ai/retail/catalogs/default_catalog/data_quality/) in the AI Commerce Search in Gemini Enterprise for Customer Experience if the percentage of events with attribution tokens is less than 95%.

To learn from user behavior and optimize search results, AI Commerce Search requires accurate attribution for the initial search event only.

## Attribution token data quality

The [Data quality dashboard](https://console.cloud.google.com/ai/retail/catalogs/default_catalog/data_quality/) in the AI Commerce Search in Gemini Enterprise for Customer Experience console will show a Critical or a Blocking non-compliance error **Status** if the percentage of events with attribution tokens is under 95%. Otherwise, the **Status** will show as Compliant:

![Alt text](https://docs.cloud.google.com/static/gemini-enterprise-cx/ai-commerce-search/images/tier-compliant.png)

The data quality at Tier 3 which is the revenue optimized model will usually not train without sufficient attributable events. It is strongly not recommended to deploy AI Commerce Search into production unless it is serving results in Tier 3 or Tier 4. For more information, see the Data quality section on how to [unlock perforance tiers](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/data-quality.md.txt#tiers) see the [Data quality](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/data-quality.md.txt#tiers) page of this documentation.

## Attribution tokens for recommendations

Recommendations from AI Commerce Search automatically create synthetic tokens for events attributable to `predict` requests.

For recommendations predictions, if a user clicks on a recommended product, the `PredictResponse.attribution_token` should be passed as a URL parameter to the product page and then logged in the `detail-page-view` event.

Log displayed recommendations as part of [`panelInfo`](https://docs.cloud.google.com/gemini-enterprise-cx/ai-commerce-search/reference/rest/v2/projects.locations.catalogs.userEvents.md.txt#panelinfo) and set:

```javascript
panelInfo.attributionToken=PredictResponse.attributionToken
```