@@ -6,14 +6,9 @@ import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect'
6
6
import { destSDKBaseURL , pluginsSDKBaseURL } from '../constants'
7
7
import type { CategoryKind } from '../types'
8
8
import { defaultConsentOptions , defaultLoadOptions } from './constants'
9
- import { trackLink } from './segments/trackLink'
10
- import type { TrackLink } from './segments/trackLink'
11
9
import { userMigrationsTraits } from './segments/userMigrationsTraits'
12
10
13
- type Analytics = RudderAnalytics & {
14
- trackLink : TrackLink
15
- }
16
-
11
+ type Analytics = RudderAnalytics
17
12
export type { Analytics }
18
13
19
14
export type OnEventError = ( error : Error ) => Promise < void > | void
@@ -51,7 +46,6 @@ export type AnalyticsProviderProps<T> = {
51
46
settings ?: {
52
47
writeKey : string
53
48
cdnURL : string
54
- timeout : number
55
49
}
56
50
loadOptions ?: LoadOptions
57
51
@@ -60,9 +54,10 @@ export type AnalyticsProviderProps<T> = {
60
54
*/
61
55
shouldRenderOnlyWhenReady ?: boolean
62
56
/**
63
- * used with shouldRenderOnlyWhenReady can blocked rendering until consent the first time.
57
+ * used with shouldRenderOnlyWhenReady can blocked rendering until consent the first time. You can also set a timeout to prevent blocking indefinitely.
64
58
*/
65
59
needConsent ?: boolean
60
+ timeout ?: number
66
61
allowedConsents : CategoryKind [ ]
67
62
deniedConsents : CategoryKind [ ]
68
63
onError ?: ( err : Error ) => void
@@ -87,6 +82,7 @@ export function AnalyticsProvider<T extends Events>({
87
82
deniedConsents,
88
83
events,
89
84
onLoaded,
85
+ timeout,
90
86
} : AnalyticsProviderProps < T > ) {
91
87
const [ isAnalyticsReady , setIsAnalyticsReady ] = useState ( false )
92
88
const [ internalAnalytics , setAnalytics ] = useState < Analytics | undefined > (
@@ -96,9 +92,10 @@ export function AnalyticsProvider<T extends Events>({
96
92
// This effect will unlock the case where we have a failure with the load of the analytics.load as rudderstack doesn't provider any solution for this case.
97
93
useEffect ( ( ) => {
98
94
let timer : ReturnType < typeof setTimeout > | undefined
99
- if ( ! isAnalyticsReady && ! internalAnalytics && settings ?. timeout ) {
95
+ if ( ! isAnalyticsReady && ! internalAnalytics && timeout ) {
100
96
if ( shouldRenderOnlyWhenReady ) {
101
- timer = setTimeout ( ( ) => setIsAnalyticsReady ( true ) , settings . timeout )
97
+ timer = setTimeout ( ( ) => setIsAnalyticsReady ( true ) , timeout )
98
+ onError ?.( new Error ( 'Analytics Setup Timeout' ) )
102
99
}
103
100
}
104
101
@@ -110,7 +107,8 @@ export function AnalyticsProvider<T extends Events>({
110
107
internalAnalytics ,
111
108
setIsAnalyticsReady ,
112
109
shouldRenderOnlyWhenReady ,
113
- settings ?. timeout ,
110
+ timeout ,
111
+ onError ,
114
112
] )
115
113
116
114
const shouldLoad = useMemo ( ( ) => {
@@ -150,12 +148,11 @@ export function AnalyticsProvider<T extends Events>({
150
148
} )
151
149
152
150
analytics . ready ( ( ) => {
153
- // @ts -expect-error tracklink is added to the analytics setup to simplify migration from segment, should be remove.
154
- setAnalytics ( { ...analytics , trackLink : trackLink ( analytics ) } )
151
+ setAnalytics ( analytics )
155
152
setIsAnalyticsReady ( true )
156
153
} )
157
154
}
158
- } , [ onError , settings , loadOptions , shouldLoad ] )
155
+ } , [ settings , loadOptions , shouldLoad ] )
159
156
160
157
const value = useMemo < AnalyticsContextInterface < T > > ( ( ) => {
161
158
const curiedEvents = Object . entries ( events ) . reduce (
0 commit comments