@@ -10,7 +10,12 @@ import {
1010} from 'react'
1111import { uniq } from '../helpers/array'
1212import { stringToHash } from '../helpers/misc'
13- import type { CategoryKind , Config , Consent , Integrations } from './types'
13+ import type {
14+ CategoryKind ,
15+ Consent ,
16+ Integrations ,
17+ SegmentConfig ,
18+ } from './types'
1419import { useSegmentIntegrations } from './useSegmentIntegrations'
1520
1621const COOKIE_PREFIX = '_scw_rgpd'
@@ -53,17 +58,29 @@ export const CookieConsentProvider = ({
5358 children,
5459 isConsentRequired,
5560 essentialIntegrations,
56- config,
61+ segmentConfig,
62+ cookiePrefix = COOKIE_PREFIX ,
63+ consentMaxAge = CONSENT_MAX_AGE ,
64+ consentAdvertisingMaxAge = CONSENT_ADVERTISING_MAX_AGE ,
65+ cookiesOptions = COOKIES_OPTIONS ,
5766} : {
5867 children : ReactNode
5968 isConsentRequired : boolean
6069 essentialIntegrations : string [ ]
61- config : Config
70+ segmentConfig : SegmentConfig
71+ cookiePrefix : string
72+ consentMaxAge : number
73+ consentAdvertisingMaxAge : number
74+ cookiesOptions : {
75+ sameSite : boolean | 'strict' | 'lax' | 'none' | undefined
76+ secure : boolean
77+ path : string
78+ }
6279} ) => {
6380 const [ needConsent , setNeedsConsent ] = useState ( false )
6481
6582 const [ cookies , setCookies ] = useState < Record < string , string > > ( )
66- const segmentIntegrations = useSegmentIntegrations ( config )
83+ const segmentIntegrations = useSegmentIntegrations ( segmentConfig )
6784
6885 useEffect ( ( ) => {
6986 setCookies ( cookie . parse ( document . cookie ) )
@@ -126,20 +143,20 @@ export const CookieConsentProvider = ({
126143 ( acc , category ) => ( {
127144 ...acc ,
128145 [ category ] : isConsentRequired
129- ? cookies ?. [ `${ COOKIE_PREFIX } _${ category } ` ] === 'true'
146+ ? cookies ?. [ `${ cookiePrefix } _${ category } ` ] === 'true'
130147 : true ,
131148 } ) ,
132149 { } ,
133150 ) ,
134- [ isConsentRequired , categories , cookies ] ,
151+ [ isConsentRequired , categories , cookies , cookiePrefix ] ,
135152 )
136153
137154 const saveConsent = useCallback (
138155 ( categoriesConsent : Partial < Consent > ) => {
139156 for ( const [ consentName , consentValue ] of Object . entries (
140157 categoriesConsent ,
141158 ) as [ CategoryKind , boolean ] [ ] ) {
142- const cookieName = `${ COOKIE_PREFIX } _${ consentName } `
159+ const cookieName = `${ cookiePrefix } _${ consentName } `
143160
144161 if ( ! consentValue ) {
145162 // If consent is set to false we have to delete the cookie
@@ -148,14 +165,14 @@ export const CookieConsentProvider = ({
148165 } )
149166 } else {
150167 document . cookie = cookie . serialize (
151- `${ COOKIE_PREFIX } _${ consentName } ` ,
168+ `${ cookiePrefix } _${ consentName } ` ,
152169 consentValue . toString ( ) ,
153170 {
154- ...COOKIES_OPTIONS ,
171+ ...cookiesOptions ,
155172 maxAge :
156173 consentName === 'advertising'
157- ? CONSENT_ADVERTISING_MAX_AGE
158- : CONSENT_MAX_AGE ,
174+ ? consentAdvertisingMaxAge
175+ : consentMaxAge ,
159176 } ,
160177 )
161178 }
@@ -165,14 +182,20 @@ export const CookieConsentProvider = ({
165182 HASH_COOKIE ,
166183 integrationsHash . toString ( ) ,
167184 {
168- ...COOKIES_OPTIONS ,
185+ ...cookiesOptions ,
169186 // Here we use the shortest max age to force to ask again for expired consent
170- maxAge : CONSENT_ADVERTISING_MAX_AGE ,
187+ maxAge : consentAdvertisingMaxAge ,
171188 } ,
172189 )
173190 setNeedsConsent ( false )
174191 } ,
175- [ integrationsHash ] ,
192+ [
193+ integrationsHash ,
194+ consentAdvertisingMaxAge ,
195+ consentMaxAge ,
196+ cookiePrefix ,
197+ cookiesOptions ,
198+ ] ,
176199 )
177200
178201 const isSegmentAllowed = useMemo (
0 commit comments