> ## 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

> Track how visitors use your AI assistant in Google Analytics, with e-commerce interactions pushed automatically through 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       |

### `molin_lead_collected`

Fired when the AI successfully collects a lead (the visitor's name and contact details) in the chat.

This is the strongest conversion signal the widget emits. Unlike engagement events such as `molin_chat_open` or `molin_message_sent`, it fires only when a real lead was captured, so it is the recommended event for conversion tracking and ad campaign optimization.

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

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

<Tip>
  To optimize ad campaigns on Molin leads: create a GTM trigger for the `molin_lead_collected` dataLayer event, forward it to GA4 as a custom event, then mark it as a key event in GA4 and import it as
  a conversion in Google Ads.
</Tip>

### `molin_order_lookup`

Fired when the AI finds a customer's order and shows its details in the chat (order status, tracking, items). A useful signal for measuring support automation.

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

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

### `molin_live_chat_requested`

Fired when the AI successfully starts a live chat request, escalating the visitor to a human support agent. It does not fire when agents are unavailable or the request fails.

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

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

### `molin_product_review_shown`

Fired when the AI shows customer product reviews in the chat.

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

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

## 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>
