Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/beige-bars-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scaleway/use-analytics": patch
---

Add allowedConsents and denied consent on cookie consent provider
5 changes: 5 additions & 0 deletions .changeset/giant-states-ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scaleway/use-analytics": patch
---

Fix readyness state
5 changes: 2 additions & 3 deletions packages/use-analytics/src/analytics/useAnalytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function AnalyticsProvider<T extends Events>({
// 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.
useEffect(() => {
let timer: ReturnType<typeof setTimeout> | undefined
if (!isAnalyticsReady && !internalAnalytics && timeout) {
if (!isAnalyticsReady && timeout) {
if (shouldRenderOnlyWhenReady) {
timer = setTimeout(() => setIsAnalyticsReady(true), timeout)
onError?.(new Error('Analytics Setup Timeout'))
Expand Down Expand Up @@ -138,8 +138,7 @@ export function AnalyticsProvider<T extends Events>({
})

onLoaded(rudderAnalytics)

setIsAnalyticsReady(true)
setAnalytics(analytics)
},
...loadOptions,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import { uniq } from '../helpers/array'
import { IS_CLIENT } from '../helpers/isClient'
import { stringToHash } from '../helpers/misc'
import { isCategoryKind } from '../types'
import type { Config, Consent, Destination, Destinations } from '../types'
import type {
CategoryKind,
Config,
Consent,
Destination,
Destinations,
} from '../types'

type Context = {
destinations: Destinations
Expand Down Expand Up @@ -185,12 +191,30 @@ export const CookieConsentProvider = ({
],
)

const allowedConsents = useMemo(
() =>
Object.keys(cookieConsent).filter(
key => cookieConsent[key as CategoryKind],
) as CategoryKind[],
[cookieConsent],
)

const deniedConsents = useMemo(
() =>
Object.keys(cookieConsent).filter(
key => !allowedConsents.includes(key as CategoryKind),
) as CategoryKind[],
[cookieConsent, allowedConsents],
)

const value = useMemo(
() => ({
destinations,
needConsent,
isDestinationsLoaded,
categoriesConsent: cookieConsent,
allowedConsents,
deniedConsents,
saveConsent,
categories: CATEGORIES,
cookies,
Expand All @@ -199,6 +223,8 @@ export const CookieConsentProvider = ({
destinations,
isDestinationsLoaded,
needConsent,
allowedConsents,
deniedConsents,
cookieConsent,
saveConsent,
cookies,
Expand Down
Loading