@@ -6,14 +6,9 @@ import { useDeepCompareEffectNoCheck } from 'use-deep-compare-effect'
66import { destSDKBaseURL , pluginsSDKBaseURL } from '../constants'
77import type { CategoryKind } from '../types'
88import { defaultConsentOptions , defaultLoadOptions } from './constants'
9- import { trackLink } from './segments/trackLink'
10- import type { TrackLink } from './segments/trackLink'
119import { userMigrationsTraits } from './segments/userMigrationsTraits'
1210
13- type Analytics = RudderAnalytics & {
14- trackLink : TrackLink
15- }
16-
11+ type Analytics = RudderAnalytics
1712export type { Analytics }
1813
1914export type OnEventError = ( error : Error ) => Promise < void > | void
@@ -51,7 +46,6 @@ export type AnalyticsProviderProps<T> = {
5146 settings ?: {
5247 writeKey : string
5348 cdnURL : string
54- timeout : number
5549 }
5650 loadOptions ?: LoadOptions
5751
@@ -60,9 +54,10 @@ export type AnalyticsProviderProps<T> = {
6054 */
6155 shouldRenderOnlyWhenReady ?: boolean
6256 /**
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.
6458 */
6559 needConsent ?: boolean
60+ timeout ?: number
6661 allowedConsents : CategoryKind [ ]
6762 deniedConsents : CategoryKind [ ]
6863 onError ?: ( err : Error ) => void
@@ -87,6 +82,7 @@ export function AnalyticsProvider<T extends Events>({
8782 deniedConsents,
8883 events,
8984 onLoaded,
85+ timeout,
9086} : AnalyticsProviderProps < T > ) {
9187 const [ isAnalyticsReady , setIsAnalyticsReady ] = useState ( false )
9288 const [ internalAnalytics , setAnalytics ] = useState < Analytics | undefined > (
@@ -96,9 +92,10 @@ export function AnalyticsProvider<T extends Events>({
9692 // 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.
9793 useEffect ( ( ) => {
9894 let timer : ReturnType < typeof setTimeout > | undefined
99- if ( ! isAnalyticsReady && ! internalAnalytics && settings ?. timeout ) {
95+ if ( ! isAnalyticsReady && ! internalAnalytics && timeout ) {
10096 if ( shouldRenderOnlyWhenReady ) {
101- timer = setTimeout ( ( ) => setIsAnalyticsReady ( true ) , settings . timeout )
97+ timer = setTimeout ( ( ) => setIsAnalyticsReady ( true ) , timeout )
98+ onError ?.( new Error ( 'Analytics Setup Timeout' ) )
10299 }
103100 }
104101
@@ -110,7 +107,8 @@ export function AnalyticsProvider<T extends Events>({
110107 internalAnalytics ,
111108 setIsAnalyticsReady ,
112109 shouldRenderOnlyWhenReady ,
113- settings ?. timeout ,
110+ timeout ,
111+ onError ,
114112 ] )
115113
116114 const shouldLoad = useMemo ( ( ) => {
@@ -150,12 +148,11 @@ export function AnalyticsProvider<T extends Events>({
150148 } )
151149
152150 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 )
155152 setIsAnalyticsReady ( true )
156153 } )
157154 }
158- } , [ onError , settings , loadOptions , shouldLoad ] )
155+ } , [ settings , loadOptions , shouldLoad ] )
159156
160157 const value = useMemo < AnalyticsContextInterface < T > > ( ( ) => {
161158 const curiedEvents = Object . entries ( events ) . reduce (
0 commit comments