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

Stop loading the cmp if user is on info page #1847

Merged
merged 14 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
akinsola-guardian marked this conversation as resolved.
Show resolved Hide resolved
---

Stop showing CMP on info pages
akinsola-guardian marked this conversation as resolved.
Show resolved Hide resolved
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,5 @@
const sectionExclusionList = ['info', 'help'];

export const isExcludedFromCMP = (pageSection: string | undefined): boolean => {
return sectionExclusionList.some((section) => section === pageSection);
};
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 @@ -75,6 +76,8 @@ export const init = (framework: ConsentFramework, pubData = {}): void => {
log('cmp', `framework: ${framework}`);
log('cmp', `frameworkMessageType: ${frameworkMessageType}`);

const pageSection = window.guardian?.config?.page?.section;

window._sp_queue = [];
/* istanbul ignore next */
window._sp_ = {
Expand All @@ -84,6 +87,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 @@ -198,6 +202,7 @@ export const init = (framework: ConsentFramework, pubData = {}): void => {
window._sp_.config.gdpr = {
targetingParams: {
framework,
excludePage: isExcludedFromCMP(pageSection),
},
};
break;
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
Loading