Skip to content

Commit 813caa9

Browse files
zhu-xiaoweixiaoweii
andauthored
feat: add export type for item (#18)
Co-authored-by: xiaoweii <xiaoweii@amazom.com>
1 parent 7cb9841 commit 813caa9

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Clickstream Web SDK can help you easily collect and report events from browser t
66

77
The SDK relies on the Amplify for JS SDK Core Library and is developed according to the Amplify AnalyticsProvider interface. In addition, we've added features that automatically collect common user events and attributes (e.g., page view, first open) to simplify data collection for users.
88

9+
Visit our [Documentation site](https://awslabs.github.io/clickstream-analytics-on-aws/en/sdk-manual/web/) to learn more about Clickstream Web SDK.
10+
911
## Integrate SDK
1012

1113
### Include SDK
@@ -37,11 +39,18 @@ Add the following code where you need to record event.
3739
```typescript
3840
import { ClickstreamAnalytics } from '@aws/clickstream-web';
3941

40-
ClickstreamAnalytics.record({ name: 'albumVisit' });
42+
// record event with attributes
4143
ClickstreamAnalytics.record({
42-
name: 'buttonClick',
43-
attributes: { _channel: 'SMS', Successful: true }
44+
name: 'add_to_cart',
45+
attributes: {
46+
event_category: 'shoes',
47+
currency: 'CNY',
48+
value: 279.9,
49+
}
4450
});
51+
52+
//record event with name
53+
ClickstreamAnalytics.record({ name: 'button_click' });
4554
```
4655

4756
#### Login and logout
@@ -72,18 +81,21 @@ Current login user's attributes will be cached in localStorage, so the next time
7281
You can add the following code to log an event with an item.
7382

7483
```typescript
75-
import { ClickstreamAnalytics } from '@aws/clickstream-web';
84+
import { ClickstreamAnalytics, Item } from '@aws/clickstream-web';
7685

77-
const item_product = {
78-
id: '1',
86+
const itemBook: Item = {
87+
id: '123',
7988
name: 'Nature',
8089
category: 'book',
81-
price: 56.5,
90+
price: 99,
8291
};
8392
ClickstreamAnalytics.record({
84-
name: 'buttonClick',
85-
attributes: { _channel: 'SMS', Successful: true },
86-
items: [item_product],
93+
name: 'view_item',
94+
attributes: {
95+
currency: 'USD',
96+
event_category: 'recommended',
97+
},
98+
items: [itemBook],
8799
});
88100
```
89101

@@ -95,8 +107,7 @@ When you are in batch mode, you can still send an event immediately by setting t
95107
import { ClickstreamAnalytics } from '@aws/clickstream-web';
96108

97109
ClickstreamAnalytics.record({
98-
name: 'immediateEvent',
99-
attributes: { url: 'https://example.com' },
110+
name: 'button_click',
100111
isImmediate: true,
101112
});
102113
```

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
*/
1313

1414
export { ClickstreamAnalytics } from './ClickstreamAnalytics';
15-
export { PageType, SendMode } from './types';
15+
export { PageType, SendMode, Item } from './types';

0 commit comments

Comments
 (0)