Skip to content
Open
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
9 changes: 7 additions & 2 deletions packages/clarity-js/src/data/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ export function consentv2(consentState: ConsentState = defaultStatus, source: nu
function getConsentData(consentState: ConsentState): ConsentData {
let consent: ConsentData = {
source: consentState.source ?? ConsentSource.Implicit,
ad_Storage: consentState.ad_Storage === Constant.Granted ? BooleanFlag.True : BooleanFlag.False,
analytics_Storage: consentState.analytics_Storage === Constant.Granted ? BooleanFlag.True : BooleanFlag.False,
//TODO: Add consentStatus as fallback once https://github.com/microsoft/clarity/pull/992/files is merged.
ad_Storage: consentValue(consentState.ad_Storage),
analytics_Storage: consentValue(consentState.analytics_Storage)
};

return consent;
Expand All @@ -202,6 +203,10 @@ function normalizeConsent(value: unknown, fallback: string = Constant.Denied): s
return typeof value === 'string' ? value.toLowerCase() : fallback;
}

function consentValue(value: string, fallback: BooleanFlag = BooleanFlag.False): BooleanFlag {
return value === Constant.Granted ? BooleanFlag.True : value === Constant.Denied ? BooleanFlag.False : fallback;
}

export function clear(): void {
// Clear any stored information in the cookie that tracks session information so we can restart fresh the next time
setCookie(Constant.SessionKey, Constant.Empty, 0);
Expand Down