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

EventsSDK: Support Custom Actions in EventPayload #72

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/analytics.action.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The action types accepted by the Analytics Events API.
<b>Signature:</b>

```typescript
export declare type Action = 'ADD_TO_CART' | 'ALL_TAB_NAVIGATION' | 'APPLY' | 'AUTO_COMPLETE_SELECTION' | 'BACKWARD_PAGINATE' | 'BOOK' | 'BRAND_ICON' | 'CALL_TO_ACTION' | 'CASE_START' | 'CASE_SUBMITTED' | 'CHAT_IMPRESSION' | 'CHAT_LINK_CLICK' | 'CHAT_RESPONSE' | 'COLLAPSE' | 'DIRECTIONS' | 'EVENT' | 'EXPAND' | 'FEATURED_MESSAGE' | 'FILTERING_WITHIN_SECTION' | 'FORWARD_PAGINATE' | 'HEADER_LINKS' | 'ITEM_IN_LIST' | 'MAP_CARD' | 'MAP_PIN' | 'MENU' | 'MESSAGE' | 'ORDER' | 'PAGINATE' | 'PHONE' | 'POST' | 'PRESET_PROMPT' | 'PRODUCT' | 'PROFILE' | 'QUESTION_FOCUS' | 'QUESTION_SUBMIT' | 'REMOVED_FILTER' | 'REVIEW' | 'SCROLL_TO_BOTTOM_OF_PAGE' | 'SEARCH_BAR_IMPRESSION' | 'SEARCH_CLEAR_BUTTON' | 'THUMBS_DOWN' | 'THUMBS_UP' | 'TICKET_URL' | 'TITLE' | 'VERTICAL_TAB_NAVIGATION' | 'VERTICAL_VIEW_ALL' | 'VOICE_START' | 'VOICE_STOP' | 'WEBSITE';
export declare type Action = `C_${string}` | `c_${string}` | 'ADD_TO_CART' | 'ALL_TAB_NAVIGATION' | 'APPLY' | 'AUTO_COMPLETE_SELECTION' | 'BACKWARD_PAGINATE' | 'BOOK' | 'BRAND_ICON' | 'CALL_TO_ACTION' | 'CASE_START' | 'CASE_SUBMITTED' | 'CHAT_IMPRESSION' | 'CHAT_LINK_CLICK' | 'CHAT_RESPONSE' | 'COLLAPSE' | 'DIRECTIONS' | 'EVENT' | 'EXPAND' | 'FEATURED_MESSAGE' | 'FILTERING_WITHIN_SECTION' | 'FORWARD_PAGINATE' | 'HEADER_LINKS' | 'ITEM_IN_LIST' | 'MAP_CARD' | 'MAP_PIN' | 'MENU' | 'MESSAGE' | 'ORDER' | 'PAGINATE' | 'PHONE' | 'POST' | 'PRESET_PROMPT' | 'PRODUCT' | 'PROFILE' | 'QUESTION_FOCUS' | 'QUESTION_SUBMIT' | 'REMOVED_FILTER' | 'REVIEW' | 'SCROLL_TO_BOTTOM_OF_PAGE' | 'SEARCH_BAR_IMPRESSION' | 'SEARCH_CLEAR_BUTTON' | 'THUMBS_DOWN' | 'THUMBS_UP' | 'TICKET_URL' | 'TITLE' | 'VERTICAL_TAB_NAVIGATION' | 'VERTICAL_VIEW_ALL' | 'VOICE_START' | 'VOICE_STOP' | 'WEBSITE';
```
2 changes: 1 addition & 1 deletion docs/analytics.eventpayload.action.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## EventPayload.action property

The user action which caused the event, e.g. ADD\_TO\_CART or THUMBS\_UP
The user action which caused the event, e.g. ADD\_TO\_CART, THUMBS\_UP, C\_CUSTOM\_ACTION

<b>Signature:</b>

Expand Down
2 changes: 1 addition & 1 deletion docs/analytics.eventpayload.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface EventPayload

