# Track Events API (Recommendations)

## Overview

The Track Events API allows you to send product interaction events directly to the recommendation engine.

Each event must correspond to one of the supported recommendation events:

- Added to cart  
- Removed from cart  
- Product ordered  
- Product viewed  

These events power recommendation feeds such as:

- Recently Viewed  
- Recently Added to Cart  
- Purchase-based recommendations  

You also will be able to map existing events using integrations Event Mapping feature.

---

## Endpoint

    POST https://api.intempt.com/v1/{orgName}/projects/{projName}/sources/{sourceId}/track

### Path Parameters

- **orgName** – Your organization name  
- **projName** – Your project name  
- **sourceId** – The source identifier  

Replace these placeholders with your actual values.

---

## Request Body Structure
```
    {
      "track": [
        {
          "name": "EVENT_NAME",
          "payload": [
            {
              "eventId": "id",
              "userId": "id",
              "anotherUserId": "id",
              "accountId": "id",
              "data": {
                "productId": "id"
              }
            }
          ]
        }
      ]
    }
```
---

## Field Definitions

### name

The event name.

Must exactly match one of:

- `Added to cart`
- `Removed from cart`
- `Product ordered`
- `Product viewed`

This determines how the recommendation engine processes the event.

---

### eventId

A unique identifier for the event.

Used for:
- Deduplication  
- Event integrity  

Must be unique per event.

---

## Identity Fields

At least one identity field must be provided:

- `userId`
- `anotherUserId` (optional)
- `accountId` (optional)

For identity setup and structure, refer to:

- [Track API](https://docs.intempt.com/track-data-24815715e0)  

Use the identity model that matches your integration.

---

## data.productId (Required)
```
    "data": {
      "productId": "id"
    }
```

- `productId` is required for all recommendation events.
- It must be included inside `data`.
- It cannot be mapped or renamed.
- It must uniquely identify a product in your catalog.

Events without `productId` will not power recommendation feeds.

---

## Supported Recommendation Events

### Product viewed

Used for:
- Recently Viewed feed  
- View-based recommendation models  

Required:
- `productId`

---

### Added to cart

Used for:
- Recently Added to Cart feed  
- Cart-based recommendation logic  

Required:
- `productId`

---

### Removed from cart

Used to maintain consistency of cart-based recommendation feeds.

Ensures:
- Removed products no longer appear in Recently Added to Cart  
- Cart state remains accurate  
- Recommendation signals reflect real behavior  

Required:
- `productId`

---

### Product ordered

Used for:
- Purchase-based recommendation models  
- Conversion tracking  
- Post-purchase recommendations  

Required:
- `productId`

---

## Example Request
```
    {
      "track": [
        {
          "name": "Added to cart",
          "payload": [
            {
              "eventId": "evt_10001",
              "userId": "user_123",
              "data": {
                "productId": "SKU_987"
              }
            }
          ]
        }
      ]
    }
```
---

## Important Notes

- `productId` is mandatory for all recommendation events.
- The `name` value must exactly match one of the supported recommendation events.
- Each `eventId` must be unique.
- At least one identity field must be provided.
- Events missing required fields will not be processed for recommendations.
