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

# Google Analytics & GTM

> Integrate Molin AI with Google Analytics and track e-commerce interactions via dataLayer events.

The Molin AI widget automatically sends interaction data to your website's Google Analytics through Google Tag Manager (GTM) integration, allowing you to track how users engage with the AI assistant on your site.

## What is the dataLayer integration?

The dataLayer integration automatically pushes events to the browser's `window.dataLayer` object when users interact with the Molin AI widget. All events are sent automatically, so no configuration is required on your part.

## Custom events

### `molin_chat_open`

Fired when the user opens the chat window.

```json theme={null}
{
  "event": "molin_chat_open",
  "widget_id": "abc123"
}
```

| Parameter   | Type     | Description                       |
| ----------- | -------- | --------------------------------- |
| `widget_id` | `string` | The unique ID of the Molin widget |

### `molin_chat_close`

Fired when the user closes the chat window.

```json theme={null}
{
  "event": "molin_chat_close",
  "widget_id": "abc123"
}
```

| Parameter   | Type     | Description                       |
| ----------- | -------- | --------------------------------- |
| `widget_id` | `string` | The unique ID of the Molin widget |

### `molin_message_sent`

Fired when the user sends a message in the chat.

```json theme={null}
{
  "event": "molin_message_sent",
  "widget_id": "abc123"
}
```

| Parameter   | Type     | Description                       |
| ----------- | -------- | --------------------------------- |
| `widget_id` | `string` | The unique ID of the Molin widget |

### `molin_link_click`

Fired when the user clicks a link inside a Molin AI widget conversation.

```json theme={null}
{
  "event": "molin_link_click",
  "widget_id": "abc123",
  "url": "https://yourstore.com/product/123"
}
```

| Parameter   | Type     | Description                       |
| ----------- | -------- | --------------------------------- |
| `widget_id` | `string` | The unique ID of the Molin widget |
| `url`       | `string` | The URL of the clicked link       |

## GA4 e-commerce events

The widget also pushes standard [GA4 e-commerce events](https://developers.google.com/analytics/devguides/collection/ga4/ecommerce) so that AI-driven product recommendations appear natively in your Google Analytics e-commerce reports.

### `view_item_list`

Fired when the AI recommends products in the chat. Each product is included as an item.

```javascript theme={null}
{
  event: 'view_item_list',
  ecommerce: {
    item_list_id: 'molin_ai_chat',
    item_list_name: 'Molin AI chat',
    items: [
      {
        item_name: 'Adidas Ultraboost 5',
        index: 0,
        item_list_id: 'molin_ai_chat',
        item_list_name: 'Molin AI chat',
        price: 189.99,
        google_business_vertical: 'retail'
      },
      {
        item_name: 'Adidas Gazelle Bold',
        index: 1,
        item_list_id: 'molin_ai_chat',
        item_list_name: 'Molin AI chat',
        price: 119.99,
        google_business_vertical: 'retail'
      }
    ]
  }
}
```

### `select_item`

Fired when the user clicks on a product card link. Identifies which product was selected from the recommendation list.

```javascript theme={null}
{
  event: 'select_item',
  ecommerce: {
    item_list_id: 'molin_ai_chat',
    item_list_name: 'Molin AI chat',
    items: [
      {
        item_name: 'Adidas Ultraboost 5',
        index: 0,
        item_list_id: 'molin_ai_chat',
        item_list_name: 'Molin AI chat',
        price: 189.99,
        google_business_vertical: 'retail'
      }
    ]
  }
}
```

### `view_item`

Fired alongside `select_item` when the user clicks a product card link. This event is used by GA4 to track product detail views.

```javascript theme={null}
{
  event: 'view_item',
  ecommerce: {
    items: [
      {
        item_name: 'Adidas Ultraboost 5',
        index: 0,
        item_list_id: 'molin_ai_chat',
        item_list_name: 'Molin AI chat',
        price: 189.99,
        google_business_vertical: 'retail'
      }
    ]
  }
}
```

### E-commerce item fields

| Field                      | Type     | Description                                        |
| -------------------------- | -------- | -------------------------------------------------- |
| `item_name`                | `string` | Product name from the product catalog              |
| `index`                    | `number` | Position of the product in the recommendation list |
| `item_list_id`             | `string` | Always `molin_ai_chat`                             |
| `item_list_name`           | `string` | Always `Molin AI chat`                             |
| `price`                    | `number` | Product price parsed from the catalog              |
| `google_business_vertical` | `string` | Always `retail`                                    |

<Note>The `price` field may be `0` in some cases. We are still upgrading our internal price parsing logic to cover all catalog formats reliably.</Note>

## Technical note

<Note>
  Before each e-commerce event, the widget pushes `{ ecommerce: null }` to clear the previous e-commerce object, following [Google's recommended practice](https://developers.google.com/analytics/devguides/collection/ga4/ecommerce#clear_the_ecommerce_object).
</Note>
