Skip to content

Commit

Permalink
Revert "Use existing consent and then delete existing consent"
Browse files Browse the repository at this point in the history
This reverts commit cc4a2e9.
  • Loading branch information
mysticfalconvt committed Mar 13, 2024
1 parent a25814c commit bff72c3
Showing 1 changed file with 0 additions and 54 deletions.
54 changes: 0 additions & 54 deletions src/cookies/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/// <reference types="cookiebot-sdk" />

import { getCookieValue } from './utils/getCookieValue';
import { optionalTypeCheck } from './utils/optionalTypeCheck';

export const ANALYTICS_COOKIE_NAME = 'CookieConsent';
export const DEPRECATED_ANALYTICS_COOKIE_NAME = 'stardogAnalyticsConsent';

export type AnalyticsConsent = {
marketing: boolean;
Expand All @@ -13,24 +9,7 @@ export type AnalyticsConsent = {
statistics: boolean;
};

export type DeprecatedAnalyticsConsent = {
consented: boolean;
identity?: string;
};

export const getAnalyticsConsent = (): AnalyticsConsent | null => {
const deprecatedCookie = getDeprecatedAnalyticsConsentCookie();
if (deprecatedCookie) {
const consented = deprecatedCookie.consented;
// delete the deprecated cookie
document.cookie = `${DEPRECATED_ANALYTICS_COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;`;
return {
marketing: consented,
necessary: consented,
preferences: consented,
statistics: consented,
};
}
if (!window.Cookiebot || !window.Cookiebot.hasResponse) {
return null;
}
Expand All @@ -42,36 +21,3 @@ export const getAnalyticsConsent = (): AnalyticsConsent | null => {
preferences: window.Cookiebot.consent.preferences,
};
};

export const decodeAnalyticsCookie = (
rawConsentCookie: string
): DeprecatedAnalyticsConsent | null => {
try {
const decoded = JSON.parse(atob(rawConsentCookie));
const consented: boolean = decoded.consented;
const identity: string = decoded.identity;

if (
typeof consented !== 'boolean' ||
!optionalTypeCheck(identity, 'string')
) {
throw new Error('invalid cookie');
}

return {
consented,
identity,
};
} catch {
return null;
}
};

export const getDeprecatedAnalyticsConsentCookie =
(): DeprecatedAnalyticsConsent | null => {
const rawConsentCookie = getCookieValue(DEPRECATED_ANALYTICS_COOKIE_NAME);
if (!rawConsentCookie) {
return null;
}
return decodeAnalyticsCookie(rawConsentCookie);
};

0 comments on commit bff72c3

Please sign in to comment.