You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/javascript/api.md
+87-16Lines changed: 87 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -33,8 +33,9 @@ Where `callback` is a function that will receive a set of `parameters` and retur
33
33
|`constants`| A group of variables that hold the different [constants](#constants) that can be used for creating components on your site. |
34
34
|`render`| Function that allows rendering a component in a specific placement and target. See more details for this function [here](#render). |
35
35
|`session`| Object that contains several values from the current session that can be useful when creating customizations. See more details for this function [here](#session). |
36
-
|`onNavigation`| Function that will be executed once any widget in a content is rendered. See more details for this function [here](#on-widget-rendered)|
37
-
|`onWidgetRendered`| Function that will be executed once the application has performed a navigation. See more details for this function [here](#on-navigation)|
36
+
|`on`| Function that will be executed upon user actions or component rendrering. See more details for this function [here](#on)|
37
+
|`onNavigation` (deprecated) | Function that will be executed once any widget in a content is rendered. See more details for this function [here](#on-widget-rendered)|
38
+
|`onWidgetRendered` (deprecated) | Function that will be executed once the application has performed a navigation. See more details for this function [here](#on-navigation)|
38
39
|`api`|[Axios](https://github.com/axios/axios) instance that allows the developer to execute AJAX requests. See more details for this function [here](#axios-api)|
39
40
40
41
And `configuration` is an object that allows these properties:
@@ -44,6 +45,19 @@ And `configuration` is an object that allows these properties:
44
45
|`shouldRenderOnNavigation`| whether the customization callback should be executed upon navigation. If `true`, the `callback` will be executed on every navigation that the application executes. **IMPORTANT:** Please make sure that this option applies and is needed to your use case in order to avoid having an unnecessary performance impact. Normally you would not need to set it to true |
45
46
|`shouldRenderOnNavigation`| if the customization uses data from the current content (by executing `window.lumapps.getCurrentContent()`). As of right now, other than that use case, `shouldRenderOnNavigation` should always be `false`. |
46
47
48
+
### events
49
+
50
+
`events` is a key/value object that holds the available events that can be subcribed to on LumApps. This variable allows developers to avoid figuring out which ids to use in order to listen to a specific event, and it also defines the available events that can be used for customization. As of now, these are the values for this object:
|`events.NAVIGATION`| Event id for user navigation events. |[Documentation](./capabilities#event-navigation)|
55
+
|`events.SEARCH_BOX`| Event id for the user searchbox interaction events. |[Documentation](./capabilities#event-searchbox)|
56
+
|`events.SEARCH_FILTER`| Event id for the user filter interaction events on the search page. |[Documentation](./capabilities#event-search-filter)|
57
+
|`events.SEARCH_RESULT`| Event id for the search result events triggered when user makes a search query. |[Documentation](./capabilities#event-search-result)|
58
+
|`events.SEARCH_SORT`| Event id for the user sort interaction events on the search page. |[Documentation](./capabilities#event-search-sort)|
59
+
|`events.WIDGET_RENDERED`| Event id for the event triggered after rendering a widget. |[Documentation](./capabilities#event-widget-rendered)|
60
+
47
61
### targets
48
62
49
63
`targets` is a key/value object that holds the available targets that can be customized on LumApps. This variable allows developers to avoid figuring out which ids to use in order to customize a specific target, and it also defines the available targets that can be customized. As of now, these are the values for this object:
@@ -1174,6 +1188,20 @@ Contains two `Promises`, one for the main navigation and another one for the sub
1174
1188
|`navigationItem.title`| Key/value where the key is a language id and the value is the title for the item in that language. This value contains the text that should be displayed on the navigation item. It takes into consideration the title of the item to display and if there is a specific override for that item's title |`Record<string, string>`|
1175
1189
|`navigationItem.slug`| Key/value where the key is a language id and the value is the slug for the item in that language. |`Record<string, string>`|
1176
1190
1191
+
### on
1192
+
```js
1193
+
window.lumapps.customize(({ on, events }) => {
1194
+
on(events, (props) => {
1195
+
// Retrieve props based on a specific event and execute additional customisations.
1196
+
});
1197
+
});
1198
+
```
1199
+
1200
+
`on` is a function that will be called each time a user perform a specific action or a component is rendered depending on the event. This callback is ideal if you need to trigger additional customisations based on user actions
1201
+
across the entire platform, or if you need to communicate information between customizable components.
1202
+
1203
+
The `props` parameter will have information depending on the event type. For a full list of all events, please refer to the [documentation](./api#events).
`onNavigation` is a function that will be called on each navigation. It receives the following parameters:
1189
-
-`currentPage`: Id of the current page.
1216
+
`onNavigation` is a function that will be called on each navigation. **This function is now deprecated**. Please `on` function with the [Navigation event](./api#eventsnavigation) instead.
1190
1217
1191
-
**Limitations and best practices**
1192
-
- This specific function should be used for tracking purposes as well as triggering other external services. It should not be used in combination with the `render` function, since this is not intended to work by design. Targets and placement should already help in rendering customizations on specific pages.
|`props.searchQuery`| Query typed by the user. |`string`|
1225
+
|`widget.suggestions`| Displayed suggestions. Contains label, counterClick, type and siteId |`object[]`|
1226
+
1227
+
#### events.SEARCH_FILTER
1202
1228
1203
-
`onWidgetRendered` is a function that will be called each time a widget is rendered on the page. This callback is ideal if you need to trigger additional customisations for a specific widget
1229
+
Event triggered each time the user interacts with the search filters. Please find below the props available for this event.
|`props.filteredResultCount`| Number of results available with the current filters applied (if any). |`number`|
1234
+
|`props.query`| Current query used to display search results |`string`|
1235
+
|`props.filters`| List of filters available. Contains id, label, value (all selected values) and choices (all available choices for a given filter) |`object[]`|
1236
+
1237
+
#### events.SEARCH_RESULT
1238
+
1239
+
Event triggered each time the user makes a search query. Please find below the props available for this event.
|`props.filteredResultCount`| Number of results available with the current filters applied (if any). |`number`|
1244
+
|`props.query`| Current query used to display search results |`string`|
1245
+
|`props.selectedFilters`| List of filters currently applied. Contains id, label, value (all selected values) and choices (all available choice for a given filter) |`object[]`|
1246
+
|`props.selectedTabInfo`| Information for the current search tab. Contains label and totalResultCount |`object[]`|
1247
+
|`props.results`| Information for the current search tab. Contains label and totalResultCount |`object[]`|
1248
+
1249
+
#### events.SEARCH_SORT
1250
+
1251
+
Event triggered each time the user makes apply a new sort order. Please find below the props available for this event.
|`props.sortOrders`| List of all sort values available. Contains a value and a label |`object[]`|
1259
+
1260
+
#### events.WIDGET_RENDERED
1261
+
1262
+
Event triggered each time a widget is rendered on the page. This event is ideal if you need to trigger additional customisations for a specific widget
1204
1263
across the entire platform, or if you need to communicate information between widgets.
1205
1264
1206
1265
The `widget` parameter will have basic information of the rendered widget, plus additional information depending on the widget type
@@ -1220,7 +1279,19 @@ The `widget` parameter will have basic information of the rendered widget, plus
1220
1279
**Limitations and best practices**
1221
1280
- LumApps widgets are rendered in a lazy fashion, meaning that they are rendered depending whether they are visible on your current viewport or not. This means that when you visit a content, `onWidgetRendered` will be executed for the widgets that are visible on the viewport, and when the user starts scrolling, `onWidgetRendered` will be executed after those widgets have loaded.
1222
1281
-`widget.items` can contain information that you can use in order to retrieve information from the rendered items on the given widget. However, it is worth mentioning that these items ARE NOT stable and can suffer changes at any time. Please consider this while developing any of your features. Only the properties documented in this section are considered stable.
1223
-
- This function is only supported on contents compatible with our next gen interface (`NGI`) system
1282
+
- This event is only supported on contents compatible with our next gen interface (`NGI`) system
1283
+
1284
+
#### events.NAVIGATION
1285
+
1286
+
It is an event that will be called on each navigation. It receives the following parameters:
1287
+
-`currentPage`: Id of the current page.
1288
+
1289
+
**Limitations and best practices**
1290
+
- This specific event should be used for tracking purposes as well as triggering other external services. It should not be used in combination with the `render` function, since this is not intended to work by design. Targets and placement should already help in rendering customizations on specific pages.
1291
+
1292
+
### on widget rendered
1293
+
1294
+
`onWidgetRendered` is a function that will be called each time a widget is rendered on the page. **This function is now deprecated**. Please `on` function with the [Widget rendered event](./api#eventswidget_rendered) instead.
Copy file name to clipboardExpand all lines: docs/javascript/capabilities.md
+40Lines changed: 40 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -717,3 +717,43 @@ Dynamic target that allows customizing the surroundings of a [widget](https://do
717
717
#### Use cases
718
718
719
719
-[Adding a customization to a widget](./use-cases#adding-a-customization-to-a-widget)
720
+
721
+
## Listening to events
722
+
723
+
The Customizations API allows, among other things, developers to listen predefined events on several sections of their sites. One of the goals of this API is to expose set of props based on user actions that can be easily used for instance for component customization in order to render additional components in some specific cases while reusing the Customization API `render` function.
724
+
725
+
In order to understand the possibilities that we have with this API, we need to first define the different elements that compose a `Event`. These components are:
726
+
-**Event**: This is the event that we want to use as reference for our customization. It is to be noted that there is a predefined list of events that are marked as [events](./api.md#events).
727
+
728
+
-**Callback**: This is where props from a given event can be retrieved. Each events has its own set of props that can be used for rendering a custom components based on props values or send tracking events to collect data on users actions. Using this capabilities it becomes possible to have one component communicating with another one.
729
+
730
+
As an example, inserting the following code in your LumApps site will display an icon in the search tab based on the number of result type filters selected:
731
+
732
+
```js
733
+
window.lumapps.customize(({ on, events, render, placement, targets, components }) => {
0 commit comments