Skip to content

Commit

Permalink
Fix for usnat supported api lookup (#1804)
Browse files Browse the repository at this point in the history
## Why?

Since 19/11/2034 ~ 18:00 UTC the consent state property `doNotSell` is
being set to true for all US users regardless of their consent choice.
This mean third party integrations that check for `doNotSell` before
loading are not running e.g. prebid, comscore and a9 (Amazon ads).

### gppData

We read the `gppData` object as provided by Sourcepoint:

<img
src="https://github.com/user-attachments/assets/fec25081-79dc-4e89-b19e-d7c032f91061"
width="300px" />

### supportedAPIs string

In order to lookup the usnat metadata we read the
`gppData.supportedAPIs` property and split the string to set the
`supportedAPIs` string (e.g. `usnat`)

### supportedAPIs lookup

We then use the `supportedAPIs` string to lookup the property on
`gppData.parsedSection[supportedAPIs]`

However currently the `supportedAPIs` string is resolving to `usnat` but
the property on `gppData.parsedSection` is `usnatv1`

This causes the lookup to fail and sets `doNotSell` to true.

## What are you changing?

This change updates the logic so rather than using the `supportedAPIs`
string it directly attempts to read the first object in
`gppData.parsedSection`.
  • Loading branch information
arelra authored Nov 23, 2024
2 parents 42da65c + fa2491c commit fdecbd8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-taxis-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/libs': patch
---

Fix cmp usnat supported api lookup
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { getConsentState } from './getConsentState.ts';
jest.mock('./api');

describe('getConsentState', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('gets the gpp consent state correctly - doNotSell is false', async () => {
getGPPData.mockResolvedValue(gppDataCanSell);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ 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];

const supportedAPIs = gppData.supportedAPIs[0]?.split(':')[1]; // E.G: '7:usnatv1', '8:uscav1'

if (supportedAPIs) {
//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;
if (supportedAPI) {
// 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;
}

return {
Expand Down

0 comments on commit fdecbd8

Please sign in to comment.