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

# Tracking Events

> Event names, parameters and data layer format for Totebot tracking, plus how to send events to other tools

This page lists the events Totebot sends to [Google Analytics](https://docs.totebot.ai/integrations/google.md) and [Meta](https://docs.totebot.ai/integrations/meta-ads.md), the data each event carries, and how to use the events on your own website.

No personal data is sent. Totebot never sends message text, names, email addresses or phone numbers.

## Event list

| Event | When it fires | Extra parameters | Meta event |
| - | - | - | - |
| `totebot_chat_opened` | A shopper opened the chat window. | | |
| `totebot_message_sent` | A shopper sent a message. | | |
| `search` | The agent searched your products. | `search_term` | `Search` |
| `view_item_list` | The agent showed product cards in a reply. | `item_list_name`, `items` (with `index`) | |
| `select_item` | A shopper clicked a product card in the chat. | `item_list_name`, `items` | |
| `view_item` | A shopper opened product details in the chat. | `items` | `ViewContent` |
| `add_to_cart` | A product was added to the cart from the chat. | `items` | `AddToCart` |
| `remove_from_cart` | A product was removed from the cart from the chat. | `items` | `RemoveFromCart` |
| `begin_checkout` | A shopper clicked checkout in the chat. | `items` | `InitiateCheckout` |
| `generate_lead` | The agent collected a lead. | `lead_source` | `Lead` |
| `totebot_handover` | The conversation was handed to your team. | | |

Events without a Meta event are only available for Google Analytics.

## Parameters

Every event carries:

| Parameter | Value |
| - | - |
| `agent_id` | The ID of your Totebot agent. |
| `conversation_id` | The ID of the conversation, when there is one. |
| `source` | Always `totebot`. |
| `channel` | Where the chat happened, when known: `web`, `whatsapp`, `telegram`, `email` and so on. |

Some events carry extra parameters:

| Parameter | Used by | Value |
| - | - | - |
| `items` | Ecommerce events | List of products (see below). |
| `currency` | Ecommerce events | Currency code, for example `EUR`. |
| `value` | Ecommerce events | Total value of the items. |
| `item_list_name` | `view_item_list`, `select_item` | Always `totebot_chat`. |
| `search_term` | `search` | The search words the agent used, with emails and phone numbers removed. At most 100 characters. |
| `lead_source` | `generate_lead` | The name of the lead action that collected the lead. Never the name, email or phone number. |

Each product in `items` can have `item_id`, `item_name`, `price`, `quantity`, `item_brand`, `item_variant` and, for `view_item_list`, `index` (its position in the reply). Fields are only included when Totebot knows them.

## Data layer format

With the **Through my website's Google tag** or **Both** delivery mode, the embed script on your page receives each event from the chat widget and does two things:

1. Pushes it into `window.dataLayer`.
2. Calls `window.gtag` if your page has it.

For ecommerce events, the script first clears the previous ecommerce object, then pushes the event:

```javascript theme={null}
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
  event: 'add_to_cart',
  ecommerce: {
    currency: 'EUR',
    value: 59.9,
    items: [
      {
        item_id: '8123',
        item_name: 'Canvas tote bag',
        price: 29.95,
        quantity: 2,
      },
    ],
  },
  agent_id: 'YOUR_AGENT_ID',
  conversation_id: 'c9f1...',
  channel: 'web',
  source: 'totebot',
});
```

`item_list_name` sits inside `ecommerce`. `search_term` and `lead_source` sit at the top level. Keys are only present when they have a value.

The `gtag` call looks like this:

```javascript theme={null}
gtag('event', 'add_to_cart', {
  currency: 'EUR',
  value: 59.9,
  items: [/* ... */],
  agent_id: 'YOUR_AGENT_ID',
  conversation_id: 'c9f1...',
  channel: 'web',
  source: 'totebot',
  send_to: 'G-XXXXXXXXXX',
});
```

`send_to` is the Measurement ID you entered in Totebot, so the event only goes to that GA4 property.

## Tracking options

You can turn off either output. Set `window.totebotTrackingOptions` on your page, before or after the embed script:

```html theme={null}
<script>
  // Only push to the data layer, don't call gtag
  window.totebotTrackingOptions = { gtag: false };
</script>
```

| Option | Use it when |
| - | - |
| `{ gtag: false }` | Google Tag Manager already forwards the data layer events to GA4. This stops events being counted twice. |
| `{ dataLayer: false }` | You don't want Totebot events in your data layer, for example because other GTM tags react to these event names. |

If you use gtag.js without Google Tag Manager, you don't need to set anything.

## Send events to other tools

The embed script also exposes the events in JavaScript, so you can forward them to any analytics tool. Listen with `window.totebot.on('event', callback)`:

```javascript theme={null}
function onTotebotEvent(event) {
  // event.name: for example 'add_to_cart'
  // event.params: the parameters listed above
  analytics.track(event.name, {
    channel: event.params.channel,
    value: event.params.value,
    currency: event.params.currency,
    items: event.params.items,
  });
}

window.totebot.on('event', onTotebotEvent);
```

Stop listening with `window.totebot.off('event', onTotebotEvent)`.

`window.totebot` exists once the embed script has loaded. If your code may run earlier, listen for the `totebot:event` browser event instead. It carries the same object in `event.detail`:

```javascript theme={null}
window.addEventListener('totebot:event', (event) => {
  onTotebotEvent(event.detail);
});
```

The callback fires for every event you ticked in the Google Analytics integration, on the web widget, when the delivery mode is **Through my website's Google tag** or **Both**. It runs in the shopper's browser, so it never fires for WhatsApp, Telegram or email chats.

> [!WARNING]
>
> Totebot events contain no personal data. Keep it that way: don't add names, email addresses, phone numbers or message text when you forward events to another tool.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.