> For the complete documentation index, see [llms.txt](https://docs.frontnow.com/advise/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.frontnow.com/advise/4/integration/events-legacy.md).

# Events (legacy)

The events every Frontnow Advisor sends by default, for callbacks and Google Analytics.

{% hint style="info" %}
Before using these events, ensure that the Frontnow Advisor has been properly initialized. For setup instructions, please refer to the [Getting Started](https://docs.frontnow.com/advise/4/introduction/getting-started.md) page.
{% endhint %}

{% hint style="info" %}
This page describes the events your Advisor sends by default. A newer set of events is available on request, see [Events](https://docs.frontnow.com/advise/4/integration/events.md).
{% endhint %}

The Advisor reports what your visitors do in two ways:

* **Callbacks:** `advisor.on(name, callback)` calls your function.
* **Google Analytics:** the same events go to Google Analytics on your page. See [Google Analytics](#google-analytics).

Both use the same event names.

| What happened                                                                    | Event                  |
| -------------------------------------------------------------------------------- | ---------------------- |
| Advisor loaded (every page load)                                                 | `ready`                |
| Advisor opened                                                                   | `open`                 |
| Advisor closed                                                                   | `close`                |
| A message was sent (see [`message`](#message))                                   | `message`              |
| Visitor submitted a typed prompt                                                 | `prompt-submit`        |
| Visitor picked a suggested question                                              | `recommended-question` |
| Visitor picked a discovery topic                                                 | `discovery-topic`      |
| Product cards shown in an answer                                                 | `products-shown`       |
| Visitor clicked a link in an answer: a product link to your shop or another link | `document-click`       |
| Visitor opened a product's details                                               | `product-detail-open`  |

The Advisor also sends `eoc_open`, `eoc_close` and some interface events (for example `header-menu-toggle` or `stop-generation`) to callbacks and Google Analytics. They are not part of this contract and can change.

{% hint style="warning" %}
The event data (`message_count`, product fields, `conversation_id`, `app_version`) needs Advise 4.5.5 or later. Older versions send less data, send `document-click` without product data and send no `products-shown`.
{% endhint %}

## Google Analytics

If your page has Google Analytics, every event is forwarded automatically with the prefix `frontnow:`, for example `frontnow:document-click`.

{% hint style="success" %}
**Using GA4?** These event names contain `:` and `-`. GA4's event naming rules only allow letters, numbers and underscores. The events on the [Events](https://docs.frontnow.com/advise/4/integration/events.md) page follow them.
{% endhint %}

* **gtag.js on the page:** the Advisor calls `gtag('event', name, params)`.
* **Google Tag Manager only:** the Advisor pushes `{ event: name, ...params }` to `window.dataLayer`.
* The Advisor never loads Google Analytics itself and never sends to Universal Analytics (`window.ga`). A page with only Universal Analytics gets no events.
* Frontnow can switch the forwarding off for your Advisor. Callbacks keep working.

### Event parameters

Every event carries `conversation_id` and `app_version` once they are known. `ready` and the first `open` on each page load never carry them, because the chat has not loaded yet.

| Parameter             | Sent on                                                              | Meaning                                                                                                                                                                                                                                                                                                             |
| --------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `conversation_id`     | all events                                                           | the chat id; changes when the visitor starts a new conversation                                                                                                                                                                                                                                                     |
| `app_version`         | all events                                                           | the Advise version, for example `4.5.5`                                                                                                                                                                                                                                                                             |
| `message_count`       | `message`, `recommended-question`, `discovery-topic`                 | messages sent in this conversation so far; `1` = conversation start                                                                                                                                                                                                                                                 |
| `product_count`       | `products-shown`                                                     | product cards shown in that answer                                                                                                                                                                                                                                                                                  |
| `product_ids`         | `products-shown`                                                     | Frontnow's ids of the cards shown, in order, comma-separated (`id1,id2`); a product shown twice appears twice. Not your article numbers: those come as `customer_product_id` with a product click. Left out when longer than 100 characters (about 9 products, Google Analytics limit) and in older Advise versions |
| `message_id`          | `products-shown`, `document-click` (products), `product-detail-open` | the answer the products belong to; not set for gallery products or before the answer has arrived                                                                                                                                                                                                                    |
| `product_id`          | `document-click` (products), `product-detail-open`                   | Frontnow product id                                                                                                                                                                                                                                                                                                 |
| `customer_product_id` | `document-click` (products), `product-detail-open`                   | your own id for the product, to match it with your own data: the article number from your product feed, or the product page URL if we crawl your catalog. Left out when there is none                                                                                                                               |
| `surface`             | `document-click` (products)                                          | where the visitor clicked: `chat` (a product in the chat) or `detail_sheet` (product details)                                                                                                                                                                                                                       |
| `source`              | `product-detail-open`                                                | where the details were opened: `product_card`, `inline_link`, `search_results` or `gallery`                                                                                                                                                                                                                         |
| `url`                 | `document-click`                                                     | the link target; left out when it is longer than 100 characters (Google Analytics limit)                                                                                                                                                                                                                            |

`document-click` carries `product_id`, `customer_product_id`, `surface` and `message_id` only when a product link was clicked.

Google Analytics never gets the visitor's text.

### Measuring conversions

* **Conversion (click to your shop):** `frontnow:document-click` that has a `product_id`. Without `product_id` it is a click on another link. Opening a product's details is not a shop visit.
* **Conversation start:** there is no separate event. Count `message`, `recommended-question` and `discovery-topic` where `message_count` is `1`.
* **Counting messages:** a typed prompt sends both `message` and `prompt-submit`. Count `message` and ignore `prompt-submit`.
* **Your own buttons:** `advisor.sendMessage()` also sends `message` (and `open`, if the Advisor was closed). If you already track the click on your button, do not count it twice.
* `ready` fires on every page load where the Advisor is set up, without any visitor action.

### Setup in Google Analytics and Tag Manager

* **gtag.js:** events arrive in GA4 directly. Register the parameters you need as custom dimensions.
* **Google Tag Manager:** create one Custom Event trigger per event name (with the prefix, for example `frontnow:document-click`) and one Data Layer Variable per parameter. Tag Manager keeps the last value of every key, so a parameter that an event does not carry still shows the value of an earlier event. This happens when a `url` or the `product_ids` list is too long or missing (older Advise versions), on product events without a `message_id` or `customer_product_id`, and on every link click after a product click: both are `document-click`, so the link click still shows the product's `product_id` and `customer_product_id`. Bind each parameter only on the tag of the event that carries it.
* `source` is a plain dataLayer key. On Tag Manager pages it overwrites a `source` variable of your own.
* **Tag Manager plus a `gtag` function on the page** (for example for Consent Mode): the Advisor calls `gtag`. Check in Tag Manager preview how your container receives the events before you build triggers. If your Google tag already forwards these events, do not add a second GA4 event tag for them, or they are counted twice.
* **Consent:** the Advisor does not check consent. The consent setup of your page applies to everything the Advisor sends to `gtag` or `dataLayer`. Frontnow's own analytics is separate and not covered by it; see our [privacy policy](https://www.frontnow.com/legal/privacy-policy).

## Callbacks

`ready`, `open`, `close`, `eoc_open` and `eoc_close` call your function without an argument. All other events call it with the event data below. The data can contain the visitor's text (`value`, and `message` on `prompt-submit`): do not send it to analytics as it is. The data can contain more keys than listed; rely only on the documented ones.

### `ready`

Triggered when the Frontnow Advisor is initialized, on every page load.

```javascript
advisor.on('ready', () => {
    console.log('Advisor is ready!');
});
```

### `open`

Triggered when the Frontnow Advisor is opened.

```javascript
advisor.on('open', () => {
    console.log('Advisor is open!');
});
```

### `close`

Triggered when the Frontnow Advisor is closed. `advisor.close()` triggers it only when the Advisor is open.

```javascript
advisor.on('close', () => {
    console.log('Advisor is closed!');
});
```

### `message`

Triggered for every message that starts a turn in the chat: a typed prompt, a tapped answer option or chip, `advisor.sendMessage()`, or a prompt passed in the page URL. Suggested questions and discovery topics send their own events instead.

```javascript
advisor.on('message', (data) => {
    console.log('Message number', data.message_count);
});
```

```jsdoc
/**
 * @typedef {Object} MessageEventData
 * @property {string} value - The text of the message.
 * @property {number} message_count - Messages sent in this conversation so far, 1 = conversation start.
 * @property {string} conversation_id - The chat id.
 * @property {string} app_version - The Advise version.
 */
```

### `prompt-submit`

Triggered together with `message` when the visitor submits a typed prompt.

```javascript
advisor.on('prompt-submit', (data) => {
    console.log('Prompt submitted with', data.source);
});
```

```jsdoc
/**
 * @typedef {Object} PromptSubmitEventData
 * @property {string} message - The typed text.
 * @property {'keyboard'|'button'} source - How the prompt was submitted.
 * @property {number} timestamp - When it was submitted (ms since 1970).
 * @property {string} conversation_id - The chat id.
 * @property {string} app_version - The Advise version.
 */
```

### `recommended-question`

Triggered when the visitor picks a suggested question: on the start screen of the previous chat design, or a question shown for a product the visitor viewed (context awareness).

```javascript
advisor.on('recommended-question', (data) => {
    console.log('Suggested question:', data.value);
});
```

```jsdoc
/**
 * @typedef {Object} RecommendedQuestionEventData
 * @property {string} value - The text of the suggested question.
 * @property {number} message_count - Messages sent in this conversation so far, 1 = conversation start.
 * @property {string} conversation_id - The chat id.
 * @property {string} app_version - The Advise version.
 */
```

### `discovery-topic`

Triggered when the visitor picks a discovery topic on the start screen.

```javascript
advisor.on('discovery-topic', (data) => {
    console.log('Discovery topic:', data.title);
});
```

```jsdoc
/**
 * @typedef {Object} DiscoveryTopicEventData
 * @property {string} topic - The name of the tab the topic belongs to (can be empty).
 * @property {string} title - The title of the discovery topic.
 * @property {string} value - The prompt text of the discovery topic.
 * @property {number} message_count - Messages sent in this conversation so far, 1 = conversation start.
 * @property {string} conversation_id - The chat id.
 * @property {string} app_version - The Advise version.
 */
```

### `products-shown`

Triggered once per answer that shows product cards, when the answer is complete. Not sent for restored conversations or for the product gallery of the previous chat design.

```javascript
advisor.on('products-shown', (data) => {
    console.log(data.product_count, 'products shown');
});
```

```jsdoc
/**
 * @typedef {Object} ProductsShownEventData
 * @property {number} product_count - Product cards shown in the answer.
 * @property {string[]} [product_ids] - Frontnow's id of each card, in order. Google Analytics gets them comma-separated. Not set in older Advise versions.
 * @property {string} message_id - The answer the products belong to.
 * @property {string} conversation_id - The chat id.
 * @property {string} app_version - The Advise version.
 */
```

### `document-click`

Triggered when the visitor clicks a link: a product's link to your shop (in the chat or in the product details), or another link in an answer. Only product links carry `product_id`, `surface` and `message_id`.

```javascript
advisor.on('document-click', (data) => {
    if (data.product_id) {
        console.log('Shop click:', data.product_id, data.url);
    } else {
        console.log('Link clicked:', data.url);
    }
});
```

```jsdoc
/**
 * @typedef {Object} DocumentClickEventData
 * @property {string} title - The product title or the link text.
 * @property {string} url - The link target.
 * @property {string} [product_id] - The Frontnow product id (product links only).
 * @property {'chat'|'detail_sheet'} [surface] - A product in the chat, or the product details (product links only).
 * @property {string} [message_id] - The answer the product belongs to (product links only). Not set for gallery products or before the answer has arrived.
 * @property {string} [customer_product_id] - Your own id for the product (product links only): the article number from your product feed, or the product page URL if we crawl your catalog. Not set when there is none.
 * @property {string} conversation_id - The chat id.
 * @property {string} app_version - The Advise version.
 */
```

### `product-detail-open`

Triggered when the visitor opens a product's details: from a product card (`product_card`), a product link in an answer (`inline_link`), the search results list (`search_results`), or the product gallery of the previous chat design (`gallery`).

```javascript
advisor.on('product-detail-open', (data) => {
    console.log('Details opened:', data.product_id);
});
```

```jsdoc
/**
 * @typedef {Object} ProductDetailOpenEventData
 * @property {string} product_id - The Frontnow product id.
 * @property {string} [message_id] - The answer the product belongs to. Not set for gallery products or before the answer has arrived.
 * @property {'product_card'|'inline_link'|'search_results'|'gallery'} source - Where the details were opened.
 * @property {string} [customer_product_id] - Your own id for the product: the article number from your product feed, or the product page URL if we crawl your catalog. Not set when there is none.
 * @property {string} conversation_id - The chat id.
 * @property {string} app_version - The Advise version.
 */
```

## Changes to Google Analytics forwarding

These changes come with the current Advisor script and apply to every Advisor, also on older Advise versions:

* Events carry parameters in Google Analytics (see [Event parameters](#event-parameters)). Before, the parameters were always empty. Older Advise versions send fewer of them.
* Universal Analytics (`window.ga`) is no longer used. Pages with gtag.js or Google Tag Manager get the events there. A page with only Universal Analytics gets no events.
* New events: `products-shown` and `product-detail-open`.

From Advise 4.5.5, `document-click` also carries the product data when a product link was clicked, and opening a product in the gallery sends `product-detail-open` instead of `document-click`.
