forked from opensearch-project/documentation-website
-
Notifications
You must be signed in to change notification settings - Fork 0
UBI docs consolidation #1
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d100735
gathering potential documentation attempts
RasonJ 0596e47
considering the dashboard tutorial
RasonJ 555d72b
place holder for js data structure usage
RasonJ a89ae40
data-structures placeholder
RasonJ 19d1516
Updating index links
RasonJ c1085c1
adding old doc to be merged
RasonJ cf9e128
Starting to link things together
RasonJ e26b8e5
fix broken link
RasonJ 92d84b1
respond to vale
epugh 84f9395
more vale violations
epugh e390422
name files consistently with docs site and fix links.
epugh 46cc0d9
vale
epugh 4e2a617
Minor tweaks. Moved Ubi under SEARCH.
RasonJ c251237
add label for versining of spec and OS version
epugh 2a39c1d
try to sort out vale error
epugh 982e334
Converting mermaid diagrams to png's
RasonJ 9402dbd
Updating query_id mermaid code
RasonJ db2546e
Better way to ignore the mermaid scripts in the md files
RasonJ cec25c9
description updates
RasonJ 1f0fa78
schema.md updating (still need to update the mermaid diagram)
RasonJ ad1b92a
schema updates
RasonJ 6f08485
chase some more vale warnings.
epugh c9edc86
updates
RasonJ 6626bb1
Merge branch 'ubi-docs-consolidation' of https://github.com/o19s/docu…
RasonJ 736bf69
Getting there. TODO's indicate a few loose ends to tie
RasonJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| --- | ||
| layout: default | ||
| title: Client Data structures old | ||
| parent: User behavior insights | ||
| has_children: false | ||
| nav_order: 7 | ||
| --- | ||
|
|
||
| The datastructures that we use for indexing events adhere to the following nested structure that aligns with the Ubi schemas. See the [schemas](.././schemas.md) for descriptions and examples of the following fields. | ||
|
|
||
| `struct UbiEvent {` | ||
| - application | ||
| - action_name | ||
| - user_id | ||
| - query_id | ||
| - session_id | ||
| - page_id | ||
| - message_type | ||
| - timestamp | ||
| - <details> | ||
| <summary>event_attributes {</summary> | ||
| <p> | ||
|
|
||
| - <details> | ||
| <summary>position {</summary> | ||
|
|
||
| - ordinal | ||
| - x | ||
| - y | ||
| - trail | ||
| } | ||
| </details> | ||
| - <details> | ||
| <summary>object {</summary> | ||
|
|
||
| - internal_id | ||
| - object_id | ||
| - object_type | ||
| - description | ||
| - object_details / | ||
| - object_details.json | ||
| } | ||
| </details> | ||
| } | ||
| </details>} | ||
| `}` | ||
|
|
||
| Typescript versions of these classes can be found in [ts/UbiEvent.ts](./ts/UbiEvent.ts). | ||
|
|
||
| Example javascript code: | ||
| ```js | ||
| // basic message format | ||
| let e = new UbiEvent('chorus', 'add_to_cart', user_id, query_id); | ||
| e.message_type = 'PURCHASE'; | ||
| e.message = item.title + ' (' + item.primary_ean + ')'; | ||
| e.session_id = session_id; | ||
| e.page_id = window.location.pathname; | ||
|
|
||
| // adding custom data fields | ||
| e.event_attributes['user_info'] = {user_name:'TheJackal', phone:'555-555-1234'} | ||
|
|
||
| // associate the object added to the cart | ||
| e.event_attributes.object = new UbiObject('product', item.primary_ean, item.title, item); | ||
|
|
||
| // save any click info | ||
| e.event_attributes.position = new UbiPosition({x:event.clientX, y:event.clientY}); | ||
|
|
||
| // index here | ||
| console.log(e.toJson()); | ||
| ``` | ||
|
|
||
| With very similar [python data structures](./py/ubi.py): | ||
| ```python | ||
| if __name__ == '__main__': | ||
| e = UbiEvent(application='chorus', action_name='add_to_cart', | ||
| user_id='USER-' + guuid(), query_id='QUERY-ID-'+ guuid(), session_id='SESSION-' + guuid(), | ||
| # object added to the cart | ||
| object= UbiObject( | ||
| object_type='product', | ||
| object_id='ISBN-' + guuid(), | ||
| description='a very nice book', details={'product_data':'random product data'} | ||
| ) | ||
| ) | ||
| e.message_type = 'PURCHASE' | ||
|
|
||
| # adding custom attribute fields | ||
| e.event_attributes['user_info'] = {'user_name':'TheJackal', 'phone':'555-555-1234'} | ||
|
|
||
| # product position information | ||
| e.event_attributes.position = UbiPosition(ordinal=3, x=250, y=400) | ||
|
|
||
| print(e.to_json()) | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| --- | ||
| layout: default | ||
| title: Client data structures | ||
| parent: User behavior insights | ||
| has_children: false | ||
| nav_order: 7 | ||
| --- | ||
|
|
||
| # Sample data structures | ||
| The data structures below can be used to create events that follow the [UBI event schema](schemas.md). | ||
|
|
||
| The developer just needs to decide on implementations for the following functions: | ||
| - `getUserId()` | ||
| - `getQueryId()` | ||
| - `getSessionId()` | ||
| - `getPageId()`- e.g.: | ||
| ```js | ||
| function getPageId(){ | ||
| return location.pathname; | ||
| } | ||
| ``` | ||
| Other sample implementations can be found [here](#TODO). | ||
|
|
||
| ```js | ||
| /********************************************************************************************* | ||
| * Ubi Event data structures | ||
| * The following structures help ensure adherence to the UBI event schema | ||
| *********************************************************************************************/ | ||
|
|
||
| export class UbiEventData { | ||
| constructor(type, id=null, description=null, details=null) { | ||
| this.object_type = type; | ||
| this.object_id = id; | ||
| this.description = description; | ||
| this.object_detail = details; | ||
|
|
||
| //override if using key_field's and values | ||
| this.key_value = id; | ||
| } | ||
| } | ||
| export class UbiPosition{ | ||
| constructor({ordinal=null, x=null, y=null, trail=null}={}) { | ||
| this.ordinal = ordinal; | ||
| this.x = x; | ||
| this.y = y; | ||
| this.trail = trail; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| export class UbiEventAttributes { | ||
| /** | ||
| * Attributes, other than `object` or `position` should be in the form of | ||
| * attributes['item1'] = 1 | ||
| * attributes['item2'] = '2' | ||
| * | ||
| * The object member is reserved for further, relevant object payloads or classes | ||
| */ | ||
| constructor({attributes={}, object=null, position=null}={}) { | ||
| if(attributes != null){ | ||
| Object.assign(this, attributes); | ||
| } | ||
| if(object != null && Object.keys(object).length > 0){ | ||
| this.object = object; | ||
| } | ||
| if(position != null && Object.keys(position).length > 0){ | ||
| this.position = position; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| export class UbiEvent { | ||
| constructor(action_name, {message=null, event_attributes={}, data_object={}}={}) { | ||
| this.action_name = action_name; | ||
| this.user_id = getUserId(); | ||
| this.query_id = getQueryId(); | ||
| this.session_id = getSessionId(); | ||
| this.page_id = getPageId(); | ||
| this.timestamp = Date.now(); | ||
|
|
||
| this.message_type = 'INFO'; | ||
| if( message ) | ||
| this.message = message; | ||
|
|
||
| this.event_attributes = new UbiEventAttributes({attributes:event_attributes, object:data_object}); | ||
| } | ||
|
|
||
| /** | ||
| * Use to suppress null objects in the json output | ||
| * @param key | ||
| * @param value | ||
| * @returns | ||
| */ | ||
| static replacer(key, value){ | ||
| if(value == null || | ||
| (value.constructor == Object && Object.keys(value).length === 0)) { | ||
| return undefined; | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @returns json string | ||
| */ | ||
| toJson() { | ||
| return JSON.stringify(this, UbiEvent.replacer); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| # Sample Usage | ||
|
|
||
| ```js | ||
| export async function logDwellTime(action_name, page, seconds){ | ||
| console.log(`${page} => ${seconds}`); | ||
| let e = new UbiEvent(action_name, { | ||
| message:`On page ${page} for ${seconds} seconds`, | ||
| event_attributes:{dwell_seconds:seconds}, | ||
| data_object:TimeMe | ||
| }); | ||
| logEvent(e); | ||
| } | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.