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

# Kameleoon.API.Products: Tracking

> Reference for the Kameleoon.API.Products methods that send product views, category views, searches, cart and wishlist changes, and purchases.

Use these methods to send product and category views, searches, cart changes, wishlist additions, and purchases to Kameleoon.

> [!NOTE]
>
> This module is available when subscribed to the Product Recommendation module or Product Targeting add-on.

## trackAddToCart

The `trackAddToCart()` method triggers when a visitor adds a product to the shopping cart.

```javascript theme={null}
var buyButton = Kameleoon.API.Utils.querySelectorAll("#buyButton")[0];
Kameleoon.API.Utils.addEventListener(buyButton, "mousedown", function () {
  Kameleoon.API.Products.trackAddToCart("myProductId", 19.99, 1, {
    stock: true, 
    recommended_code: 'some-unique-code', //see the arguments table for more information
    recommended_by: 'dynamic'//see the arguments table for more information
  });
});
```

**Arguments**

| Name | Type | Description |
| - | - | - |
| productID | String | Unique product identifier. This field is mandatory. |
| unitPrice | Number | Price for a single unit of the product referenced by **productID**. This field is optional; if you don't specify it, Kameleoon uses the default price of the product from the imported product feed. |
| amount | Number | Total quantity of the product after the cart update. Use non-incremental values. For example, if the cart contains two items with the same `productID` and you add another, specify 3. If you remove two items from a cart containing 20, specify 18. |
| parameters | Object | [Parameters for the recommendation platform.](#parameters-for-the-recommendation-platform) This field is optional. |

### Parameters for the recommendation platform

| Name | Type | Description |
| - | - | - |
| recommended\_by | String | For SPAs or pop-ups, set this value to `dynamic`. This field is mandatory in specific scenarios. |
| recommended\_code | String | For SPAs or pop-ups, provide the unique widget code found in the "data-recommender-code" attribute in your account. |
| stock | Boolean | Product availability. This value overrides data from product feeds or catalog imports. This field is optional. |

## trackAddToWishList

The `trackAddToWishList()` method executes when a visitor adds or removes a product from the wish list or favorites.

```javascript theme={null}
Kameleoon.API.Products.trackAddToWishList("myProductId"); // to add to wish list

Kameleoon.API.Products.trackAddToWishList("myProductId", -1); // to remove from wish list
```

| Name | Type | Description |
| - | - | - |
| productId | String | Unique identifier of the product added to the wishlist. This field is mandatory. |
| quantity | Number | Quantity to update. Use negative values (for example, -1) to indicate removal. If omitted, the method defaults to **1**. |

## trackCategoryView

The `trackCategoryView()` method executes for each category page view during a session.

```javascript theme={null}
if (location.href.indexOf("productPage") != -1) {
  Kameleoon.API.Core.runWhenConditionTrue(function () {
    return typeof dataLayer != null;
  }, function () {
    dataLayer.forEach(function (map) {
      if (map.categoryID) {
        Kameleoon.API.Products.trackCategoryView(5);
      }
    });
  }, 200);
}
```

**Arguments**

| Name | Type | Description |
| - | - | - |
| categoryID | String | Unique category identifier. This field is mandatory. |

## trackProductView

The `trackProductView()` method executes for each product view during a session. This method allows Kameleoon to build an automated product catalog without an XML feed integration, which simplifies the setup of product recommendation projects.

```javascript theme={null}
Kameleoon.API.Products.trackProductView("myProductID", {
    "name": "productName",
    "categories": [{
        "id": "13",
        "name": "productCategory",
        "parent": null,
        "url": "website.com/category/2"
    }],
    "imageURL": "https://www.mywebsite/productImage.jpg",
    "price": 19.99,
   "oldPrice": 23.99,
    "accessories": ['productID1', 'productID2'],
    "available": true,
    "availableQuantity": 15,
    "brand": "productBrand",
    "groupId": "groupID1",
    "sku": "productSKU",
    "description": "This is a short description",
    "rating": 4,
    "model": "phone 14 128GB",
    "leftovers": "one",
    "tags": ["shirt", "red"],
    "typePrefix": "mobile phone",
    "seasonality": [1, 2, 3, 10, 11, 12],
    "priceMargin": 100,
    "isChild": false,
    "isNew": false,
    "isFashion": true,
    "auto": {
        "vds": ["BP8AN5", "HH5820"],
        "compatibility": [ 
            {
                "brand": "BMW"
            }, 
            { 
                "brand": "Mini", "model": "Cooper S" 
            } 
        ]
    },
    "fashion":  {
        "gender": "f",
        "type": "shoe",
        "sizes": ["37", "42"],
        "feature": "adult",
        "colors": [ 
            { 
                "color": "red" 
            }, 
            { 
                "color": "green", "picture": "https://example.com/items/395532-green.jpg" 
            }
        ]
    },
    "params": [
        {
            "name": "connectivity",
            "value": ["bluetooth", "wi-fi"]
        },
        {
            "name": "lengths",
            "value": ["4", "6", "8"],
            "unit": "cm"
        }
    ]
});
```

**Arguments**

| Name | Type | Description |
| - | - | - |
| productID | String | Product identifier. Use any unique value that identifies this particular product. This field is mandatory. |
| productData | Object | [Product object](https://docs.kameleoon.com/developer-docs/apis/activation-api-js/api-reference/objects/goal-segment-trigger-and-product.md#product). This field is mandatory for importing product feeds via the Product Recommendation add-on. |

## trackSearchQuery

The `trackSearchQuery()` method records user search queries.

```javascript theme={null}
Kameleoon.API.Products.trackSearchQuery("Example search request");
```

**Arguments**

| Name | Type | Description |
| - | - | - |
| search\_query | String | The search query value. This field is mandatory. |

## trackTransaction

The `trackTransaction()` method executes when a transaction or purchase occurs.

```javascript theme={null}
Kameleoon.API.Products.trackTransaction(
 [
  {
   "productID": "myProductID1",
   "quantity": 4
  },
  {
   "productID": "myProductID4564",
   "quantity": 1
  }
 ],
 {
  "order": "N318",
  "order_price": 29999
 }
);
```

**Arguments**

| Name | Type | Description |
| - | - | - |
| products | Array | List of objects containing the `productID` and `quantity` for each product in the transaction. This field is mandatory. |
| params | Object | [Additional parameters for the recommendation platform.](#additional-parameters-for-tracktransaction) This field is optional. |

### Additional parameters for trackTransaction

| Name | Type | Description |
| - | - | - |
| order | string | Store order number. If you omit this, the engine uses an internal numbering system, which prevents order status synchronization. Refer to the parameter descriptions below. |
| order\_price | Number | Final order cost, including discounts, bonuses, and additional services. If you omit this, the engine calculates the cost from the product database without discounts or services. |
| email | string | Customer email. |
| phone | string | Customer phone number. |
| promocode | string | Transaction promo code. |
| order\_cash | number | Cash payment amount. |
| order\_bonuses | number | Bonus payment amount. |
| order\_delivery | number | Delivery fee. |
| order\_discount | number | Order discount amount. |
| delivery\_type | string | Delivery method. |
| payment\_type | string | Payment type (for example, `cash`, `card`, or `wire`). |
| tax\_free | boolean | Tax-free status. |
