Skip to content

Commit 37b453a

Browse files
authored
feat(cookie-consent): export allowed, denied consents (#2772)
1 parent 3966096 commit 37b453a

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

.changeset/beige-bars-wonder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@scaleway/use-analytics": patch
3+
---
4+
5+
Add allowedConsents and denied consent on cookie consent provider

.changeset/giant-states-ask.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@scaleway/use-analytics": patch
3+
---
4+
5+
Fix readyness state

packages/use-analytics/src/analytics/useAnalytics.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function AnalyticsProvider<T extends Events>({
9292
// 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.
9393
useEffect(() => {
9494
let timer: ReturnType<typeof setTimeout> | undefined
95-
if (!isAnalyticsReady && !internalAnalytics && timeout) {
95+
if (!isAnalyticsReady && timeout) {
9696
if (shouldRenderOnlyWhenReady) {
9797
timer = setTimeout(() => setIsAnalyticsReady(true), timeout)
9898
onError?.(new Error('Analytics Setup Timeout'))
@@ -140,8 +140,7 @@ export function AnalyticsProvider<T extends Events>({
140140
normalizeIdsMigration(analytics)
141141

142142
onLoaded(rudderAnalytics)
143-
144-
setIsAnalyticsReady(true)
143+
setAnalytics(analytics)
145144
},
146145
...loadOptions,
147146
})

packages/use-analytics/src/cookies-consent/CookieConsentProvider.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ import { uniq } from '../helpers/array'
2222
import { IS_CLIENT } from '../helpers/isClient'
2323
import { stringToHash } from '../helpers/misc'
2424
import { isCategoryKind } from '../types'
25-
import type { Config, Consent, Destination, Destinations } from '../types'
25+
import type {
26+
CategoryKind,
27+
Config,
28+
Consent,
29+
Destination,
30+
Destinations,
31+
} from '../types'
2632

2733
type Context = {
2834
destinations: Destinations
@@ -185,12 +191,30 @@ export const CookieConsentProvider = ({
185191
],
186192
)
187193

194+
const allowedConsents = useMemo(
195+
() =>
196+
Object.keys(cookieConsent).filter(
197+
key => cookieConsent[key as CategoryKind],
198+
) as CategoryKind[],
199+
[cookieConsent],
200+
)
201+
202+
const deniedConsents = useMemo(
203+
() =>
204+
Object.keys(cookieConsent).filter(
205+
key => !allowedConsents.includes(key as CategoryKind),
206+
) as CategoryKind[],
207+
[cookieConsent, allowedConsents],
208+
)
209+
188210
const value = useMemo(
189211
() => ({
190212
destinations,
191213
needConsent,
192214
isDestinationsLoaded,
193215
categoriesConsent: cookieConsent,
216+
allowedConsents,
217+
deniedConsents,
194218
saveConsent,
195219
categories: CATEGORIES,
196220
cookies,
@@ -199,6 +223,8 @@ export const CookieConsentProvider = ({
199223
destinations,
200224
isDestinationsLoaded,
201225
needConsent,
226+
allowedConsents,
227+
deniedConsents,
202228
cookieConsent,
203229
saveConsent,
204230
cookies,

0 commit comments

Comments
 (0)