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

# Cart Utilities

> Administrative utilities for cart management and analytics

## Overview

Cart Utilities provide administrative functions for cart maintenance, analytics, and cleanup operations. These internal functions help maintain system performance and provide insights into customer behavior.

**Location:** `convex/customers/cartUtils.ts`

## Cleanup Abandoned Carts

<ParamField path="daysOld" type="number" required>
  Age threshold in days
</ParamField>

<CodeGroup>
  ```typescript TypeScript theme={null}
  const result = await convex.mutation(api.customers.cartUtils.cleanupAbandonedCarts, {
    daysOld: 30
  });
  ```
</CodeGroup>

## Get Cart Analytics

<ParamField path="storeId" type="Id<'stores'>">
  Optional store filter
</ParamField>

<CodeGroup>
  ```typescript TypeScript theme={null}
  const analytics = await convex.query(api.customers.cartUtils.getCartAnalytics, {
    storeId: "j123456789"
  });
  ```
</CodeGroup>

<ResponseExample>
  ```json Response theme={null}
  {
    "totalCarts": 150,
    "totalItems": 450,
    "totalValue": 2250.75,
    "averageCartValue": 15.00,
    "averageItemsPerCart": 3.0,
    "topProducts": [
      {
        "productId": "p123456789",
        "productName": "Pizza Margherita",
        "quantityInCarts": 25,
        "timesAdded": 18
      }
    ]
  }
  ```
</ResponseExample>

<Note>
  These are internal administrative functions for system maintenance and analytics.
</Note>
