Skip to content

Commit 2977579

Browse files
authored
Merge pull request #22 from Swetrix/feature/profiles
Profiles
2 parents 51f4b9a + d87931c commit 2977579

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Lib.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export interface LibOptions {
3232

3333
/** Set a custom URL of the API server (for selfhosted variants of Swetrix). */
3434
apiURL?: string
35+
36+
/**
37+
* Optional profile ID for long-term user tracking.
38+
* If set, it will be used for all pageviews and events unless overridden per-call.
39+
*/
40+
profileId?: string
3541
}
3642

3743
export interface TrackEventOptions {
@@ -45,6 +51,9 @@ export interface TrackEventOptions {
4551
meta?: {
4652
[key: string]: string | number | boolean | null | undefined
4753
}
54+
55+
/** Optional profile ID for long-term user tracking. Overrides the global profileId if set. */
56+
profileId?: string
4857
}
4958

5059
// Partial user-editable pageview payload
@@ -63,6 +72,9 @@ export interface IPageViewPayload {
6372
meta?: {
6473
[key: string]: string | number | boolean | null | undefined
6574
}
75+
76+
/** Optional profile ID for long-term user tracking. Overrides the global profileId if set. */
77+
profileId?: string
6678
}
6779

6880
// Partial user-editable error payload
@@ -318,6 +330,7 @@ export class Lib {
318330
ca: getUTMCampaign(),
319331
te: getUTMTerm(),
320332
co: getUTMContent(),
333+
profileId: event.profileId ?? this.options?.profileId,
321334
}
322335
await this.sendRequest('custom', data)
323336
}
@@ -539,6 +552,7 @@ export class Lib {
539552
ca: getUTMCampaign(),
540553
te: getUTMTerm(),
541554
co: getUTMContent(),
555+
profileId: this.options?.profileId,
542556
...payload,
543557
}
544558

0 commit comments

Comments
 (0)