Skip to content

Commit

Permalink
Merge 9c2e7f2 into 58f7015
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsola-guardian authored Dec 11, 2024
2 parents 58f7015 + 9c2e7f2 commit 68a61d2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-dancers-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/libs': minor
---

Stop showing CMP on info pages
1 change: 1 addition & 0 deletions @types/window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ declare global {
tests?: ServerSideTests;
page?: {
isPreview: boolean;
section?: string;
};
stage?: string;
isDev?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isExcludedFromCMP } from './exclusionList.ts';

describe('isExcludedFromCMP', () => {
test('should return false if empty', () => {
expect(isExcludedFromCMP('')).toBe(false);
});

test('should return false if param not in sectionExclusionList', () => {
expect(isExcludedFromCMP('foo')).toBe(false);
});

test('should return true if param in sectionExclusionList', () => {
expect(isExcludedFromCMP('info')).toBe(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const sectionExclusionList = ['info', 'help', 'community', 'identity'];

export const isExcludedFromCMP = (pageSection: string): boolean => {
console.log('pageSection', pageSection);
return sectionExclusionList.some((section) => section === pageSection);
};
17 changes: 12 additions & 5 deletions libs/@guardian/libs/src/consent-management-platform/sourcepoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { log } from '../logger/logger';
import { isExcludedFromCMP } from './exclusionList';
import { setCurrentFramework } from './getCurrentFramework';
import { isGuardianDomain } from './lib/domain';
import { mark } from './lib/mark';
Expand Down Expand Up @@ -73,6 +74,7 @@ export const init = (framework: ConsentFramework, pubData = {}): void => {

log('cmp', `framework: ${framework}`);
log('cmp', `frameworkMessageType: ${frameworkMessageType}`);
const pageSection = window.guardian?.config?.page?.section as string;

window._sp_queue = [];
/* istanbul ignore next */
Expand All @@ -83,6 +85,7 @@ export const init = (framework: ConsentFramework, pubData = {}): void => {
propertyHref: getPropertyHref(framework),
targetingParams: {
framework,
excludePage: isExcludedFromCMP(pageSection),
},
pubData: { ...pubData, cmpInitTimeUtc: new Date().getTime() },

Expand Down Expand Up @@ -194,11 +197,15 @@ export const init = (framework: ConsentFramework, pubData = {}): void => {

switch (framework) {
case 'tcfv2':
window._sp_.config.gdpr = {
targetingParams: {
framework,
},
};
{
const pageSection = window.guardian?.config?.page?.section as string;
window._sp_.config.gdpr = {
targetingParams: {
framework,
excludePage: isExcludedFromCMP(pageSection),
},
};
}
break;
case 'usnat':
window._sp_.config.usnat = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ declare global {
propertyId?: number;
targetingParams: {
framework: ConsentFramework;
excludePage: boolean;
};
ccpa?: {
targetingParams?: {
Expand All @@ -45,6 +46,7 @@ declare global {
gdpr?: {
targetingParams?: {
framework: ConsentFramework;
excludePage: boolean;
};
};
usnat?: {
Expand Down

0 comments on commit 68a61d2

Please sign in to comment.