@@ -9,7 +9,7 @@ import Script from 'next/script';
99import type { PropsWithChildren } from 'react' ;
1010import { createContext , useContext , useEffect , useState } from 'react' ;
1111
12- import { isTrackingCookieAllowed } from './lib' ;
12+ import { isNavigatorTrackingAllowed } from './lib' ;
1313import { logToConsole , normalizePrezlyMetaPlugin , sendEventToPrezlyPlugin } from './plugins' ;
1414import { TrackingPolicy } from './types' ;
1515import type {
@@ -22,15 +22,13 @@ interface Context {
2222 analytics : Analytics | undefined ;
2323 consent : boolean | null ;
2424 gallery ?: PickedGalleryProperties ;
25- isEnabled : boolean ;
2625 /**
2726 * - TRUE - tracking allowed (i.e. user clicked "Allow")
2827 * - FALSE - tracking disallowed (i.e. user clicked "Disallow" or browser "Do Not Track" mode is ON)
2928 * - NULL - unknown (i.e. user didn't click anything yet, and no browser preference set)
3029 */
3130 isTrackingCookieAllowed : boolean | null ;
3231 newsroom ?: PickedNewsroomProperties ;
33- setConsent ( consent : boolean ) : void ;
3432 story ?: PickedStoryProperties ;
3533 trackingPolicy : TrackingPolicy ;
3634}
@@ -73,14 +71,25 @@ export function AnalyticsProvider({
7371 user,
7472} : PropsWithChildren < Props > ) {
7573 const {
76- tracking_policy : trackingPolicy = TrackingPolicy . DEFAULT ,
74+ tracking_policy : trackingPolicy = TrackingPolicy . DEFAULT as TrackingPolicy ,
7775 segment_analytics_id : segmentWriteKey = customSegmentWriteKey ,
7876 uuid,
7977 } = newsroom || { } ;
8078
81- const [ consent , setConsent ] = useState < boolean | null > ( null ) ;
79+ const [ isTrackingCookieAllowed , setIsTrackingCookieAllowed ] = useState (
80+ trackingPolicy === TrackingPolicy . WILD_WEST ,
81+ ) ;
82+
8283 const [ analytics , setAnalytics ] = useState < Analytics | undefined > ( undefined ) ;
8384
85+ useEffect ( ( ) => {
86+ setIsTrackingCookieAllowed (
87+ isEnabled &&
88+ ( isNavigatorTrackingAllowed ( ) ?? false ) &&
89+ trackingPolicy === TrackingPolicy . WILD_WEST ,
90+ ) ;
91+ } , [ isEnabled , trackingPolicy ] ) ;
92+
8493 useEffect ( ( ) => {
8594 async function loadAnalytics ( writeKey : string ) {
8695 try {
@@ -155,13 +164,11 @@ export function AnalyticsProvider({
155164 < AnalyticsContext . Provider
156165 value = { {
157166 analytics,
158- consent,
167+ consent : null ,
159168 gallery,
160- isEnabled,
161- isTrackingCookieAllowed : isTrackingCookieAllowed ( consent , newsroom ) ,
169+ isTrackingCookieAllowed,
162170 newsroom,
163171 story,
164- setConsent,
165172 trackingPolicy,
166173 } }
167174 >
0 commit comments