Skip to content

Commit

Permalink
Merge 4f61167 into 73990ee
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsola-guardian authored Oct 2, 2024
2 parents 73990ee + 4f61167 commit dbe54cd
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 141 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-nails-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/commercial': minor
---

Updates @guardian/libs to latest version which migrated frameworks from ccpa to usnat. Therefore, commercial needed to be updated to reflect this.
2 changes: 1 addition & 1 deletion docs/e2e-testing/# E2E testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- TCF: If the user doesn't consent we shouldn't show ads.
- TCF: Ads don't render until the user gives consent.
- AUS: Check if a user selects "non personalized advertising" that the targeting is different.
- CCPA: Check if a user selects "do not sell my information" that the targeting is different.
- USNAT: Check if a user selects "do not sell my information" that the targeting is different.

- Lower priorities features:
- Commercial metrics
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@guardian/eslint-config-typescript": "^12.0.0",
"@guardian/identity-auth": "^3.0.0",
"@guardian/identity-auth-frontend": "^5.0.0",
"@guardian/libs": "18.0.2",
"@guardian/libs": "19.0.0",
"@guardian/prettier": "8.0.1",
"@guardian/source": "8.0.0",
"@playwright/test": "1.46.0",
Expand Down Expand Up @@ -127,7 +127,7 @@
"@guardian/core-web-vitals": "^7.0.0",
"@guardian/identity-auth": "^3.0.0",
"@guardian/identity-auth-frontend": "^5.0.0",
"@guardian/libs": "^18.0.0",
"@guardian/libs": "^19.1.0",
"@guardian/source": "^8.0.0",
"typescript": "~5.5.3"
},
Expand Down
38 changes: 26 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 19 additions & 9 deletions src/core/send-commercial-metrics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ConsentState } from '@guardian/libs';
import type { ConsentState, USNATConsentState } from '@guardian/libs';
import { onConsent } from '@guardian/libs';
import { EventTimer } from './event-timer';
import {
Expand Down Expand Up @@ -103,16 +103,26 @@ const tcfv2AllConsentExceptPurpose8: ConsentState = {
framework: 'tcfv2',
};

const ccpaConsent: ConsentState = {
ccpa: { doNotSell: false },
const usnatNonConsentObject: USNATConsentState = {
doNotSell: true,
signalStatus: 'ready',
};

const usnatConsentObject: USNATConsentState = {
doNotSell: false,
signalStatus: 'ready',
};

const usnatConsent: ConsentState = {
usnat: usnatConsentObject,
canTarget: true,
framework: 'ccpa',
framework: 'usnat',
};

const ccpaNonConsent: ConsentState = {
ccpa: { doNotSell: true },
const usnatNonConsent: ConsentState = {
usnat: usnatNonConsentObject,
canTarget: false,
framework: 'ccpa',
framework: 'usnat',
};

const setVisibility = (value: 'hidden' | 'visible'): void => {
Expand Down Expand Up @@ -212,7 +222,7 @@ describe('send commercial metrics', () => {
});

it('sends metrics when non-TCFv2 user (i.e. USA or Australia) consents', async () => {
mockOnConsent(ccpaConsent);
mockOnConsent(usnatConsent);

await initCommercialMetrics({
pageViewId: PAGE_VIEW_ID,
Expand All @@ -231,7 +241,7 @@ describe('send commercial metrics', () => {
});

it('sends metrics when non-TCFv2 user (i.e. USA or Australia) does not consent', async () => {
mockOnConsent(ccpaNonConsent);
mockOnConsent(usnatNonConsent);

await initCommercialMetrics({
pageViewId: PAGE_VIEW_ID,
Expand Down
58 changes: 36 additions & 22 deletions src/core/targeting/build-page-targeting.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { ConsentState, TCFv2ConsentState } from '@guardian/libs';
import type {
ConsentState,
TCFv2ConsentState,
USNATConsentState,
} from '@guardian/libs';
import { cmp as cmp_, setCookie, storage } from '@guardian/libs';
import { getAuthStatus as getAuthStatus_ } from 'lib/identity/api';
import type { AuthStatus } from 'lib/identity/api';
Expand Down Expand Up @@ -52,17 +56,27 @@ const mockViewport = (width: number, height: number): void => {
});
};

// CCPA
const ccpaWithConsentMock: ConsentState = {
ccpa: { doNotSell: false },
const usnatConsent: USNATConsentState = {
doNotSell: false,
signalStatus: 'ready',
};

const usnatNonConsent: USNATConsentState = {
doNotSell: true,
signalStatus: 'ready',
};

// USNAT
const usnatWithConsentMock: ConsentState = {
usnat: usnatConsent,
canTarget: true,
framework: 'ccpa',
framework: 'usnat',
};

const ccpaWithoutConsentMock: ConsentState = {
ccpa: { doNotSell: true },
const usnatWithoutConsentMock: ConsentState = {
usnat: usnatNonConsent,
canTarget: false,
framework: 'ccpa',
framework: 'usnat',
};

// AUS
Expand Down Expand Up @@ -258,15 +272,15 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).pa,
).toBe('t');
expect(
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithoutConsentMock,
consentState: usnatWithoutConsentMock,
isSignedIn: true,
}).pa,
).toBe('f');
Expand All @@ -293,15 +307,15 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).rdp,
).toBe('f');
expect(
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithoutConsentMock,
consentState: usnatWithoutConsentMock,
isSignedIn: true,
}).rdp,
).toBe('t');
Expand Down Expand Up @@ -598,7 +612,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).permutive,
).toEqual(['1', '2', '3']);
Expand All @@ -612,7 +626,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('5');
Expand All @@ -624,7 +638,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('16-19');
Expand All @@ -636,7 +650,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('30plus');
Expand All @@ -648,7 +662,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('0');
Expand All @@ -660,7 +674,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).fr,
).toEqual('0');
Expand All @@ -672,7 +686,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithoutConsentMock,
consentState: usnatWithoutConsentMock,
isSignedIn: true,
}).fr,
).toEqual('0');
Expand Down Expand Up @@ -902,8 +916,8 @@ describe('Build Page Targeting', () => {
});

it.each([
[ccpaWithConsentMock, '9'],
[ccpaWithoutConsentMock, '9'],
[usnatWithConsentMock, '9'],
[usnatWithoutConsentMock, '9'],

[ausWithConsentMock, '9'],
[ausWithoutConsentMock, '9'],
Expand Down Expand Up @@ -1126,7 +1140,7 @@ describe('Build Page Targeting', () => {
buildPageTargeting({
adFree: false,
clientSideParticipations: {},
consentState: ccpaWithConsentMock,
consentState: usnatWithConsentMock,
isSignedIn: true,
}).firstvisit,
).toBeUndefined();
Expand Down
Loading

0 comments on commit dbe54cd

Please sign in to comment.