tracker: move userid to common props, use email/device as dist id
This commit is contained in:
parent
9f51ab85da
commit
529965486c
3 changed files with 23 additions and 4 deletions
|
|
@ -8,6 +8,15 @@ export default class Analytics {
|
|||
public readonly sharedProperties: SharedProperties
|
||||
public readonly people: People
|
||||
|
||||
/**
|
||||
* @param localStorage Class or Object that implements Storage-like interface that stores
|
||||
* values persistently like window.localStorage or any other file-based storage
|
||||
*
|
||||
* @param sessionStorage Class or Object that implements Storage-like interface that stores values
|
||||
* on per-session basis like window.sessionStorage or any other in-memory storage
|
||||
*
|
||||
* @param getToken Function that returns token to bind events to a se
|
||||
* */
|
||||
constructor(
|
||||
private readonly localStorage: StorageLike,
|
||||
private readonly sessionStorage: StorageLike,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { isObject } from './utils.js'
|
|||
|
||||
export default class People {
|
||||
ownProperties: Record<string, any> = {}
|
||||
user_id: string | null = null
|
||||
|
||||
constructor(
|
||||
private readonly sharedProperties: SharedProperties,
|
||||
|
|
@ -12,14 +11,18 @@ export default class People {
|
|||
) {}
|
||||
|
||||
identify = (user_id: string) => {
|
||||
this.user_id = user_id
|
||||
this.sharedProperties.setUserId(user_id)
|
||||
|
||||
// TODO: fetch endpoint when it will be here
|
||||
}
|
||||
|
||||
get user_id() {
|
||||
return this.sharedProperties.user_id
|
||||
}
|
||||
|
||||
// TODO: what exactly we're removing here besides properties and id?
|
||||
deleteUser = () => {
|
||||
this.user_id = null
|
||||
this.sharedProperties.setUserId(null)
|
||||
this.ownProperties = {}
|
||||
|
||||
// TODO: fetch endpoint when it will be here
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ export default class SharedProperties {
|
|||
utmCampaign: string | null
|
||||
deviceId: string
|
||||
searchEngine: string | null
|
||||
user_id: string | null = null
|
||||
|
||||
constructor(
|
||||
private readonly localStorage: StorageLike,
|
||||
|
|
@ -83,7 +84,9 @@ export default class SharedProperties {
|
|||
[`${prefix}utm_source`]: this.utmSource,
|
||||
[`${prefix}utm_medium`]: this.utmMedium,
|
||||
[`${prefix}utm_campaign`]: this.utmCampaign,
|
||||
[`${prefix}distinct_id`]: this.deviceId,
|
||||
[`${prefix}device_id`]: this.deviceId,
|
||||
[`${prefix}user_id`]: this.user_id,
|
||||
[`${prefix}distinct_id`]: this.user_id ?? this.deviceId,
|
||||
[`${prefix}sdk_edition`]: 'web',
|
||||
[`${prefix}sdk_version`]: 'TRACKER_VERSION',
|
||||
[`${prefix}timezone`]: getUTCOffsetString(),
|
||||
|
|
@ -91,6 +94,10 @@ export default class SharedProperties {
|
|||
}
|
||||
}
|
||||
|
||||
setUserId = (user_id: string | null) => {
|
||||
this.user_id = user_id
|
||||
}
|
||||
|
||||
public get defaultPropertyKeys() {
|
||||
return Object.keys(this.all)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue