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

feat: support adding global attributes when initializing SDK #30

Merged
merged 2 commits into from
Oct 27, 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
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
Loading