Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use applicableSections and supportedAPIs to get consentState #1818

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions .changeset/twenty-parrots-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/libs': patch
---

Use applicableSections and supportedAPI to get consent state in the US
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ import { getGPPData } from './api';
export const getConsentState: () => Promise<USNATConsentState> = async () => {
let doNotSell = false; // Opt-Out
const gppData = await getGPPData();
const supportedAPI = Object.values(gppData.parsedSections)[0];

if (supportedAPI) {
// Get applicableSections
const applicableSections = gppData.applicableSections[0]; // e.g. '7' for usnat
akinsola-guardian marked this conversation as resolved.
Show resolved Hide resolved

// Find the supported API
const supportedAPI = gppData.supportedAPIs.find(
(api) => applicableSections && api.includes(applicableSections.toString()),
); // Find string that contains the applicableSection i.e. (7) in '7:usnat'
akinsola-guardian marked this conversation as resolved.
Show resolved Hide resolved

// Get parsedSections key and object
const parsedSectionKey = supportedAPI
? supportedAPI.split(':')[1]
: undefined; // i.e. get 'usnat' from '7:usnat'

const parsedSection = parsedSectionKey
? gppData.parsedSections[parsedSectionKey]
: undefined; // Get the gpp consent object with the key

if (parsedSection) {
// https://github.com/InteractiveAdvertisingBureau/Global-Privacy-Platform/blob/main/Sections/US-National/IAB%20Privacy%E2%80%99s%20National%20Privacy%20Technical%20Specification.md
// 0 Not Applicable. SharingOptOutNotice value was not applicable or no notice was provided, 1 Opted Out, 2 Did Not Opt Out
doNotSell = supportedAPI.SaleOptOut !== 2 || supportedAPI.Gpc;
doNotSell = parsedSection.SaleOptOut !== 2 || parsedSection.Gpc;
}

return {
Expand Down