Ensure we update metadata when session ID changes
This commit is contained in:
@@ -41,12 +41,13 @@ let baseMetadata: BaseMetadata = {
|
|||||||
country: device.get(['mergedGeolocation'])?.countryCode || 'unknown',
|
country: device.get(['mergedGeolocation'])?.countryCode || 'unknown',
|
||||||
}
|
}
|
||||||
export function updateBaseMetadata(
|
export function updateBaseMetadata(
|
||||||
metadata: Omit<BaseMetadata, 'deviceId' | 'sessionId'>,
|
metadata: Partial<Omit<BaseMetadata, 'deviceId'>>,
|
||||||
) {
|
) {
|
||||||
baseMetadata = {
|
baseMetadata = {
|
||||||
deviceId: getDeviceId() || 'unknown',
|
...baseMetadata,
|
||||||
sessionId: getSessionId(),
|
|
||||||
...metadata,
|
...metadata,
|
||||||
|
sessionId: metadata.sessionId || getSessionId(),
|
||||||
|
deviceId: getDeviceId() || 'unknown',
|
||||||
}
|
}
|
||||||
__onMetadataChange()
|
__onMetadataChange()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import uuid from 'react-native-uuid'
|
import uuid from 'react-native-uuid'
|
||||||
|
|
||||||
import {onAppStateChange} from '#/lib/appState'
|
import {onAppStateChange} from '#/lib/appState'
|
||||||
|
import {updateBaseMetadata} from '#/logger/metadata'
|
||||||
import {device} from '#/storage'
|
import {device} from '#/storage'
|
||||||
|
|
||||||
const TTL = 5 * 60 * 1e3 // 5 min on native
|
const TTL = 5 * 60 * 1e3 // 5 min on native
|
||||||
@@ -14,6 +15,7 @@ let sessionId = (() => {
|
|||||||
const lastEvent = device.get(['nativeSessionIdLastEventAt'])
|
const lastEvent = device.get(['nativeSessionIdLastEventAt'])
|
||||||
const id = existing && !expired(lastEvent) ? existing : uuid.v4()
|
const id = existing && !expired(lastEvent) ? existing : uuid.v4()
|
||||||
device.set(['nativeSessionId'], id)
|
device.set(['nativeSessionId'], id)
|
||||||
|
updateBaseMetadata({sessionId: id})
|
||||||
return id
|
return id
|
||||||
})()
|
})()
|
||||||
|
|
||||||
@@ -23,6 +25,7 @@ onAppStateChange(state => {
|
|||||||
if (expired(lastEvent)) {
|
if (expired(lastEvent)) {
|
||||||
sessionId = uuid.v4()
|
sessionId = uuid.v4()
|
||||||
device.set(['nativeSessionId'], sessionId)
|
device.set(['nativeSessionId'], sessionId)
|
||||||
|
updateBaseMetadata({sessionId})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
device.set(['nativeSessionIdLastEventAt'], Date.now())
|
device.set(['nativeSessionIdLastEventAt'], Date.now())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import uuid from 'react-native-uuid'
|
import uuid from 'react-native-uuid'
|
||||||
|
|
||||||
import {onAppStateChange} from '#/lib/appState'
|
import {onAppStateChange} from '#/lib/appState'
|
||||||
|
import {updateBaseMetadata} from '#/logger/metadata'
|
||||||
|
|
||||||
const TTL = 30 * 60 * 1e3 // 30 min on web
|
const TTL = 30 * 60 * 1e3 // 30 min on web
|
||||||
const SESSION_ID_KEY = 'bsky_session_id'
|
const SESSION_ID_KEY = 'bsky_session_id'
|
||||||
@@ -17,6 +18,7 @@ let sessionId = (() => {
|
|||||||
const lastEvent = lastEventStr ? Number(lastEventStr) : undefined
|
const lastEvent = lastEventStr ? Number(lastEventStr) : undefined
|
||||||
const id = existing && !expired(lastEvent) ? existing : uuid.v4()
|
const id = existing && !expired(lastEvent) ? existing : uuid.v4()
|
||||||
window.sessionStorage.setItem(SESSION_ID_KEY, id)
|
window.sessionStorage.setItem(SESSION_ID_KEY, id)
|
||||||
|
updateBaseMetadata({sessionId: id})
|
||||||
return id
|
return id
|
||||||
})()
|
})()
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ onAppStateChange(state => {
|
|||||||
if (expired(lastEvent)) {
|
if (expired(lastEvent)) {
|
||||||
sessionId = uuid.v4()
|
sessionId = uuid.v4()
|
||||||
window.sessionStorage.setItem(SESSION_ID_KEY, sessionId)
|
window.sessionStorage.setItem(SESSION_ID_KEY, sessionId)
|
||||||
|
updateBaseMetadata({sessionId})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window.sessionStorage.setItem(LAST_EVENT_KEY, String(Date.now()))
|
window.sessionStorage.setItem(LAST_EVENT_KEY, String(Date.now()))
|
||||||
|
|||||||
Reference in New Issue
Block a user