| Property | Type | Description |
| --- | --- | --- |
| [action](./analytics.eventpayload.action.md) | [Action](./analytics.action.md) | The user action which caused the event, e.g. ADD\_TO\_CART or THUMBS\_UP |
| [action](./analytics.eventpayload.action.md) | [Action](./analytics.action.md) | The user action which caused the event, e.g. ADD\_TO\_CART, THUMBS\_UP, C\_CUSTOM\_ACTION |
| [authorization?](./analytics.eventpayload.authorization.md) | string | <i>(Optional)</i> The authorization token for the request. This will be setup from the Key or Bearer in the config. |
| [bot?](./analytics.eventpayload.bot.md) | boolean | <i>(Optional)</i> Whether the event is the result of bot activity. |
| [browserAgent?](./analytics.eventpayload.browseragent.md) | { browser?: string; browserVersion?: string; os?: string; osVersion?: string; device?: string; deviceClass?: string; userAgent?: string; } | <i>(Optional)</i> Information about the visitors device and browser. |
Expand Down
2 changes: 1 addition & 1 deletion etc/analytics.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```ts

// @public
export type Action = 'ADD_TO_CART' | 'ALL_TAB_NAVIGATION' | 'APPLY' | 'AUTO_COMPLETE_SELECTION' | 'BACKWARD_PAGINATE' | 'BOOK' | 'BRAND_ICON' | 'CALL_TO_ACTION' | 'CASE_START' | 'CASE_SUBMITTED' | 'CHAT_IMPRESSION' | 'CHAT_LINK_CLICK' | 'CHAT_RESPONSE' | 'COLLAPSE' | 'DIRECTIONS' | 'EVENT' | 'EXPAND' | 'FEATURED_MESSAGE' | 'FILTERING_WITHIN_SECTION' | 'FORWARD_PAGINATE' | 'HEADER_LINKS' | 'ITEM_IN_LIST' | 'MAP_CARD' | 'MAP_PIN' | 'MENU' | 'MESSAGE' | 'ORDER' | 'PAGINATE' | 'PHONE' | 'POST' | 'PRESET_PROMPT' | 'PRODUCT' | 'PROFILE' | 'QUESTION_FOCUS' | 'QUESTION_SUBMIT' | 'REMOVED_FILTER' | 'REVIEW' | 'SCROLL_TO_BOTTOM_OF_PAGE' | 'SEARCH_BAR_IMPRESSION' | 'SEARCH_CLEAR_BUTTON' | 'THUMBS_DOWN' | 'THUMBS_UP' | 'TICKET_URL' | 'TITLE' | 'VERTICAL_TAB_NAVIGATION' | 'VERTICAL_VIEW_ALL' | 'VOICE_START' | 'VOICE_STOP' | 'WEBSITE';
export type Action = `C_${string}` | `c_${string}` | 'ADD_TO_CART' | 'ALL_TAB_NAVIGATION' | 'APPLY' | 'AUTO_COMPLETE_SELECTION' | 'BACKWARD_PAGINATE' | 'BOOK' | 'BRAND_ICON' | 'CALL_TO_ACTION' | 'CASE_START' | 'CASE_SUBMITTED' | 'CHAT_IMPRESSION' | 'CHAT_LINK_CLICK' | 'CHAT_RESPONSE' | 'COLLAPSE' | 'DIRECTIONS' | 'EVENT' | 'EXPAND' | 'FEATURED_MESSAGE' | 'FILTERING_WITHIN_SECTION' | 'FORWARD_PAGINATE' | 'HEADER_LINKS' | 'ITEM_IN_LIST' | 'MAP_CARD' | 'MAP_PIN' | 'MENU' | 'MESSAGE' | 'ORDER' | 'PAGINATE' | 'PHONE' | 'POST' | 'PRESET_PROMPT' | 'PRODUCT' | 'PROFILE' | 'QUESTION_FOCUS' | 'QUESTION_SUBMIT' | 'REMOVED_FILTER' | 'REVIEW' | 'SCROLL_TO_BOTTOM_OF_PAGE' | 'SEARCH_BAR_IMPRESSION' | 'SEARCH_CLEAR_BUTTON' | 'THUMBS_DOWN' | 'THUMBS_UP' | 'TICKET_URL' | 'TITLE' | 'VERTICAL_TAB_NAVIGATION' | 'VERTICAL_VIEW_ALL' | 'VOICE_START' | 'VOICE_STOP' | 'WEBSITE';

// @public
export function analytics(config: AnalyticsConfig): AnalyticsEventService;
Expand Down
2 changes: 2 additions & 0 deletions src/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @public
*/
export type Action =
| `C_${string}`
| `c_${string}`
| 'ADD_TO_CART'
| 'ALL_TAB_NAVIGATION'
| 'APPLY'
Expand Down
2 changes: 1 addition & 1 deletion src/EventPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Action } from './Action';
* @public
*/
export interface EventPayload {
/** The user action which caused the event, e.g. ADD_TO_CART or THUMBS_UP */
/** The user action which caused the event, e.g. ADD_TO_CART, THUMBS_UP, C_CUSTOM_ACTION */
action: Action;
/** The authorization token for the request. This will be setup from the Key or Bearer in the config. */
authorization?: string;
Expand Down
8 changes: 4 additions & 4 deletions tests/AnalyticsEventReporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Test report function', () => {
});

const res = await reporter.report({
action: 'APPLY',
action: 'C_CUSTOM_ACTION',
destinationUrl: 'https://google.com',
});

Expand All @@ -83,7 +83,7 @@ describe('Test report function', () => {
expect(mockPostWithBeacon).toHaveBeenCalledWith(
'https://eu.yextevents.com/accounts/me/events',
{
action: 'APPLY',
action: 'C_CUSTOM_ACTION',
authorization: 'KEY validKey',
clientSdk: {
ANALYTICS: '1.0.0-beta.0'
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('Test report function', () => {
env: EnvironmentEnum.Sandbox,
};
const reporter = new AnalyticsEventReporter(config).with({
action: 'ADD_TO_CART',
action: 'c_lowercase_custom_action',
referrerUrl: 'https://yext.com',
count: 5,
});
Expand All @@ -139,7 +139,7 @@ describe('Test report function', () => {
expect(mockPostWithFetch).toHaveBeenCalledWith(
'https://sbx.us.yextevents.com/accounts/me/events',
{
action: 'ADD_TO_CART',
action: 'c_lowercase_custom_action',
authorization: 'Bearer bearerToken',
clientSdk: {
ANALYTICS: '1.0.0-beta.0'
Expand Down
4 changes: 2 additions & 2 deletions tests/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('Merge Function Test', () => {

const unaffectedEvent1: PartialPayload = JSON.parse(JSON.stringify(event1));
const event2 = {
action: 'ADD_TO_CART',
action: 'C_CUSTOM_ACTION',
browserAgent: {
os: undefined,
browser: 'Safari',
Expand All @@ -99,7 +99,7 @@ describe('Merge Function Test', () => {
const result = merge(event1, event2);

const expected: EventPayload = {
action: 'ADD_TO_CART',
action: 'C_CUSTOM_ACTION',
browserAgent: {
browser: 'Safari',
device: 'MacBook Air',
Expand Down