generated from fingerprintjs/library-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pageHandler.ts
35 lines (34 loc) · 932 Bytes
/
pageHandler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { FPJSSegmentIntegrationBody, MaybeNullOrUndefined as NullOrUn } from '../types'
import { SegmentSpecPage } from '../types/segment/specs/page'
import '../types/segment'
import { SegmentSpecWithUserId } from '../types/segment/utils/id'
export function handlePage(
page: NullOrUn<SegmentSpecPage<{}, { context?: object }>>,
userId: NullOrUn<SegmentSpecWithUserId['userId']>,
body: FPJSSegmentIntegrationBody
) {
if (!page) {
return
}
try {
Segment.page({
...page,
anonymousId: body.visitorId,
userId,
context: {
ip: body.ip,
browserDetails: body.browserDetails,
incognito: body.incognito,
confidenceScore: body.confidence?.score,
requestId: body.requestId,
...page?.context,
},
properties: {
url: body.url,
...page?.properties,
},
})
} catch (e) {
console.log('error:pageHandler', e)
}
}