@@ -6,6 +6,7 @@ import { useObservable, useRollbar } from '@jetstream/shared/ui-utils';
66import { Announcement , SalesforceOrgUi } from '@jetstream/types' ;
77import { useAmplitude } from '@jetstream/ui-core' ;
88import { fromAppState } from '@jetstream/ui/app-state' ;
9+ import { CookieConsentBanner , useConditionalGoogleAnalytics } from '@jetstream/ui/cookie-consent-banner' ;
910import { initDexieDb } from '@jetstream/ui/db' ;
1011import { AxiosResponse } from 'axios' ;
1112import { useAtom , useAtomValue } from 'jotai' ;
@@ -42,6 +43,9 @@ export const AppInitializer: FunctionComponent<AppInitializerProps> = ({ onAnnou
4243 const { version, announcements, appInfo } = useAtomValue ( fromAppState . appInfoState ) ;
4344 const [ orgs , setOrgs ] = useAtom ( fromAppState . salesforceOrgsState ) ;
4445 const invalidOrg = useObservable ( orgConnectionError$ ) ;
46+ const [ analytics , setAnalytics ] = useAtom ( fromAppState . analyticsState ) ;
47+
48+ useConditionalGoogleAnalytics ( environment . googleAnalyticsSiteId , analytics === 'accepted' ) ;
4549
4650 const recordSyncEntitlementEnabled = ability . can ( 'access' , 'RecordSync' ) ;
4751 const recordSyncEnabled = recordSyncEntitlementEnabled && userProfile . preferences . recordSyncEnabled ;
@@ -88,7 +92,7 @@ APP VERSION ${version}
8892 userProfile : userProfile ,
8993 version,
9094 } ) ;
91- useAmplitude ( ) ;
95+ useAmplitude ( analytics !== 'accepted' ) ;
9296
9397 useEffect ( ( ) => {
9498 if ( invalidOrg ) {
@@ -137,8 +141,12 @@ APP VERSION ${version}
137141 return ( ) => document . removeEventListener ( 'visibilitychange' , handleWindowFocus ) ;
138142 } , [ handleWindowFocus ] ) ;
139143
140- // eslint-disable-next-line react/jsx-no-useless-fragment
141- return < Fragment > { children } </ Fragment > ;
144+ return (
145+ < Fragment >
146+ < CookieConsentBanner onConsentChange = { setAnalytics } />
147+ { children }
148+ </ Fragment >
149+ ) ;
142150} ;
143151
144152export default AppInitializer ;
0 commit comments