Skip to content

Commit 6ba8662

Browse files
committed
Revamping documentations to reflect updates.
UBI has evolved since it was first released in May 2024. This is an update of the documentation. We have introduced an explicit JS client, so we can streamline the documentation by referencing the deployed document.
1 parent 71f95df commit 6ba8662

File tree

4 files changed

+100
-227
lines changed

4 files changed

+100
-227
lines changed

_search-plugins/ubi/data-structures.md

Lines changed: 0 additions & 204 deletions
This file was deleted.

_search-plugins/ubi/index.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ redirect_from:
1111
**Introduced 2.15**
1212
{: .label .label-purple }
1313

14-
**References UBI Specification 1.0.0**
14+
**References UBI Specification 1.2.0**
1515
{: .label .label-purple }
1616

17-
User Behavior Insights (UBI) is a plugin that captures client-side events and queries for the purposes of improving search relevance and the user experience.
18-
It is a causal system, linking a user's query to all of their subsequent interactions with your application until they perform another search.
17+
User Behavior Insights (UBI) is a project for capturing client-side events and queries for the purposes of improving search relevance and the user experience.
18+
It is a *causal* system, linking a user's query to all of their subsequent interactions with your application until they perform another search.
19+
This differs from many systems that infer the linking of search to events through *chronological* sequence.
1920

