Skip to content

Commit

Permalink
Check GPC for doNotSell (#1740)
Browse files Browse the repository at this point in the history
* Check GPC for doNotSell

* Created minor changeset

* Add test to check GPC behaviour
  • Loading branch information
akinsola-guardian authored Nov 7, 2024
1 parent 549868d commit 3936b1c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-humans-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/libs': minor
---

Checking for the Global Privacy Control setting in the user's browser for USNAT.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type GppParsedSections = Record<
{
Version: number;
SaleOptOut: number;
Gpc: boolean;
}
>;

Expand All @@ -20,4 +21,5 @@ export interface GPPData {
supportedAPIs: string[];
parsedSections: GppParsedSections;
signalStatus: GPPSignalStatus;
gpcEnabled: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"parsedSections": {
"usnatv1": {
"Version": 1,
"SaleOptOut": 2
"SaleOptOut": 2,
"Gpc": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"parsedSections": {
"usnatv1": {
"Version": 1,
"SaleOptOut": 1
"SaleOptOut": 1,
"Gpc": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ describe('getConsentState', () => {
expect(doNotSell).toBe(true);
});

it('gets the gpp consent state correctly if it gpc is true - doNotSell is true', async () => {
let gpcEnabled = gppDataCanSell;
gpcEnabled.parsedSections.usnatv1.Gpc = true;

getGPPData.mockResolvedValue(gpcEnabled);

const { doNotSell } = await getConsentState();

expect(getGPPData).toHaveBeenCalledTimes(1);
expect(doNotSell).toBe(true);
});

it('gets the gpp consent state correctly if it fails - doNotSell is false', async () => {
getGPPData.mockResolvedValue(gppDataFail);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ export const getConsentState: () => Promise<USNATConsentState> = async () => {
const supportedAPIs = gppData.supportedAPIs[0]?.split(':')[1]; // E.G: '7:usnatv1', '8:uscav1'

if (supportedAPIs) {
doNotSell = gppData.parsedSections[supportedAPIs]?.SaleOptOut !== 2; // 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 =
gppData.parsedSections[supportedAPIs]?.SaleOptOut !== 2 ||
gppData.parsedSections[supportedAPIs].Gpc;
// https://github.com/InteractiveAdvertisingBureau/Global-Privacy-Platform/blob/main/Sections/US-National/IAB%20Privacy%E2%80%99s%20National%20Privacy%20Technical%20Specification.md
}

return {
Expand Down

0 comments on commit 3936b1c

Please sign in to comment.