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

# Methods

Frontnow Advisor provides a range of actions that allow you to customize the functionality of the widget and provide personalized recommendations and guidance to your website visitors.

{% hint style="info" %}
Before using these methods, 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.

You can call the methods before the Advisor is ready. The Advisor keeps the calls and runs them in order as soon as it is ready. This does not apply to `isReady()` and `updateTargetElement()`, which always run right away.
{% endhint %}

### `isReady()`

Checks if the Frontnow Advisor is ready.

**Returns:**

* `boolean` - `true` if the advisor is ready, otherwise `false`.

**Example usage:**

```javascript
if (advisor.isReady()) {
    console.log('Advisor is ready!');
}
```

### `open()`

Opens the Frontnow Advisor widget.

**Example usage:**

```javascript
advisor.open();
```

### `close()`

Closes the Frontnow Advisor widget.

**Example usage:**

```javascript
advisor.close();
```

### `showEoC()`

Opens the Frontnow "End of Conversation" widget.

**Example usage:**

```javascript
advisor.showEoC();
```

### `closeEoC()`

Closes the Frontnow "End of Conversation" widget.

**Example usage:**

```javascript
advisor.closeEoC();
```

### `showLauncher()`

Shows the Frontnow Advisor launcher button.

**Example usage:**

```javascript
advisor.showLauncher();
```

### `hideLauncher()`

Hides the Frontnow Advisor launcher button.

**Example usage:**

```javascript
advisor.hideLauncher();
```

### `sendMessage(message, options)`

Sends a message to the Frontnow Advisor. The widget opens if it is closed.

**Parameters:**

* `message` (`string`) - The message to send to the advisor.
* `options` (`object`, optional)
  * `newSession` (`boolean`) - `true` starts a new chat with `message` as its first message. Without it, the message goes into the current chat.

**Example usage:**

```javascript
advisor.sendMessage('How can I find the best city bike?');
```

**Start a new chat for every trigger:**

Use `newSession: true` when every trigger must be a fresh conversation, for example a search bar or an "ask the advisor" button. Each call opens a new chat; the previous chat is left behind.

```javascript
searchForm.addEventListener('submit', (event) => {
  event.preventDefault();
  advisor.sendMessage(searchInput.value, { newSession: true });
});
```

{% hint style="warning" %}
Do not combine `openNewChat()` with `sendMessage()` to start a new chat with a message. The message can land in the previous chat. Use the `newSession` option instead.
{% endhint %}

**Notes:**

* If you call `sendMessage()` before the Advisor is ready, the message is sent as soon as the Advisor is ready.
* With `newSession`, keep the message to search-field length (a few hundred characters).

### `stopMessage()`

Stops the current message loading in the Frontnow Advisor.

**Example usage:**

```javascript
advisor.stopMessage();
```

### `triggerPageView(url)`

Records a page view for `url`. Use it on single-page sites where the page changes without a full page load. The Advisor already records page loads and history changes (`pushState`, `popState`) on its own.

**Parameters:**

* `url` (`string`): The URL of the page the visitor now sees.

**Example usage:**

```javascript
// After your router has shown the new page:
advisor.triggerPageView(window.location.href);
```

**Notes:**

* A page view from `triggerPageView()` counts the same as an automatic one: the Advisor gets it, it is saved as a page view event, and page events configured for that URL fire. Before November 2026, `triggerPageView()` only informed the Advisor, so sites that call it now see more page views in the reports.
* Pass the same URL the browser shows (`window.location.href`). If you also use `pushState` and pass a different form of the URL (relative path, trailing slash, hash), the page view can be counted twice.

### `updateTargetElement(`newTargetElement`)`

Updates the target element for the Frontnow Advisor. This method is only applicable when using custom targeting.

**Parameters:**

* `newTargetElement` (`HTMLElement`): The new HTML element to target.

**Disclaimer:**

This method should only be used if you are implementing custom targeting for the Frontnow Advisor. Ensure that the `newTargetElement` parameter is a valid HTML element.

**Example usage:**

```javascript
const newTarget = document.getElementById('custom-target');
if (newTarget) {
    advisor.updateTargetElement(newTarget);
}
```

**Notes:**

* The current advisor instance will close before updating the target element.
* The `advisorContainer` will be removed and reinitialized to target the new element.

### `openNewChat()`

{% hint style="warning" %}
Deprecated. This method does nothing in current Advisor versions. To start a new chat with a message, use `sendMessage(message, { newSession: true })`.
{% endhint %}

**Example usage:**

```javascript
advisor.openNewChat();
```
