> 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.md).

# Events

Track any events provided by the Frontnow Advisor to enhance your user experience or integrate with your own event tracking systems.

{% 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="warning" %}
**Opt-in.** The events on this page are switched on per Advisor. Ask your Frontnow contact to enable them for yours. Until then, your Advisor sends the events described in [Events (legacy)](https://docs.frontnow.com/advise/4/integration/events-legacy.md).
{% endhint %}

The Advisor reports what your visitors do in these 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).
* **Other analytics tools:** forward the callbacks to your tool. See [Other analytics tools](#other-analytics-tools).

All use the same event names. There is one event per visitor action.

| What happened                                  | Event                  |
| ---------------------------------------------- | ---------------------- |
| Advisor loaded (every page load)               | `ready`                |
| Advisor opened                                 | `open`                 |
| Advisor closed                                 | `close`                |
| A message was sent (see [`message`](#message)) | `message`              |
| 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 product's link to your shop  | `product_click`        |
| Visitor opened a product's details             | `product_detail_open`  |
| Visitor clicked another link in an answer      | `link_click`           |

{% hint style="info" %}
These events need Advise 4.5.5 or later.
{% endhint %}

## Google Analytics

If your page has Google Analytics, every event is forwarded automatically with the prefix `frontnow_`, for example `frontnow_product_click`.

* **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`, `product_click`, `product_detail_open` | the answer the products belong to; not set when the product is not part of an answer (yet)                                                                                                                                                                                                                          |
| `product_id`          | `product_click`, `product_detail_open`                   | Frontnow product id                                                                                                                                                                                                                                                                                                 |
| `customer_product_id` | `product_click`, `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`             | `product_click`                                          | 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`                 | `product_click`, `link_click`                            | the link target; left out when it is longer than 100 characters (Google Analytics limit)                                                                                                                                                                                                                            |
| `trigger`             | `open`                                                   | what opened the Advisor: `launcher`, `send_message`, `open_method`, `goto` or `app`; see [`open`](#open)                                                                                                                                                                                                            |

Google Analytics never gets the visitor's text.

### Measuring conversions

* **Conversion (click to your shop):** `frontnow_product_click`. 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`.
* **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_product_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) and on product events without a `message_id` or `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).

## Other analytics tools

Matomo, econda, Adobe Analytics or any other tool can receive the events through the [callbacks](#callbacks). This works whether Google Analytics forwarding is on or off.

Put the code in the same script, right after `new AdvisorSDK(...)`, so `ready` is not missed. Run it once per page load: every `advisor.on` adds a listener, so running it again counts every event twice.

```javascript
// Right after: var advisor = new AdvisorSDK("YOUR_API_KEY");
var FRONTNOW_EVENTS = [
  'ready', 'open', 'close', 'message', 'recommended_question', 'discovery_topic',
  'products_shown', 'product_click', 'product_detail_open', 'link_click'
];
var FRONTNOW_PARAMS = [
  'conversation_id', 'app_version', 'message_count', 'product_count', 'product_ids', 'message_id',
  'product_id', 'customer_product_id', 'surface', 'source', 'url', 'trigger'
];

FRONTNOW_EVENTS.forEach(function (name) {
  advisor.on(name, function (data) {
    var params = {};
    FRONTNOW_PARAMS.forEach(function (key) {
      var value = data ? data[key] : undefined;
      if (Array.isArray(value)) value = value.join(','); // product_ids
      if (value !== undefined && value !== null && value !== '') params[key] = value;
    });
    // Replace with your tool's call. Never send `data` itself: it can contain the visitor's text.
    yourTool.track('frontnow_' + name, params);
  });
});
```

* **Tools without free parameters** (category, action, label): use the category `Frontnow`, the event name as action, `customer_product_id`, `product_id` or `url` as label, and `message_count` or `product_count` as value.
* **Parameters:** they mean the same as in [Event parameters](#event-parameters). Differences from Google Analytics: `ready` and `close` carry none, `open` carries only `trigger`, and none of the three carries `conversation_id`. Long `url`s are not removed.
* **Counting:** the same rules as in [Measuring conversions](#measuring-conversions) apply.
* **Tag Manager:** the code also works in the Custom HTML tag from [Getting Started](https://docs.frontnow.com/advise/4/introduction/getting-started.md), below the `new AdvisorSDK` line.
* **Consent:** the Advisor does not check consent, and `advisor.on` fires whether or not the visitor has consented. Gate your forwarding code behind your page's consent management: run `yourTool.track(...)` only when the visitor has consented to analytics. Frontnow's own analytics is separate and not covered by your page's consent setup; see our [privacy policy](https://www.frontnow.com/legal/privacy-policy).

{% hint style="info" %}
**Test first.** Replace `yourTool.track(...)` with `console.log(name, params)`, open the Advisor and ask a question that shows products. If `products_shown` appears in the console, it works. If only `ready`, `open`, `close` and `message` appear, the events on this page are not switched on for your Advisor yet (see the opt-in note at the top). These four have the same names in the [legacy events](https://docs.frontnow.com/advise/4/integration/events-legacy.md), the others do not.
{% endhint %}

## Callbacks

`ready` and `close` call your function without an argument. `open` calls it with `{ trigger }`, see [`open`](#open). All other events call it with the event data below. The data can contain the visitor's text (`value`): 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. `trigger` says what opened it:

* `launcher`: the visitor clicked the launcher.
* `send_message`: `advisor.sendMessage()`.
* `open_method`: `advisor.open()`.
* `goto`: your page opened a saved conversation (`advisor.goto()`).
* `app`: reserved, not sent today.

```javascript
advisor.on('open', (data) => {
    console.log('Advisor opened by', data.trigger);
});
```

### `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.
 */
```

### `recommended_question`

Triggered when the visitor picks one of the suggested questions shown for a product they 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.

```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.
 */
```

### `product_click`

Triggered when the visitor clicks a product's link to your shop, in the chat or in the product details.

```javascript
advisor.on('product_click', (data) => {
    console.log('Shop click:', data.product_id, data.url);
});
```

```jsdoc
/**
 * @typedef {Object} ProductClickEventData
 * @property {string} title - The product title.
 * @property {string} url - The product URL in your shop.
 * @property {string} product_id - The Frontnow product id.
 * @property {'chat'|'detail_sheet'} surface - A product in the chat, or the product details.
 * @property {string} [message_id] - The answer the product belongs to. Not set when the product is not part of an answer (yet).
 * @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.
 */
```

### `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 when the product is not part of an answer (yet).
 * @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.
 */
```

### `link_click`

Triggered when the visitor clicks a link in an answer that is not a product link.

```javascript
advisor.on('link_click', (data) => {
    console.log('Link clicked:', data.url);
});
```

```jsdoc
/**
 * @typedef {Object} LinkClickEventData
 * @property {string} title - The link text.
 * @property {string} url - The link target.
 * @property {string} conversation_id - The chat id.
 * @property {string} app_version - The Advise version.
 */
```
