# Surveys - Connect Window API

The Connect Window API exposes public functions that can be called to setup or make configuration changes to surveys to be displayed on the page.

## Properties

This is a list of all properties that can be set on the window API.

| Name                                          | Description                                                                        | Sample                                 |
| --------------------------------------------- | ---------------------------------------------------------------------------------- | -------------------------------------- |
| `window.okeConnectApi.subscriberId`           | Okendo subscriber id for connecting to your store.                                 | `00000000-0000-0000-0000-000000000000` |
| `window.okeConnectApi.apiDomain`              | Shopify domain for connecting to your store.                                       | `{your-shopify-domain}`                |
| `window.okeConnectApi.channel`                | The survey channel being implemented. `on-site` or `post-checkout`                 | `on-site`                              |
| `window.okeConnectApi.targetElementId`        | Optional target element id in which to display an embedded survey.                 | `okendo-survey`                        |
| `window.okeConnectApi.checkout.orderId`       | Order id to associate with the customer and survey response.                       | `5179739177206`                        |
| `window.okeConnectApi.checkout.subtotalPrice` | Price of the order used for order value conditions as well as revenue attribution. | `100`                                  |
| `window.okeConnectApi.checkout.email`         | Used to attribute orders to survey responses.                                      | `user@example.com`                     |
| `window.okeConnectApi.checkout.lineItems`     | An array of product ids being purchased. Used for cart content conditions.         | `112233, 112244`                       |

## Functions

### <mark style="color:blue;">setup</mark>

Initialises the surveys scripts on the page.

#### Example Usage

```javascript
window.okeConnectApi.setup();
```

#### Properties

Before calling `setup`, you should set the properties below.

<table><thead><tr><th width="402">Name</th><th>Description</th></tr></thead><tbody><tr><td><code>window.okeConnectApi.subscriberId</code></td><td>Either subscriberId or apiDomain is required.</td></tr><tr><td><code>window.okeConnectApi.apiDomain</code></td><td>Either subscriberId or apiDomain is required.</td></tr><tr><td><code>window.okeConnectApi.channel</code></td><td><code>on-site</code> or <code>post-checkout</code></td></tr><tr><td><code>window.okeConnectApi.targetElementId</code></td><td>An optional target element id to place an embedded survey in.</td></tr></tbody></table>

#### Parameters

<table><thead><tr><th width="223">Parameter</th><th width="208">Description</th><th width="116">Value Type</th><th>Supported Values</th><th>Required</th></tr></thead><tbody><tr><td><code>customEventsOnly</code></td><td>Supress all page event triggers to allow manually triggering custom event surveys after initialisation.</td><td><code>boolean</code></td><td><code>true</code>, <code>false</code></td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr></tbody></table>

### <mark style="color:blue;">raiseCustomEvent</mark>

Raise a custom event to potentially trigger a given survey. Display frequency rules are followed by default which can prevent a survey from being displayed to a given user for example if they have already answered the survey in their session.

#### Example Usage

```javascript
window.okeConnectApi.raiseCustomEvent('product-survey');
```

#### Properties

You should set one of these properties before you can raise a custom event.

| Name                                | Description                                   |
| ----------------------------------- | --------------------------------------------- |
| `window.okeConnectApi.subscriberId` | Either subscriberId or apiDomain is required. |
| `window.okeConnectApi.apiDomain`    | Either subscriberId or apiDomain is required. |

#### Parameters

<table><thead><tr><th width="150">Parameter</th><th width="230">Description</th><th width="116">Value Type</th><th>Supported Values</th><th>Required</th></tr></thead><tbody><tr><td><code>eventName</code></td><td>The name of the event on the survey to show.</td><td><code>string</code></td><td></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td></tr><tr><td><code>forceShow</code></td><td>Flag to ignore all display rules and show the survey. Defaults to <code>false</code></td><td><code>boolean</code></td><td><code>true</code>, <code>false</code></td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr></tbody></table>

<figure><img src="/files/BkfnRX5FLG9f1p1gscIh" alt=""><figcaption><p>Setting a custom eventName on the on-site channel survey.</p></figcaption></figure>

### <mark style="color:blue;">addToCart</mark>

Raise an add to cart event to trigger any add to cart surveys or to support a remove from cart trigger later. Add and remove from cart events rely on a cached list of products to store state between events.

#### Example Usage

```javascript
window.okeConnectApi.addToCart('11223344');
```

#### Parameters

| Parameter   | Description                         | Value Type | Required             |
| ----------- | ----------------------------------- | ---------- | -------------------- |
| `productId` | The product id being added to cart. | `string`   | :white\_check\_mark: |

### <mark style="color:blue;">removeFromCart</mark>

Raise a remove from cart event to trigger any remove from cart surveys.

#### Example Usage

```javascript
window.okeConnectApi.removeFromCart('11223344');
```

#### Parameters

| Parameter   | Description                             | Value Type | Required             |
| ----------- | --------------------------------------- | ---------- | -------------------- |
| `productId` | The product id being removed from cart. | `string`   | :white\_check\_mark: |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.okendo.io/on-site/storefront-javascript-api/surveys-connect-window-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
