Skip to content

Commit

Permalink
fix(WWP-3314): use latest MSPS config
Browse files Browse the repository at this point in the history
  • Loading branch information
kamenboev committed Jan 16, 2024
1 parent fa7d891 commit 0efedc7
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 110 deletions.
4 changes: 2 additions & 2 deletions site/pages/components/consent-settings-link.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Custom and required props are detailed below:
<Prop name="gdpr" type="boolean">
If you're using the unified Sourcepoint script for GDPR.
</Prop>
<Prop name="ccpa" type="boolean">
If you're using the unified Sourcepoint script for CCPA.
<Prop name="usnat" type="boolean">
If you're using the unified Sourcepoint script for USNAT.
</Prop>
<Prop name="tabToOpen" type="'purposes' | 'vendors' | 'features' | 'purposes-li' | 'vendors-li'">
If you're using the unified Sourcepoint script for GDPR, you can choose the opening view of the modal.
Expand Down
17 changes: 8 additions & 9 deletions site/pages/components/consent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ please see Sourcepoint [Unified Script or Web Implementation](https://docs.sourc
for a full reference.
<br/>
<br/>
In order to add Sourcepoint script for GDPR or CCPA you must add at least an empty gdpr or ccpa object (see below).
To enable default MSPA configuration ccpa object should contain 'includeGppApi' parameter set to 'true'. Instructions and additional MSPS settings can be found in <a href="https://docs.sourcepoint.com/hc/en-us/articles/18007731422099-Enable-GPP-Multi-State-Privacy-String-MSPS-with-U-S-Privacy-CCPA-solution" target="_blank">this Sourcepoint guide</a>.
In order to add Sourcepoint script for GDPR or USNAT you must add at least an empty gdpr or usnat object (see below).
The usnat object should contain 'includeUspApi' parameter set to 'true'. This enables both the older ccpa type string as well as the gpp string (part of the MSPS signal). Instructions and additional MSPS settings can be found in <a href="https://docs.sourcepoint.com/hc/en-us/articles/21455316499731#h_01HC0NYD93FV6MBBH6Y1NPCRMX" target="_blank">this Sourcepoint guide</a>.
<Prop name="accountId" type="number" required>
The accountId value associates the property with your organization's
Sourcepoint account. Your organization's accountId can be retrieved by
Expand All @@ -48,7 +48,7 @@ please see Sourcepoint [Unified Script or Web Implementation](https://docs.sourc
</Prop>
<Prop name="baseEndpoint" type="string">
A single server endpoint that serves the messaging experience.
For GDPR TCF, CCPA, GDPR Standard, and Custom Messaging, the baseEndpoint is https://cdn.privacy-mgmt.com.
For GDPR TCF, USNAT, GDPR Standard, and Custom Messaging, the baseEndpoint is https://cdn.privacy-mgmt.com.
</Prop>
<Prop name="isSPA" type="boolean">
When set to true, will confirm the implementation for a single page
Expand Down Expand Up @@ -116,8 +116,8 @@ please see Sourcepoint [Unified Script or Web Implementation](https://docs.sourc
targetingParams set within the gdpr object will override overall targetingParams
</Prop>
</Prop>
<Prop name="ccpa" type="object">
In order to surface a CCPA message to your clients, you will need to include the ccpa:{ } object in your client configuration script regardless of whether you configure any optional parameters.
<Prop name="usnat" type="object">
In order to surface a USNAT message to your clients, you will need to include the usnat:{ } object in your client configuration script regardless of whether you configure any optional parameters.
<Prop name="alwaysDisplayDNS" type="boolean">
Setting this parameter to true enables use cases where a Sourcepoint Do Not Sell (my data) notification is hardcoded.
</Prop>
Expand All @@ -132,11 +132,10 @@ please see Sourcepoint [Unified Script or Web Implementation](https://docs.sourc
<br/>
targetingParams set within the gdpr object will override overall targetingParams
</Prop>
<Prop name="includeGppApi" type="boolean | MSPATransactions">
Allows your organization to use the Multi-State Privacy String (MSPS). It is a signal that notifies downstream partners that participating publishers have provided end-users with specific notice and choice over data processing activities on their properties.
In order to set the default settings on the MSPS, set the includeGppApi parameter to true.
<Prop name="includeUspApi" type="boolean | MSPATransactions">
Including this flag as 'true' enables support for the existing (Legacy) USP string, part of CCPA.&nbsp;
MSPS settings could be customized by passing configuration object to the includeGppApi as&nbsp;
<a href="https://docs.sourcepoint.com/hc/en-us/articles/18007731422099-Enable-GPP-Multi-State-Privacy-String-MSPS-with-U-S-Privacy-CCPA-solution" target="_blank">shown here</a>.
<a href="https://docs.sourcepoint.com/hc/en-us/articles/21455316499731-GPP-Multi-State-Privacy-String-MSPS-Transition-readiness-web-and-app-" target="_blank">shown here</a>.
</Prop>
</Prop>
</Prop>
Expand Down
62 changes: 6 additions & 56 deletions src/consent/__tests__/__snapshots__/consent.test.tsx.snap

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/consent/__tests__/consent-settings-link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ describe('ConsentSettingsLink', () => {
gdpr: {
loadPrivacyManagerModal: expectedFunction,
},
ccpa: {
loadPrivacyManagerModal: expectedFunction,
},
};
(global as any).window._sp_ = sp;
(global as any).window._sp_usnat = {
loadPrivacyManagerModal: expectedFunction,
};
});

afterEach(() => {
Expand Down Expand Up @@ -61,10 +61,10 @@ describe('ConsentSettingsLink', () => {
);
});

test('call unified ccpa SourcePoint function', async () => {
test('call unified usnat SourcePoint function', async () => {
const link = await renderWithTheme(ConsentSettingsLink, {
privacyManagerId,
ccpa: true,
usnat: true,
}).findByRole('button');
fireEvent.click(link);

Expand Down
20 changes: 3 additions & 17 deletions src/consent/__tests__/consent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ describe('Consent', () => {
expect(fragment).toMatchSnapshot();
});

test('the Unified Consent V2 renders GPP correctly with default baseEndpoint', () => {
test('the Unified Consent V2 renders USNAT correctly', () => {
const fragment = renderToFragment(
<Consent
sourcePointConfigUnified={{
accountId: 259,
propertyHref: 'https://newskit.dev-news.co.uk',
ccpa: {
includeGppApi: true,
usnat: {
includeUspApi: true,
},
}}
reactHelmet={helmet}
Expand All @@ -109,20 +109,6 @@ describe('Consent', () => {
expect(fragment).toMatchSnapshot();
});

test('the Unified Consent V2 renders CCPA correctly', () => {
const fragment = renderToFragment(
<Consent
sourcePointConfigUnified={{
accountId: 259,
propertyHref: 'https://newskit.dev-news.co.uk',
ccpa: {},
}}
reactHelmet={helmet}
/>,
);
expect(fragment).toMatchSnapshot();
});

test('the Unified Consent V2 renders correctly with trailing slash on baseEndpoint', () => {
const fragment = renderToFragment(
<Consent
Expand Down
16 changes: 7 additions & 9 deletions src/consent/consent-settings-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ type SPWindowUnifiedGDPR = Window & {
};
};

type SPWindowUnifiedCCPA = Window & {
_sp_?: {
ccpa?: {
loadPrivacyManagerModal: (managerId: string) => void;
};
type SPWindowUnifiedUSNAT = Window & {
_sp_usnat?: {
loadPrivacyManagerModal: (managerId: string) => void;
};
};

Expand All @@ -29,7 +27,7 @@ export interface ConsentSettingsLinkProps extends Omit<LinkProps, 'href'> {
privacyManagerId: string;
children?: string;
gdpr?: boolean;
ccpa?: boolean;
usnat?: boolean;
tabToOpen?:
| 'purposes'
| 'vendors'
Expand All @@ -42,7 +40,7 @@ export const ConsentSettingsLink: React.FC<ConsentSettingsLinkProps> = ({
siteId,
privacyManagerId,
gdpr,
ccpa,
usnat,
tabToOpen,
children = 'Manage Consent',
...props
Expand All @@ -60,9 +58,9 @@ export const ConsentSettingsLink: React.FC<ConsentSettingsLinkProps> = ({
privacyManagerId,
tabToOpen,
);
} else if (ccpa) {
} else if (usnat) {
// eslint-disable-next-line no-underscore-dangle
(window as SPWindowUnifiedCCPA)._sp_!.ccpa!.loadPrivacyManagerModal(
(window as SPWindowUnifiedUSNAT)._sp_usnat!.loadPrivacyManagerModal(
privacyManagerId,
);
} else {
Expand Down
16 changes: 6 additions & 10 deletions src/consent/consent-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,18 @@ export const getUnifiedScripts = (config: SourcePointConfigUnified) => {
}
: false;

const ccpaStub = config.ccpa
const usnatStub = config.usnat
? {
content: `(function () { var e = false; var c = window; var t = document; function r() { if (!c.frames["__uspapiLocator"]) { if (t.body) { var a = t.body; var e = t.createElement("iframe"); e.style.cssText = "display:none"; e.name = "__uspapiLocator"; a.appendChild(e) } else { setTimeout(r, 5) } } } r(); function p() { var a = arguments; __uspapi.a = __uspapi.a || []; if (!a.length) { return __uspapi.a } else if (a[0] === "ping") { a[2]({ gdprAppliesGlobally: e, cmpLoaded: false }, true) } else { __uspapi.a.push([].slice.apply(a)) } } function l(t) { var r = typeof t.data === "string"; try { var a = r ? JSON.parse(t.data) : t.data; if (a.__cmpCall) { var n = a.__cmpCall; c.__uspapi(n.command, n.parameter, function (a, e) { var c = { __cmpReturn: { returnValue: a, success: e, callId: n.callId } }; t.source.postMessage(r ? JSON.stringify(c) : c, "*") }) } } catch (a) { } } if (typeof __uspapi !== "function") { c.__uspapi = p; __uspapi.msgHandler = l; c.addEventListener("message", l, false) } })();`,
}
: false;

const gppStub = config.ccpa?.includeGppApi
? {
content: `window.__gpp_addFrame=function(e){if(!window.frames[e])if(document.body){var t=document.createElement("iframe");t.style.cssText="display:none",t.name=e,document.body.appendChild(t)}else window.setTimeout(window.__gpp_addFrame,10,e)},window.__gpp_stub=function(){var e=arguments;if(__gpp.queue=__gpp.queue||[],__gpp.events=__gpp.events||[],!e.length||1==e.length&&"queue"==e[0])return __gpp.queue;if(1==e.length&&"events"==e[0])return __gpp.events;var t=e[0],p=e.length>1?e[1]:null,s=e.length>2?e[2]:null;if("ping"===t)p({gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[],gppString:"",parsedSections:{}},!0);else if("addEventListener"===t){"lastId"in __gpp||(__gpp.lastId=0),__gpp.lastId++;var n=__gpp.lastId;__gpp.events.push({id:n,callback:p,parameter:s}),p({eventName:"listenerRegistered",listenerId:n,data:!0,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[],gppString:"",parsedSections:{}}},!0)}else if("removeEventListener"===t){for(var a=!1,i=0;i<__gpp.events.length;i++)if(__gpp.events[i].id==s){__gpp.events.splice(i,1),a=!0;break}p({eventName:"listenerRemoved",listenerId:s,data:a,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[],gppString:"",parsedSections:{}}},!0)}else"hasSection"===t?p(!1,!0):"getSection"===t||"getField"===t?p(null,!0):__gpp.queue.push([].slice.apply(e))},window.__gpp_msghandler=function(e){var t="string"==typeof e.data;try{var p=t?JSON.parse(e.data):e.data}catch(e){p=null}if("object"==typeof p&&null!==p&&"__gppCall"in p){var s=p.__gppCall;window.__gpp(s.command,(function(p,n){var a={__gppReturn:{returnValue:p,success:n,callId:s.callId}};e.source.postMessage(t?JSON.stringify(a):a,"*")}),"parameter"in s?s.parameter:null,"version"in s?s.version:"1.1")}},"__gpp"in window&&"function"==typeof window.__gpp||(window.__gpp=window.__gpp_stub,window.addEventListener("message",window.__gpp_msghandler,!1),window.__gpp_addFrame("__gppLocator"));`,
content: `
(function () { var e = false; var c = window; var t = document; function r() { if (!c.frames["__uspapiLocator"]) { if (t.body) { var a = t.body; var e = t.createElement("iframe"); e.style.cssText = "display:none"; e.name = "__uspapiLocator"; a.appendChild(e) } else { setTimeout(r, 5) } } } r(); function p() { var a = arguments; __uspapi.a = __uspapi.a || []; if (!a.length) { return __uspapi.a } else if (a[0] === "ping") { a[2]({ gdprAppliesGlobally: e, cmpLoaded: false }, true) } else { __uspapi.a.push([].slice.apply(a)) } } function l(t) { var r = typeof t.data === "string"; try { var a = r ? JSON.parse(t.data) : t.data; if (a.__cmpCall) { var n = a.__cmpCall; c.__uspapi(n.command, n.parameter, function (a, e) { var c = { __cmpReturn: { returnValue: a, success: e, callId: n.callId } }; t.source.postMessage(r ? JSON.stringify(c) : c, "*") }) } } catch (a) { } } if (typeof __uspapi !== "function") { c.__uspapi = p; __uspapi.msgHandler = l; c.addEventListener("message", l, false) } })();
window.__gpp_addFrame=function(e){if(!window.frames[e])if(document.body){var t=document.createElement("iframe");t.style.cssText="display:none",t.name=e,document.body.appendChild(t)}else window.setTimeout(window.__gpp_addFrame,10,e)},window.__gpp_stub=function(){var e=arguments;if(__gpp.queue=__gpp.queue||[],__gpp.events=__gpp.events||[],!e.length||1==e.length&&"queue"==e[0])return __gpp.queue;if(1==e.length&&"events"==e[0])return __gpp.events;var t=e[0],p=e.length>1?e[1]:null,s=e.length>2?e[2]:null;if("ping"===t)p({gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[],gppString:"",parsedSections:{}},!0);else if("addEventListener"===t){"lastId"in __gpp||(__gpp.lastId=0),__gpp.lastId++;var n=__gpp.lastId;__gpp.events.push({id:n,callback:p,parameter:s}),p({eventName:"listenerRegistered",listenerId:n,data:!0,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[],gppString:"",parsedSections:{}}},!0)}else if("removeEventListener"===t){for(var a=!1,i=0;i<__gpp.events.length;i++)if(__gpp.events[i].id==s){__gpp.events.splice(i,1),a=!0;break}p({eventName:"listenerRemoved",listenerId:s,data:a,pingData:{gppVersion:"1.1",cmpStatus:"stub",cmpDisplayStatus:"hidden",signalStatus:"not ready",supportedAPIs:["2:tcfeuv2","5:tcfcav1","6:uspv1","7:usnatv1","8:uscav1","9:usvav1","10:uscov1","11:usutv1","12:usctv1"],cmpId:0,sectionList:[],applicableSections:[],gppString:"",parsedSections:{}}},!0)}else"hasSection"===t?p(!1,!0):"getSection"===t||"getField"===t?p(null,!0):__gpp.queue.push([].slice.apply(e))},window.__gpp_msghandler=function(e){var t="string"==typeof e.data;try{var p=t?JSON.parse(e.data):e.data}catch(e){p=null}if("object"==typeof p&&null!==p&&"__gppCall"in p){var s=p.__gppCall;window.__gpp(s.command,(function(p,n){var a={__gppReturn:{returnValue:p,success:n,callId:s.callId}};e.source.postMessage(t?JSON.stringify(a):a,"*")}),"parameter"in s?s.parameter:null,"version"in s?s.version:"1.1")}},"__gpp"in window&&"function"==typeof window.__gpp||(window.__gpp=window.__gpp_stub,window.addEventListener("message",window.__gpp_msghandler,!1),window.__gpp_addFrame("__gppLocator"));
`,
}
: false;

return [
gdprStub,
ccpaStub,
gppStub,
usnatStub,
{
content: `window._sp_ = ${JSON.stringify(
{
Expand Down
4 changes: 2 additions & 2 deletions src/consent/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export interface SourcePointConfigUnified {
groupPmId?: number;
targetingParams?: object;
};
ccpa?: {
usnat?: {
alwaysDisplayDNS?: boolean;
groupPmId?: number;
targetingParams?: object;
includeGppApi?: boolean | MSPATransactions;
includeUspApi?: boolean;
};
}

Expand Down

0 comments on commit 0efedc7

Please sign in to comment.