2021
UBI includes the following elements:
2122
* A machine-readable [schema](https://github.com/o19s/ubi) that faciliates interoperablity of the UBI specification.
2223
* An OpenSearch [plugin](https://github.com/opensearch-project/user-behavior-insights) that facilitates the storage of client-side events and queries.
23-
* A client-side JavaScript [example reference implementation]({{site.url}}{{site.baseurl}}/search-plugins/ubi/data-structures/) that shows how to capture events and send them to the OpenSearch UBI plugin.
24+
* A client-side JavaScript [reference implementation](https://github.com/opensearch-project/user-behavior-insights/tree/main/ubi-javascript-collector/ubi.js) that shows how to capture searches and events.
2425

2526
<!-- vale off -->
2627

@@ -30,7 +31,8 @@ The UBI documentation is organized into two categories: *Explanation and referen
3031

3132
| Link | Description |
3233
| :--------- | :------- |
33-
| [UBI Request/Response Specification](https://github.com/o19s/ubi/) | The industry-standard schema for UBI requests and responses. The current version references UBI Specification 1.0.0. |
34+
| [UBISearch.dev](https://UBISearch.dev) | The User Behavior Insights community website. |
35+
| [UBI Request/Response Specification](https://github.com/o19s/ubi/) | The industry-standard schema for UBI requests and responses. The current version references UBI Specification 1.2.0. |
3436
| [UBI index schema]({{site.url}}{{site.baseurl}}/search-plugins/ubi/schemas/) | Documentation on the individual OpenSearch query and event stores. |
3537

3638

@@ -39,7 +41,7 @@ The UBI documentation is organized into two categories: *Explanation and referen
3941
| Link | Description |
4042
| :--------- | :------- |
4143
| [UBI plugin](https://github.com/opensearch-project/user-behavior-insights) | How to install and use the UBI plugin. |
42-
| [UBI client data structures]({{site.url}}{{site.baseurl}}/search-plugins/ubi/data-structures/) | Sample JavaScript structures for populating the event store. |
44+
| [UBI JavaScript Collector]({{site.url}}{{site.baseurl}}/search-plugins/ubi/ubi-javascript-collector/) | Clientside JavaScript library to capture events. |
4345
| [Example UBI query DSL queries]({{site.url}}{{site.baseurl}}/search-plugins/ubi/dsl-queries/) | How to write queries for UBI data in OpenSearch query DSL. |
4446
| [Example UBI SQL queries]({{site.url}}{{site.baseurl}}/search-plugins/ubi/sql-queries/) | How to write analytic queries for UBI data in SQL. |
4547
| [UBI dashboard tutorial]({{site.url}}{{site.baseurl}}/search-plugins/ubi/ubi-dashboard-tutorial/) | How to build a dashboard containing UBI data. |

_search-plugins/ubi/schemas.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ The User Behavior Insights (UBI) data collection process involves tracking and r
1616

1717
For UBI to function properly, the connections between the following fields must be consistently maintained within an application that has UBI enabled:
1818

19-
- [`object_id`](#object_id) represents an ID for whatever object the user receives in response to a query. For example, if you search for books, it might be an ISBN code of a book, such as `978-3-16-148410-0`.
20-
- [`query_id`](#query_id) is a unique ID for the raw query language executed and the `object_id` values of the _hits_ returned by the user's query.
19+
- [`object_id`](#object_id) represents an ID for whatever object the user receives in response to a query. For example, if you search for books, it might be an ISBN number for a book, such as `978-3-16-148410-0`.
20+
- [`query_id`](#query_id) is a unique ID for the raw query language executed and the `object_id` maps to the primary identifier of the _hits_ returned by the user's query.
2121
- [`client_id`](#client_id) represents a unique query source. This is typically a web browser used by a unique user.
2222
- [`object_id_field`](#object_id_field) specifies the name of the field in your index that provides the `object_id`. For example, if you search for books, the value might be `isbn_code`.
2323
- [`action_name`](#action_name), though not technically an ID, specifies the exact user action (such as `click`, `add_to_cart`, `watch`, `view`, or `purchase`) that was taken (or not taken) for an object with a given `object_id`.
@@ -138,11 +138,11 @@ All underlying query information and results (`object_ids`) are stored in the `u
138138

139139
The `ubi_queries` index [schema](https://github.com/OpenSearch-project/user-behavior-insights/tree/main/src/main/resources/queries-mapping.json) includes the following fields:
140140

141-
- `timestamp` (events and queries): A UNIX timestamp indicating when the query was received.
141+
- `timestamp` (events and queries): A ISO 8601 formatted timestamp indicating when the query was received.
142142

143-
- `query_id` (events and queries): The unique ID of the query provided by the client or generated automatically. Different queries with the same text generate different `query_id` values.
143+
- `query_id` (events and queries): The unique ID of the query provided by the client or generated by the search engine. Different queries with the same text generate different `query_id` values.
144144

145-
- `client_id` (events and queries): A user/client ID provided by the client application.
145+
- `client_id` (events and queries): A client ID provided by the client application.
146146

147147
- `query_response_objects_ids` (queries): An array of object IDs. An ID can have the same value as the `_id`, but it is meant to be the externally valid ID of a document, item, or product.
148148

@@ -169,7 +169,7 @@ The following are the predefined, minimal fields in the `ubi_events` index:
169169
<p id="query_id"> </p>
170170

171171
- `query_id` (size 100): The unique identifier of a query, which is typically a UUID but can be any string.
172-
The `query_id` is either provided by the client or generated at index time by the UBI plugin. The `query_id` values in both the **UBI queries** and **UBI events** indexes must be consistent.
172+
The `query_id` is either provided by the client or generated at query time by the UBI plugin. The `query_id` values in both the **UBI queries** and **UBI events** indexes must be consistent.
173173

174174
<p id="client_id"> </p>
175175

@@ -193,18 +193,12 @@ The following are the predefined, minimal fields in the `ubi_events` index:
193193

194194
- `event_attributes.position.ordinal`: Tracks the list position that a user can select (for example, selecting the third element can be described as `event{onClick, results[4]}`).
195195

196-
- `event_attributes.position.{x,y}`: Tracks x and y values defined by the client.
197-
198-
- `event_attributes.position.page_depth`: Tracks the page depth of the results.
199-
200-
- `event_attributes.position.scroll_depth`: Tracks the scroll depth of the page results.
201-
202-
- `event_attributes.position.trail`: A text field that tracks the path/trail that a user took to get to this location.
203-
196+
- `event_attributes.position.xy.{x,y}`: Tracks x and y values defined by the client.
197+
204198
- `event_attributes.object`: Contains identifying information about the object returned by the query (for example, a book, product, or post).
205199
The `object` structure can refer to the object by internal ID or object ID. The `object_id` is the ID that links prior queries to this object. This field comprises the following subfields:
206200

207-
- `event_attributes.object.internal_id`: A unique ID that OpenSearch can use to internally index the object, for example, the `_id` field in the indexes.
201+
- `event_attributes.object.internal_id`: The unique ID that OpenSearch uses to internally index the object, for example, the `_id` field in the indexes.
208202

209203
<p id="object_id">
210204

@@ -214,9 +208,9 @@ The following are the predefined, minimal fields in the `ubi_events` index:
214208

215209
<p id="object_id_field">
216210
217-
- `event_attributes.object.object_id_field`: Indicates the type/class of the object and the name of the search index field that contains the `object_id`.
211+
- `event_attributes.object.object_id_field`: Indicates the type/class of the object and the name of the search index field that contains the `object_id` such as `ssn`, `isbn`, or `ean`.
218212

219-
- `event_attributes.object.description`: An optional description of the object.
213+
- `event_attributes.object.object_type`: An optional readable version of the type/class of the object. For a social e-commerce site, these could include product, user, post, comment and so on.
220214

221215
- `event_attributes.object.object_detail`: Optional additional information about the object.
222216

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
layout: default
3+
title: UBI Javascript Collector
4+
parent: User Behavior Insights
5+
has_children: false
6+
nav_order: 10
7+
---
8+
9+
# UBI Javascript Collector
10+
11+
UBI comes with a very basic JavaScript client that manages the life cycle of the `query_id` for a specific search and can create UBI Event data structures and store them for specific actions.
12+
13+
For more information about the schema, see [UBI index schemas]({{site.url}}{{site.baseurl}}/search-plugins/ubi/schemas/).
14+
15+
We recommend that you refer to the client as a starting point for your own specific needs.
16+
17+
## Installation
18+
19+
The client comes as a single file `ubi.js` and only has a dependency on the `axios` library. Download it from https://github.com/opensearch-project/user-behavior-insights/tree/main/ubi-javascript-collector.
20+
21+
Reference the events and create the client via:
22+
23+
```js
24+
import { UbiEvent } from './ubi';
25+
import { UbiEventAttributes } from './ubi'
26+
import { UbiClient } from './ubi'
27+
28+
const ubiClient = new UbiClient('http://localhost:9200');
29+
```
30+
31+
32+
## Creating an Event
33+
34+
This code snippet is to track adding an item to a shopping cart in an e-commerce application. It utilizes the `UbiEvent` and `UbiEventAttributes` class to encapsulate event details, which can then be sent to the tracking system.
35+
```js
36+
var event = new UbiEvent(
37+
'add_to_cart',
38+
client_id,
39+
session_id,
40+
getQueryId(),
41+
new UbiEventAttributes('product', item.primary_ean, item.title, item),
42+
item.title + ' (' + item.id + ')'
43+
);
44+
```
45+
46+
### Parameters
47+
48+
1. **Event Name**:
49+
- `'add_to_cart'` - This string indicates the type of event being tracked.
50+
51+
2. **Client ID**:
52+
- `client_id` - A variable that holds the unique identifier for the client. This helps in distinguishing between different users or sessions.
53+
54+
3. **Session ID**:
55+
- `session_id` - A variable that contains the unique identifier for the user session. This is used to track user interactions within a specific session.
56+
57+
4. **Query ID**:
58+
- `getQueryId()` - A function call that retrieves the current query ID, which may represent a specific search or interaction context.
59+
60+
5. **UbiEventAttributes**:
61+
- This is an instance of the `UbiEventAttributes` class, which encapsulates additional details about the event:
62+
- **Type**:
63+
- `'product'` - Specifies that the attribute type is related to a product.
64+
- **Primary EAN**:
65+
- `item.primary_ean` - This is the product's unique identifier in EAN format.
66+
- **Title**:
67+
- `item.title` - The name or description of the product.
68+
- **Item**:
69+
- `item` - The complete product object containing all relevant details.
70+
71+
6. **Event Label**:
72+
- `item.title + ' (' + item.id + ')'` - This creates a descriptive label for the event that includes the product title and its unique identifier (ID).
73+
74+
75+
## Tracking the Event
76+
77+
Sending the event to the backend is as simple as:
78+
79+
```js
80+
ubiClient.trackEvent(event);
81+
```

0 commit comments

Comments
 (0)