Skip to content

Commit

Permalink
feat: support adding global attributes when initializing SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu-xiaowei authored Oct 27, 2023
1 parent 617ee9f commit e41333f
Show file tree
Hide file tree
Showing 5 changed files with 305 additions and 144 deletions.
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,29 @@ ClickstreamAnalytics.setUserAttributes({
When opening for the first time after integrating the SDK, you need to manually set the user attributes once, and current login user's attributes will be cached in localStorage, so the next time browser open you don't need to set all user's attribute again, of course you can use the same api `ClickstreamAnalytics.setUserAttributes()` to update the current user's attribute when it changes.

#### Add global attribute

```typescript
ClickstreamAnalytics.setGlobalAttributes({
_traffic_source_medium: "Search engine",
_traffic_source_name: "Summer promotion",
level: 10
});
```
It is recommended to set global attributes after each SDK initialization, global attributes will be included in all events that occur after it is set.
1. Add global attributes when initializing the SDK

```typescript
ClickstreamAnalytics.init({
appId: "your appId",
endpoint: "https://example.com/collect",
globalAttributes:{
_traffic_source_medium: "Search engine",
_traffic_source_name: "Summer promotion",
}
});
```

2. Add global attributes after initializing the SDK

``` typescript
ClickstreamAnalytics.setGlobalAttributes({
_traffic_source_medium: "Search engine",
level: 10,
});
```

It is recommended to set global attributes when initializing the SDK, global attributes will be included in all events that occur after it is set, you also can remove a global attribute by setting its value to `null`.

#### Record event with items

Expand Down
Loading

0 comments on commit e41333f

Please sign in to comment.