Skip to content

Commit

Permalink
Add mergeUserConsent
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsola-guardian committed Jan 13, 2025
1 parent 840cb98 commit 2f01a66
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getCookie } from '../cookies/getCookie';
import { PROPERTY_ID_MAIN, PROPERTY_ID_SUPPORT } from './lib/sourcepointConfig';
import type { SPUserConsent } from './types/tcfv2';

// https://sourcepoint-public-api.readme.io/reference/post_consent-v3-siteid-tcstring

export const mergeUserConsent = () => {
const consentUUID = getCookie({ name: 'consentUUID' });
const url = `https://cdn.privacy-mgmt.com/consent/tcfv2/consent/v3/${PROPERTY_ID_SUPPORT}/tcstring?consentUUID=${consentUUID}`;
const spUserConsentString = localStorage.getItem(
`_sp_user_consent_${PROPERTY_ID_MAIN}`,
);
const userConsent = JSON.parse(spUserConsentString ?? '{}') as SPUserConsent;

fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
euconsent: userConsent.gdpr?.euconsent,
}),
}).catch((error) => {
console.error('Error:', error);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PROPERTY_ID_SUPPORT,
SourcePointChoiceTypes,
} from './lib/sourcepointConfig';
import { mergeUserConsent } from './mergeUserConsent';
import { invokeCallbacks } from './onConsentChange';
import { stub } from './stub';
import type { ConsentFramework } from './types';
Expand Down Expand Up @@ -95,6 +96,10 @@ export const init = (
const isFeatureFlagEnabled = window.location.search.includes('CMP_COP');
const isMainSite = window.location.search.includes('CMP_MAIN');

if (!isMainSite) {
mergeUserConsent();
}

log('cmp', `framework: ${framework}`);
log('cmp', `frameworkMessageType: ${frameworkMessageType}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ export type TCPingStatusCode =
| 'visible'
| 'hidden'
| 'disabled';

export interface SPUserConsent {
gdpr?: {
euconsent?: string;
};
}

0 comments on commit 2f01a66

Please sign in to comment.