Skip to content

Commit f083954

Browse files
committed
Fix built-in context typing for newTracker (fix snowplow#1089)
PR snowplow#1090
1 parent 1786c93 commit f083954

6 files changed

Lines changed: 60 additions & 9 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-tracker-core",
5+
"comment": "Fix newTracker built-in context typing",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-tracker-core"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-tracker-core",
5+
"comment": "Added BuiltInContexts type",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-tracker-core"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-tracker",
5+
"comment": "Fix newTracker built-in context typing",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-tracker"
10+
}

libraries/browser-tracker-core/src/tracker/types.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ import {
3737
} from '@snowplow/tracker-core';
3838
import { SharedState } from '../state';
3939

40+
type RequireAtLeastOne<T> = { [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>> }[keyof T];
41+
42+
/* Available built-in contexts */
43+
export type BuiltInContexts =
44+
| RequireAtLeastOne<{
45+
/* Toggles the web_page context */
46+
webPage: boolean;
47+
/* Toggles the session context */
48+
session: boolean;
49+
}>
50+
| Record<string, never>;
51+
4052
/* Configuration for Anonymous Tracking */
4153
export type AnonymousTrackingOptions = boolean | { withSessionTracking?: boolean; withServerAnonymisation?: boolean };
4254
/* Available configurations for different storage strategies */
@@ -139,7 +151,7 @@ export type TrackerConfiguration = {
139151
bufferSize?: number;
140152
/**
141153
* Configure the cross domain linker which will add user identifiers to
142-
* links becaused on the callback
154+
* links on the callback
143155
*/
144156
crossDomainLinker?: (elt: HTMLAnchorElement | HTMLAreaElement) => boolean;
145157
/**
@@ -162,7 +174,7 @@ export type TrackerConfiguration = {
162174
*/
163175
discoverRootDomain?: boolean;
164176
/**
165-
* The storage strategy which the tracker will use for storing user and session identifers
177+
* The storage strategy which the tracker will use for storing user and session identifiers
166178
* and if local storage is allowed for buffering the events
167179
* @defaultValue cookieAndLocalStorage
168180
*/
@@ -189,15 +201,15 @@ export type TrackerConfiguration = {
189201
*/
190202
connectionTimeout?: number;
191203
/**
192-
* Condifugration for Anonymous Tracking
204+
* Configuration for Anonymous Tracking
193205
* @defaultValue false
194206
*/
195207
anonymousTracking?: AnonymousTrackingOptions;
196208
/**
197209
* Use to configure built in contexts
198210
* @defaultValue `{ webPage: true, session: false }`
199211
*/
200-
contexts?: { webPage: boolean; session: boolean };
212+
contexts?: BuiltInContexts;
201213
/**
202214
* Inject plugins which will be evaluated for each event
203215
* @defaultValue []
@@ -432,7 +444,7 @@ export interface BrowserTracker {
432444
newSession: () => void;
433445

434446
/**
435-
* Enable querystring decoration for links pasing a filter
447+
* Enable querystring decoration for links passing a filter
436448
*
437449
* @param crossDomainLinkerCriterion - Function used to determine which links to decorate
438450
*/

trackers/browser-tracker/docs/browser-tracker.api.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ export interface BrowserTracker {
9898
updatePageActivity: () => void;
9999
}
100100

101+
// Warning: (ae-forgotten-export) The symbol "RequireAtLeastOne" needs to be exported by the entry point index.module.d.ts
102+
//
103+
// @public (undocumented)
104+
export type BuiltInContexts = RequireAtLeastOne<{
105+
/* Toggles the web_page context */
106+
webPage: boolean;
107+
/* Toggles the session context */
108+
session: boolean;
109+
}> | Record<string, never>;
110+
101111
// @public
102112
export function clearGlobalContexts(trackers?: Array<string>): void;
103113

@@ -329,10 +339,7 @@ export type TrackerConfiguration = {
329339
resetActivityTrackingOnPageView?: boolean;
330340
connectionTimeout?: number;
331341
anonymousTracking?: AnonymousTrackingOptions;
332-
contexts?: {
333-
webPage: boolean;
334-
session: boolean;
335-
};
342+
contexts?: BuiltInContexts;
336343
plugins?: Array<BrowserPlugin>;
337344
customHeaders?: Record<string, string>;
338345
retryStatusCodes?: number[];

trackers/browser-tracker/src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
ActivityCallbackData,
3737
BrowserPlugin,
3838
BrowserPluginConfiguration,
39+
BuiltInContexts,
3940
DisableAnonymousTrackingConfiguration,
4041
EnableAnonymousTrackingConfiguration,
4142
AnonymousTrackingOptions,
@@ -67,6 +68,7 @@ export {
6768
ActivityCallbackData,
6869
BrowserPlugin,
6970
BrowserPluginConfiguration,
71+
BuiltInContexts,
7072
FlushBufferConfiguration,
7173
PageViewEvent,
7274
EnableAnonymousTrackingConfiguration,

0 commit comments

Comments
 (0)