# Cart Event

Use a cart event to capture customer interactions when they modify the contents of their online shopping cart, including adding items, removing items, or replacing the entire cart.

## Event Structure

All cart events require these fields:

| Field Name | Field Type                                                                                                                      | Description                                   |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| `lineItem` | [Line Item Attribute](/docs/data/data-cloud-engagement-mobile-sdk/guide/c360a-api-engagement-mobile-sdk-line-item-attribute.md) | Required. A single line item attribute value. |

## Event Types

The Cart Event supports these interaction types:

- Add To Cart: Track when customers add items to their shopping cart
- Remove From Cart: Track when customers remove items from their shopping cart
- Replace Cart: Track when customers replace their entire shopping cart contents

### Add to Cart Event

Track when customers add items to their shopping cart.

```sfdocs-code {"lang":"swift", "title": "iOS Example", "src": "" }
AddToCartEvent(
    lineItem: LineItem(
        catalogObjectType: "Product",
        catalogObjectId: "product-1",
        quantity: 1,
        price: 20.0,
        currency: "USD",
        attributes: [
            "gift_wrap": false
        ]
    )
)
```

```sfdocs-code {"lang":"kotlin", "title": "Android Example", "src": "" }
CartEvent.add(
    lineItem = LineItem(
        catalogObjectId = "product-1",
        catalogObjectType = "Product",
        quantity = 1,
        price = 20.0,
        currency = "USD",
        attributes = mapOf(
            "gift_wrap" to false
        )
    )
)
```

## Remove from Cart Event

Track when customers remove items from their shopping cart.

```sfdocs-code {"lang":"swift", "title": "iOS Example", "src": "" }
RemoveFromCartEvent(
    lineItem: LineItem(
        catalogObjectType: "Product",
        catalogObjectId: "product-1",
        quantity: 1
    )
)
```

```sfdocs-code {"lang":"kotlin", "title": "Android Example", "src": "" }
CartEvent.remove(
    lineItem = LineItem(
        catalogObjectId = "product-1",
        catalogObjectType = "Product",
        quantity = 1
    )
)
```

## Replace Cart Event

Track when customers replace their entire shopping cart contents.

```sfdocs-code {"lang":"swift", "title": "iOS Example", "src": "" }
ReplaceCartEvent(
    lineItems: [
        LineItem(
            catalogObjectType: "Product",
            catalogObjectId: "product-1",
            quantity: 1
        ),
        LineItem(
            catalogObjectType: "Product",
            catalogObjectId: "product-2",
            quantity: 1,
            price: 20.0,
            currency: "USD",
            attributes: [
                "gift_wrap": false
            ]
        )
    ]
)
```

```sfdocs-code {"lang":"kotlin", "title": "Android Example", "src": "" }
CartEvent.replace(
    lineItems = listOf(
        LineItem(
            catalogObjectType = "Product",
            catalogObjectId = "product-1",
            quantity = 1
        ),
        LineItem(
            catalogObjectType = "Product",
            catalogObjectId = "product-2",
            quantity = 1,
            price = 20.0,
            currency = "USD",
            attributes = mapOf(
                "gift_wrap" to false
            )
        )
    )
)
```
