tracker: user/device id hardreset method
This commit is contained in:
parent
529965486c
commit
fa2923b83d
3 changed files with 16 additions and 3 deletions
|
|
@ -16,6 +16,12 @@ export default class People {
|
|||
// TODO: fetch endpoint when it will be here
|
||||
}
|
||||
|
||||
// add "hard" flag to force generate device id as well ?
|
||||
reset = () => {
|
||||
this.sharedProperties.resetUserId()
|
||||
this.ownProperties = {}
|
||||
}
|
||||
|
||||
get user_id() {
|
||||
return this.sharedProperties.user_id
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,6 +98,11 @@ export default class SharedProperties {
|
|||
this.user_id = user_id
|
||||
}
|
||||
|
||||
resetUserId = () => {
|
||||
this.user_id = null
|
||||
this.deviceId = this.getDistinctDeviceId(true)
|
||||
}
|
||||
|
||||
public get defaultPropertyKeys() {
|
||||
return Object.keys(this.all)
|
||||
}
|
||||
|
|
@ -106,9 +111,9 @@ export default class SharedProperties {
|
|||
return this.deviceId
|
||||
}
|
||||
|
||||
private getDistinctDeviceId = () => {
|
||||
private getDistinctDeviceId = (force?: boolean) => {
|
||||
const potentialStored = this.localStorage.getItem(distinctIdKey)
|
||||
if (potentialStored) {
|
||||
if (potentialStored && !force) {
|
||||
return potentialStored
|
||||
} else {
|
||||
const distinctId = `${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`
|
||||
|
|
|
|||
|
|
@ -157,7 +157,9 @@ describe('SharedProperties', () => {
|
|||
$utm_medium: 'test_medium',
|
||||
$utm_campaign: 'test_campaign',
|
||||
$distinct_id: expect.stringMatching(/^[a-z0-9]{6,12}-[a-z0-9]{6,12}-[a-z0-9]{6,12}$/),
|
||||
$search_engine: null
|
||||
$search_engine: null,
|
||||
$user_id: null,
|
||||
$device_id: expect.stringMatching(/^[a-z0-9]{6,12}-[a-z0-9]{6,12}-[a-z0-9]{6,12}$/),
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue