Skip to content

Commit

Permalink
fix(WWP-3314): sp config bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kamenboev committed Feb 14, 2024
1 parent beb06c2 commit ec9d80b
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions src/consent/consent-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ function replacer(key: string, value: string | Function | Object) {
: value;
}

function stringifySPContent(content: Object) {
return JSON.stringify(content, replacer).replace(/\\"/g, "'");
}

export const getV2Scripts = (config: SourcePointConfigTCFV2) => {
const baseEndpoint =
(config.baseEndpoint && config.baseEndpoint.replace(/\/$/, '')) ||
Expand All @@ -26,15 +30,12 @@ export const getV2Scripts = (config: SourcePointConfigTCFV2) => {
content: `!function () { var e = function () { var e, t = "__tcfapiLocator", a = [], n = window; for (; n;) { try { if (n.frames[t]) { e = n; break } } catch (e) { } if (n === window.top) break; n = n.parent } e || (!function e() { var a = n.document, r = !!n.frames[t]; if (!r) if (a.body) { var i = a.createElement("iframe"); i.style.cssText = "display:none", i.name = t, a.body.appendChild(i) } else setTimeout(e, 5); return !r }(), n.__tcfapi = function () { for (var e, t = arguments.length, n = new Array(t), r = 0; r < t; r++)n[r] = arguments[r]; if (!n.length) return a; if ("setGdprApplies" === n[0]) n.length > 3 && 2 === parseInt(n[1], 10) && "boolean" == typeof n[3] && (e = n[3], "function" == typeof n[2] && n[2]("set", !0)); else if ("ping" === n[0]) { var i = { gdprApplies: e, cmpLoaded: !1, cmpStatus: "stub" }; "function" == typeof n[2] && n[2](i) } else a.push(n) }, n.addEventListener("message", (function (e) { var t = "string" == typeof e.data, a = {}; try { a = t ? JSON.parse(e.data) : e.data } catch (e) { } var n = a.__tcfapiCall; n && window.__tcfapi(n.command, n.version, (function (a, r) { var i = { __tcfapiReturn: { returnValue: a, success: r, callId: n.callId } }; t && (i = JSON.stringify(i)), e.source.postMessage(i, "*") }), n.parameter) }), !1)) }; "undefined" != typeof module ? module.exports = e : e() }();`,
},
{
content: `window._sp_ = ${JSON.stringify(
{
config: {
...config,
baseEndpoint,
},
content: `window._sp_ = ${stringifySPContent({
config: {
...config,
baseEndpoint,
},
replacer,
)}`,
})}`,
},
{
src: `${baseEndpoint}/wrapperMessagingWithoutDetection.js`,
Expand Down Expand Up @@ -74,15 +75,12 @@ export const getUnifiedScripts = (config: SourcePointConfigUnified) => {
ccpaStub,
usnatStub,
{
content: `window._sp_ = ${JSON.stringify(
{
config: {
...config,
baseEndpoint,
},
content: `window._sp_ = ${stringifySPContent({
config: {
...config,
baseEndpoint,
},
replacer,
)}`,
})}`,
},
{
src: `${baseEndpoint}/unified/wrapperMessagingWithoutDetection.js`,
Expand All @@ -96,15 +94,12 @@ export const getNonTCFScripts = (config: SourcePointConfigNonTCFV1) => {
(config.baseEndpoint && config.baseEndpoint.replace(/\/$/, '')) ||
'https://cdn.privacy-mgmt.com';

const windowSP = `window._sp_ = ${JSON.stringify(
{
config: {
...config,
baseEndpoint,
},
const windowSP = `window._sp_ = ${stringifySPContent({
config: {
...config,
baseEndpoint,
},
replacer,
)}`;
})}`;

return [
{
Expand Down

0 comments on commit ec9d80b

Please sign in to comment.