Skip to content

Commit

Permalink
feat: add privacy features required scripts to all build.washingtonpo…
Browse files Browse the repository at this point in the history
…st.com pages [SRED-2] (#367)

* feat: add privacy features required scripts to all build.washingtonpost.com pages [SRED-2]

* refactor: use Script component from next js

* fix: use wp_geo cookie instead of wp_ak_ot in displayConfig and tcfString privacy scripts

* chore: include package-lock changes

* fix: invert logic on checking wp_geo to remove iab_banner in displayConfig

* fix: use OR when checking gtml to remove iab_banner in displayConfig

* fix: make changes requested by Aram

* fix: remove extra paren

* fix: add string to console log

* fix: wrap function in Script correctly
  • Loading branch information
hs4man21 authored Apr 14, 2023
1 parent c5be884 commit bf67fa1
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 0 deletions.
167 changes: 167 additions & 0 deletions build.washingtonpost.com/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint no-empty: ["error", { "allowEmptyCatch": true }] */
/* eslint-disable @typescript-eslint/no-this-alias */
import React from "react";
import { ThemeProvider } from "next-themes";
import Script from "next/script";
Expand Down Expand Up @@ -95,6 +97,171 @@ function App({ Component, pageProps }) {
disableTransitionOnChange={false}
enableColorScheme={false}
>
<link rel="preconnect" href="https://www.googletagmanager.com" />
<Script
id="pwapiConfig"
src="https://www.washingtonpost.com/subscribe/static/tetro-client/fusion/tetro.min.js"
async=""
/>
<Script id="displayConfig">
{`(() => {
window.dQ = window.dQ || {};
window.dQ.hold = window.dQ.hold || [];
var geoCookie = document.cookie.match("(^|;) ?wp_geo=([^;]*)(;|$)")
? RegExp.$2
: "";
window.dQ.participants = ["iab_banner", "softwall"];
// Removed iab_banner to support gradual rollout. Will remove upon completion.
if (
geoCookie.indexOf("|EEA") === -1
) {
window.dQ.participants = window.dQ.participants.filter(
(element) => element !== "iab_banner"
);
}
// Define placeholder function early. Will be replaced by Tetro client.
if (typeof window.registerDisplay !== "function") {
window.registerDisplay = (...args) => {
window.dQ.hold.push(args[0]);
};
}
})()`}
</Script>
<Script id="tcfString">
{`(() => {
var OneTrustTCFStub;
var geoCookie = document.cookie.match("(^|;) ?wp_geo=([^;]*)(;|$)")
? RegExp.$2
: "";
if (
(geoCookie.indexOf("|EEA") >= 0 ||
(window && window.location.href.indexOf("otr=eea") >= 0))
) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
OneTrustTCFStub = (function (e) {
"use strict";
var t = function () {
var o = this;
(this.LOCATOR_NAME = "__tcfapiLocator"),
(this.win = window),
(this.init = function () {
for (; o.win; ) {
try {
if (o.win.frames[o.LOCATOR_NAME]) {
o.cmpFrame = o.win;
break;
}
} catch (e) {}
if (o.win === window.top) break;
o.win = o.win.parent;
}
o.cmpFrame ||
(o.addFrame(),
(o.win.__tcfapi = o.executeTcfApi),
(o.win.receiveOTMessage = o.receiveIabMessage),
(o.win.attachEvent || o.win.addEventListener)(
"message",
o.win.receiveOTMessage,
!1
));
}),
(this.addFrame = function () {
var e = o.win.document,
t = !!o.win.frames[o.LOCATOR_NAME];
if (!t)
if (e.body) {
var i = e.createElement("iframe");
(i.style.cssText = "display:none"),
(i.name = o.LOCATOR_NAME),
i.setAttribute("title", "TCF Locator"),
e.body.appendChild(i);
} else setTimeout(o.addFrame, 5);
return !t;
}),
(this.receiveIabMessage = function (a) {
var n = "string" == typeof a.data,
e = {};
try {
e = n ? JSON.parse(a.data) : a.data;
} catch (e) {}
if (e && e.__tcfapiCall) {
var t = e.__tcfapiCall,
r = t.callId,
i = t.command,
s = t.parameter,
c = t.version;
o.executeTcfApi(
i,
s,
function (e, t) {
var i = {
__tcfapiReturn: {
returnValue: e,
success: t,
callId: r,
},
};
a &&
a.source &&
a.source.postMessage &&
a.source.postMessage(
n ? JSON.stringify(i) : i,
"*"
);
},
c
);
}
}),
(this.executeTcfApi = function () {
for (var e = [], t = 0; t < arguments.length; t++)
e[t] = arguments[t];
if (!e.length) return o.win.__tcfapi.a || [];
if ("setGdprApplies" === e[0])
3 < e.length &&
2 === parseInt(e[1], 10) &&
"boolean" == typeof e[3] &&
((o.gdprApplies = e[3]),
"function" == typeof e[2] && e[2]("set", !0));
else {
var i = e[0],
a = e[1],
n = e[2],
r = e[3];
"function" == typeof n &&
i &&
("ping" === i
? o.getPingReq(n, o.gdprApplies)
: o.addToQ(i, a, n, r));
}
}),
(this.addToQ = function (e, t, i, a) {
var n = o.win.__tcfapi;
(n.a = n.a || []), n.a.push([e, t, i, a]);
}),
(this.getPingReq = function (e, t) {
void 0 === t && (t = void 0),
e({
gdprApplies: t,
cmpLoaded: !1,
cmpStatus: "stub",
apiVersion: "2.0",
});
}),
this.init();
},
i = new t();
return (e.TCF = t), (e.tcfStub = i), e;
})({});
} else {
// do nothing
}
})()`}
</Script>
<Script
async
src="https://www.googletagmanager.com/gtm.js?id=GTM-WHNNX8B"
/>
<Script id="gtm-script" strategy="afterInteractive">
{`
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
Expand Down
30 changes: 30 additions & 0 deletions package-lock.json

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

4 comments on commit bf67fa1

@vercel
Copy link

@vercel vercel bot commented on bf67fa1 Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wpds-ui-kit-vitejs-example – ./apps/vite-project

wpds-ui-kit-vitejs-example.preview.now.washingtonpost.com
wpds-ui-kit-vitejs-example-git-main.preview.now.washingtonpost.com

@vercel
Copy link

@vercel vercel bot commented on bf67fa1 Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on bf67fa1 Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wpds-ui-kit – ./build.washingtonpost.com

build.washingtonpost.com
wpds-ui-kit-git-main.preview.now.washingtonpost.com
wpds-ui-kit.preview.now.washingtonpost.com

@vercel
Copy link

@vercel vercel bot commented on bf67fa1 Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wpds-ui-kit-storybook – ./

wpds-ui-kit-storybook.preview.now.washingtonpost.com
wpds-ui-kit-storybook-git-main.preview.now.washingtonpost.com

Please sign in to comment.