@rpcbase/client 0.154.0 → 0.155.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
import {useEffect} from "react"
|
|
3
|
+
import {usePostHog} from "posthog-js/react"
|
|
4
|
+
import FingerprintJS from "@fingerprintjs/fingerprintjs"
|
|
5
|
+
|
|
6
|
+
import getUid from "../auth/getUid"
|
|
7
|
+
|
|
8
|
+
// TMP: RB_TENANT_ID must come from the server, not be set in env here
|
|
9
|
+
import {RB_TENANT_ID, POSTHOG_KEY} from "env"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const AnalyticsContainer = ({children}) => {
|
|
13
|
+
const {hostname} = window.location
|
|
14
|
+
if (__DEV__ || hostname === "localhost" || hostname.endsWith(".local")) return null
|
|
15
|
+
if (!POSTHOG_KEY) return null
|
|
16
|
+
|
|
17
|
+
const posthog = usePostHog()
|
|
18
|
+
|
|
19
|
+
const uid = getUid()
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!posthog) return
|
|
23
|
+
|
|
24
|
+
if (uid) {
|
|
25
|
+
posthog.identify(uid, {
|
|
26
|
+
uid,
|
|
27
|
+
env: __DEV__ ? "dev" : "prod",
|
|
28
|
+
})
|
|
29
|
+
posthog.group("customer", RB_TENANT_ID, {
|
|
30
|
+
name: "default",
|
|
31
|
+
})
|
|
32
|
+
posthog.group("env", __DEV__ ? "dev" : "prod")
|
|
33
|
+
}
|
|
34
|
+
// user isn't identified, use fingerprint instead
|
|
35
|
+
else {
|
|
36
|
+
const run = async() => {
|
|
37
|
+
const fp = await FingerprintJS.load()
|
|
38
|
+
const fpResult = await fp.get()
|
|
39
|
+
|
|
40
|
+
posthog.identify(fpResult.visitorId, {
|
|
41
|
+
type: "fingerprint",
|
|
42
|
+
env: __DEV__ ? "dev" : "prod",
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
run()
|
|
47
|
+
}
|
|
48
|
+
}, [posthog, uid])
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<>{children}</>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default AnalyticsContainer
|
package/AppProvider/index.js
CHANGED
|
@@ -5,13 +5,15 @@ import {PostHogProvider} from "posthog-js/react"
|
|
|
5
5
|
|
|
6
6
|
import {HashStateProvider} from "../hashState"
|
|
7
7
|
|
|
8
|
+
import AnalyticsContainer from "./AnalyticsContainer"
|
|
9
|
+
|
|
8
10
|
// TODO: flags here should be optional
|
|
9
11
|
import {flagValues} from "config/flags"
|
|
10
12
|
|
|
11
13
|
import {POSTHOG_KEY} from "env"
|
|
12
14
|
|
|
13
15
|
|
|
14
|
-
const
|
|
16
|
+
const PostHogWrapper = ({children, ...props}) => {
|
|
15
17
|
|
|
16
18
|
const {hostname} = window.location
|
|
17
19
|
|
|
@@ -33,7 +35,9 @@ const AnalyticsWrapper = ({children, ...props}) => {
|
|
|
33
35
|
},
|
|
34
36
|
}}
|
|
35
37
|
>
|
|
36
|
-
|
|
38
|
+
<AnalyticsContainer>
|
|
39
|
+
{children}
|
|
40
|
+
</AnalyticsContainer>
|
|
37
41
|
</PostHogProvider>
|
|
38
42
|
)
|
|
39
43
|
}
|
|
@@ -43,11 +47,11 @@ const AnalyticsWrapper = ({children, ...props}) => {
|
|
|
43
47
|
const AppProvider = ({children, ...props}) => {
|
|
44
48
|
|
|
45
49
|
return (
|
|
46
|
-
<
|
|
50
|
+
<PostHogWrapper>
|
|
47
51
|
<HashStateProvider>
|
|
48
52
|
{children}
|
|
49
53
|
</HashStateProvider>
|
|
50
|
-
</
|
|
54
|
+
</PostHogWrapper>
|
|
51
55
|
)
|
|
52
56
|
|
|
53
57
|
}
|