Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(integration): update getSnippetConfig docs #1385

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ out further information about:
- **Functions supported by the [X API object](#x-api)** to initialize Interface X
- Notes on how to set up [**the preview of query results**](#dynamic-query-results-preview) for
determined queries at the pre-search stage
- [**Tracking options for add to cart events**](#tracking-events-for-add-to-cart-on-product-detail-pages) from product detail pages
- [**Tracking options for add to cart events**](#tracking-events-for-add-to-cart-on-product-detail-pages)
from product detail pages

### Snippet configuration

Expand Down Expand Up @@ -315,6 +316,7 @@ functions to integrate Interface X in your website. You can access these fu
| `search` | `query` - _Optional_. Query to open Interface X | Executes Interface X and triggers a search with the given query. |
| `close` | none | Closes Interface X search layer. |
| `setSnippetConfig` | [snippet configuration params](#snippet-configuration) - _Required_. Initialization options | Changes initialization options so that all components react to the changes, i.e. changing both search engine and language without reloading the page. |
| `getSnippetConfig` | none | Returns the current initialization options. |
| `addProductToCart` | `productId` - _Optional._ Id of the product added to cart | Sends tracking of the `AddToCart` event to the [Empathy Tagging microservice](/develop-empathy-platform/capture-interaction-signals/tagging-api-guide.md) for the product displayed on screen. This function is called from the product detail page (PDP) when the shopper clicks on the add-to-cart button. If the `productId` is not provided, the URL detects whether the shopper found the product via a search session or not. |

### Dynamic query results preview
Expand Down Expand Up @@ -409,61 +411,48 @@ instance:

### Tracking events for add to cart on product detail pages

Empathy Platform Interface X allows you to track shoppers' add-to-cart interactions from any product detail page (PDP) in your commerce store, regardless of whether your commerce store is running on a **single-page application or not**.
Empathy Platform Interface X allows you to track shoppers' add-to-cart interactions from any product
detail page (PDP) in your commerce store, regardless of whether your commerce store is running on a
**single-page application or not**.

#### Tracking add-to-cart events on non-SPA webpages
To track your shoppers' add-to-cart interactions from any PDP based on a non-spa structured webpage, follow these steps:

To track your shoppers' add-to-cart interactions from any PDP based on a non-spa structured webpage,
follow these steps:

1. Add the `productId` parameter when initializing the script.

```html
window.InterfaceX.init({
instance: "instanceName",
lang: "es",
documentDirection: "ltr",
scope: 'desktop',
currency: "EUR",
consent: true,
isSPA: false,
queriesPreview: []
{
query: 'coats',
title: 'Winter Coats'
}
],
callbacks: {
UserClickedAResult: function(a, b, e, t) {}
},
productId: '11776347-ES' // Add this parameter
})
```
```html
window.InterfaceX.init({ instance: "instanceName", lang: "es", documentDirection: "ltr", scope:
'desktop', currency: "EUR", consent: true, isSPA: false, queriesPreview: [] { query: 'coats',
title: 'Winter Coats' } ], callbacks: { UserClickedAResult: function(a, b, e, t) {} }, productId:
'11776347-ES' // Add this parameter })
```

2. Call the `InterfaceX.addProductToCart('11776347-ES')` function to track the event when the add-to-cart button is clicked.
2. Call the `InterfaceX.addProductToCart('11776347-ES')` function to track the event when the
add-to-cart button is clicked.

```html
yourCommerceStoreEnvironment.addToCartButton.addEventListener('click', () =>
InterfaceX.addProductToCart('11776347-ES');
);
```html
yourCommerceStoreEnvironment.addToCartButton.addEventListener('click', () =>
InterfaceX.addProductToCart('11776347-ES'); );
```


#### Tracking add-to-cart events on SPA webpages
To track your shoppers' add-to-cart interactions from any PDP based on a SPA structured webpage, follow these steps:

1. Call the `InterfaceX.bus.emit('PDPIsLoaded')` function any time a new PDP-type page is loaded.

To track your shoppers' add-to-cart interactions from any PDP based on a SPA structured webpage,
follow these steps:

```html
if (yourCommerceStoreEnvironment.isPDP && window.initX.isSpa) {
InterfaceX.bus.emit('PDPIsLoaded')
}
```
1. Call the `InterfaceX.bus.emit('PDPIsLoaded')` function any time a new PDP-type page is loaded.

2. Call the `InterfaceX.addProductToCart()` function to track the event when the add-to-cart button is clicked:
```html
if (yourCommerceStoreEnvironment.isPDP && window.initX.isSpa) {
InterfaceX.bus.emit('PDPIsLoaded') }
```

2. Call the `InterfaceX.addProductToCart()` function to track the event when the add-to-cart button
is clicked:

```html
yourCommerceStoreEnvironment.addToCartButton.addEventListener('click', () =>
InterfaceX.addProductToCart();
);
```
```html
yourCommerceStoreEnvironment.addToCartButton.addEventListener('click', () =>
InterfaceX.addProductToCart(); );
```