Skip to content

Commit

Permalink
fix!: visitor id disabled by default (#199)
Browse files Browse the repository at this point in the history
Since we are defaulting to disable (whereas it was previously enabled), we mark the commit as breaking.
To re-enable this functionality; manually run `confidence.track(visitorIdentity())`
  • Loading branch information
nicklasl authored Sep 11, 2024
1 parent 85b8b15 commit aea60c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
18 changes: 17 additions & 1 deletion packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,30 @@ confidence.track('event_name', { 'message-detail1': 'something interesting' });
### Auto track

Confidence supports automatically tracking certain things out of the box and supports API's for you to extend that functionality.

#### Visitor ID (web)

Confidence can provide all flag resolves and tracking events with a browser specific identifier. We call this `visitor_id`.
The `visitor_id` is stored in a cookie. To add a generated `visitor_id` to the context, use the following:

```ts
import { visitorIdentity } from './trackers';
confidence.track(visitorIdentity());
```

#### Page Views (web)

Confidence can automatically track `page views` on events such as `load`, `pushState`, `replaceState`, `popstate` and `hashchange`.
To automatically track `page views`, use the following:

```ts
import { Confidence, pageViews } from '@spotify-confidence/sdk';
confidence.track(pageViews());
```

and to automatically track events containing web vitals data, use:
#### Web vitals (web)

To automatically send tracking events containing [web vitals data](https://web.dev/articles/vitals), use:

```ts
import { Confidence, webVitals } from '@spotify-confidence/sdk';
Expand Down
7 changes: 1 addition & 6 deletions packages/sdk/src/Confidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Context } from './context';
import { Logger } from './logger';
import { FlagEvaluation, FlagResolver, State, StateObserver } from './flags';
import { SdkId } from './generated/confidence/flags/resolver/v1/types';
import { visitorIdentity } from './trackers';
import { Trackable } from './Trackable';
import { Closer } from './Closer';
import { Subscribe, Observer, subject, changeObserver } from './observing';
Expand Down Expand Up @@ -366,17 +365,13 @@ export class Confidence implements EventSender, Trackable, FlagResolver {
maxOpenRequests: (50 * 1024) / (estEventSizeKb * maxBatchSize),
logger,
});
const root = new Confidence({
return new Confidence({
environment: environment,
flagResolverClient,
eventSenderEngine,
timeout,
logger,
});
if (environment === 'client') {
root.track(visitorIdentity());
}
return root;
}
}

Expand Down

0 comments on commit aea60c4

Please sign in to comment.