@@ -10,35 +10,50 @@ export default function PostHogIdentify() {
1010 const lastConnector = useRef < string | undefined > ( undefined )
1111
1212 useEffect ( ( ) => {
13- if ( ! posthog . __loaded ) return
14-
15- if ( isConnected && address ) {
16- const distinctId = address . toLowerCase ( )
17- const connectorName = connector ?. name
18-
19- if ( lastAddress . current !== distinctId ) {
20- if ( lastAddress . current ) posthog . reset ( )
21- posthog . identify ( distinctId , {
22- wallet_address : distinctId ,
23- wallet_connector : connectorName ,
24- } )
25- lastAddress . current = distinctId
26- lastConnector . current = connectorName
13+ const run = ( ) => {
14+ if ( isConnected && address ) {
15+ const distinctId = address . toLowerCase ( )
16+ const connectorName = connector ?. name
17+ const phId = posthog . get_distinct_id ?.( )
18+ const needsIdentify = lastAddress . current !== distinctId || phId !== distinctId
19+
20+ if ( needsIdentify ) {
21+ if ( lastAddress . current && lastAddress . current !== distinctId ) {
22+ posthog . reset ( )
23+ }
24+ posthog . identify ( distinctId , {
25+ wallet_address : distinctId ,
26+ wallet_connector : connectorName ,
27+ } )
28+ lastAddress . current = distinctId
29+ lastConnector . current = connectorName
30+ return
31+ }
32+
33+ if ( lastConnector . current !== connectorName ) {
34+ posthog . setPersonProperties ( { wallet_connector : connectorName } )
35+ lastConnector . current = connectorName
36+ }
2737 return
2838 }
2939
30- if ( lastConnector . current !== connectorName ) {
31- posthog . setPersonProperties ( { wallet_connector : connectorName } )
32- lastConnector . current = connectorName
40+ if ( lastAddress . current ) {
41+ posthog . reset ( )
42+ lastAddress . current = undefined
43+ lastConnector . current = undefined
3344 }
34- return
3545 }
3646
37- if ( lastAddress . current ) {
38- posthog . reset ( )
39- lastAddress . current = undefined
40- lastConnector . current = undefined
47+ if ( posthog . __loaded ) {
48+ run ( )
49+ return
4150 }
51+
52+ const off = posthog . onFeatureFlags ( ( ) => {
53+ off ?.( )
54+ run ( )
55+ } )
56+ return ( ) => off ?.( )
4257 } , [ address , isConnected , connector ?. name ] )
4358
4459 return null
0 commit comments