-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAnalyticsProvider.tsx
49 lines (40 loc) · 1.23 KB
/
AnalyticsProvider.tsx
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { FC, ReactElement, useEffect } from 'react'
import { useAccount } from 'wagmi'
import { datadogRum } from '@datadog/browser-rum'
const env = process.env.NODE_ENV
const ddApplicationId = process.env.NEXT_PUBLIC_DATADOG_APPLICATION_ID
const ddClientToken = process.env.NEXT_PUBLIC_DATADOG_CLIENT_TOKEN
type Props = {
children: ReactElement
}
const AnalyticsProvider: FC<Props> = ({ children }) => {
const accountData = useAccount()
useEffect(() => {
if (accountData) {
datadogRum.setUser({
id: accountData.address?.toLowerCase(),
})
}
}, [accountData])
useEffect(() => {
if (typeof window !== 'undefined' && !datadogRum.getInitConfiguration()) {
if (!ddApplicationId || !ddClientToken) return
datadogRum.init({
applicationId: ddApplicationId,
clientToken: ddClientToken,
site: 'datadoghq.com',
service: 'nfteart-marketplace',
env,
sampleRate: 100,
replaySampleRate: 100,
trackInteractions: true,
trackFrustrations: true,
trackResources: true,
defaultPrivacyLevel: 'mask-user-input',
})
datadogRum.startSessionReplayRecording()
}
}, [])
return children
}
export default AnalyticsProvider