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

Add order continue button clicked event and pass handled events #16

Merged
merged 1 commit into from
Oct 6, 2024
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
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,25 @@ topper.initialize({ bootstrapToken: <bootstrap token>, config: { variant: TOPPER

Listen to single events like order placed or all events:

Single event:

```javascript
// Single event.
const topper = new TopperWebSdk();

topper.on(TOPPER_EVENTS.ORDER_PLACED, ({ data }) => {});

// All events.
topper.initialize({ bootstrapToken: <bootstrap token> });
```

All events:

```javascript
const topper = new TopperWebSdk();

topper.on(TOPPER_EVENTS.ALL, ({ data, name }) => {});
```

topper.initialize({ bootstrapToken: <bootstrap token> });
```

### Multiple instances

Expand All @@ -98,11 +110,11 @@ const topperIframe2 = new TopperWebSdk({ variant: TOPPER_VARIANTS.IFRAME });
const topperIframe1Element = document.getElementById('topper-iframe-1');
const topperIframe2Element = document.getElementById('topper-iframe-2');

topperIframe1.initialize({ bootstrapToken: <bootstrap token>, iframeElement: topperIframe1Element });
topperIframe2.initialize({ bootstrapToken: <bootstrap token>, iframeElement: topperIframe2Element });

topperIframe1.on(TOPPER_WEB_SDK_EVENTS.ORDER_PLACED, ({ data }) => {});
topperIframe2.on(TOPPER_WEB_SDK_EVENTS.ORDER_PLACED, ({ data }) => {});

topperIframe1.initialize({ bootstrapToken: <bootstrap token>, iframeElement: topperIframe1Element });
topperIframe2.initialize({ bootstrapToken: <bootstrap token>, iframeElement: topperIframe2Element });
```

### Triggering Events
Expand Down
1 change: 1 addition & 0 deletions src/enums/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum Events {
ALL = '*',
ORDER_CONTINUE_BUTTON_CLICKED = 'orderContinueButtonClicked',
ORDER_PLACED = 'orderPlaced',
WIDGET_CONTINUE_BUTTON_CLICKED = 'widgetContinueButtonClicked'
}
8 changes: 5 additions & 3 deletions src/topper-web-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ class TopperWebSdk {
const queryParams = {
bt: bootstrapToken,
...(isTopperSelfEmbed && { embed: 1 }),
...(this.config.locale && { locale: this.config.locale }),
...(this.config.theme && { theme: this.config.theme }),
...(this.eventHandlers &&
Object.keys(this.eventHandlers).length && { events: Object.keys(this.eventHandlers).join(',') }),
...(this.config.is_android_app && { is_android_app: 1 }),
...(this.config.is_ios_app && { is_ios_app: 1 })
...(this.config.is_ios_app && { is_ios_app: 1 }),
...(this.config.locale && { locale: this.config.locale }),
...(this.config.theme && { theme: this.config.theme })
};

const url = queryString.stringifyUrl({ query: queryParams, url: `${baseUrl}/` });
Expand Down