<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [XAPI](./x-components.xapi.md) &gt; [addProductToCart](./x-components.xapi.addproducttocart.md)

## XAPI.addProductToCart() method

To track that a product was added to the cart from PDP.

**Signature:**

```typescript
addProductToCart(productId?: string): void;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  productId | string | _(Optional)_ The id of the product added to cart. |

**Returns:**

void

## Remarks

if no productId is provided, then the current page url will be used as id for getting the previously stored result information.

