From 55736ff91db59b0117f2939cf22e4fb8477cf618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Wed, 27 Oct 2021 15:10:19 -0300 Subject: [PATCH 01/16] adding cookiebot plugin --- gatsby-config.js | 6 ++++++ package.json | 1 + yarn.lock | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/gatsby-config.js b/gatsby-config.js index c95282ddc..af57a69b9 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -215,6 +215,12 @@ module.exports = { // selfHostedOrigin: "YOUR_SELF_HOSTED_ORIGIN", }, }, + { + resolve: "gatsby-plugin-cookiebot", + options: { + cookiebotId: "e11e4375-71b9-426d-a76d-61eae3ddc08f", // Required. Site's Cookiebot ID. + }, + }, { resolve: `gatsby-plugin-manifest`, options: { diff --git a/package.json b/package.json index 7c82b7a03..2a3fba6c4 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "gatsby": "^2.32.13", "gatsby-cli": "^2.11.5", "gatsby-image": "^2.3.1", + "gatsby-plugin-cookiebot": "^1.0.1", "gatsby-plugin-create-client-paths": "^2.3.1", "gatsby-plugin-feed": "^3.4.0", "gatsby-plugin-google-analytics": "^2.10.0", diff --git a/yarn.lock b/yarn.lock index cd46cb3fc..46169e5ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8601,6 +8601,13 @@ gatsby-page-utils@^0.9.1: lodash "^4.17.20" micromatch "^4.0.2" +gatsby-plugin-cookiebot@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/gatsby-plugin-cookiebot/-/gatsby-plugin-cookiebot-1.0.1.tgz#f388d3704f89ccfe8c7581da73d65c7549755c4c" + integrity sha512-kCi2XzlIc9r7qxlz1uQe03NwrbvL/k415lQ8u4j5wA20jyI3oq+g7FtOUpNB/y6IeNUyA3kMC9BlzS2X2YhCPQ== + dependencies: + react "^17.0.2" + gatsby-plugin-create-client-paths@^2.3.1: version "2.8.0" resolved "https://registry.yarnpkg.com/gatsby-plugin-create-client-paths/-/gatsby-plugin-create-client-paths-2.8.0.tgz#17b0811c3e5dbb2f940b7bc7212817f37524e366" @@ -16110,6 +16117,14 @@ react@^16.13.1, react@^16.8.0, react@^16.8.4, react@^16.8.6: object-assign "^4.1.1" prop-types "^15.6.2" +react@^17.0.2: + version "17.0.2" + resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037" + integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + reactcss@^1.2.0: version "1.2.3" resolved "https://registry.yarnpkg.com/reactcss/-/reactcss-1.2.3.tgz#c00013875e557b1cf0dfd9a368a1c3dab3b548dd" From 851dd5acedb75d51a3b67ccf4b3f2d19eb41eec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Wed, 27 Oct 2021 15:12:00 -0300 Subject: [PATCH 02/16] adding cookieconsent to openinfra live --- src/templates/openinfra-live.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/templates/openinfra-live.js b/src/templates/openinfra-live.js index e28b1db71..0c14f0c50 100644 --- a/src/templates/openinfra-live.js +++ b/src/templates/openinfra-live.js @@ -49,7 +49,7 @@ export const OpenInfraLiveTemplate = ({
- +
@@ -167,7 +167,7 @@ export const OpenInfraLiveTemplate = ({
{moment.utc(episode.date).format("dddd, MMMM DD, YYYY")}
- +
@@ -248,7 +248,7 @@ export const OpenInfraLiveTemplate = ({
- +
From ba6786725ecfb001d788887888aa362584eafe4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Wed, 27 Oct 2021 15:15:51 -0300 Subject: [PATCH 03/16] adding nvmrc file --- .nvmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 000000000..5b0ad74a8 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +16.13.0 \ No newline at end of file From de6fd756da2adefe1939b8660b1f990b1dc14cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Wed, 27 Oct 2021 15:20:41 -0300 Subject: [PATCH 04/16] changing node version --- .nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nvmrc b/.nvmrc index 5b0ad74a8..21cff1fb0 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16.13.0 \ No newline at end of file +14.18.1 \ No newline at end of file From ddc9775329c0a6b57c197d559c47983dfe9776d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Wed, 27 Oct 2021 15:38:28 -0300 Subject: [PATCH 05/16] downgrade node version --- .nvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nvmrc b/.nvmrc index 21cff1fb0..d4cf210a5 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -14.18.1 \ No newline at end of file +14.15.5 \ No newline at end of file From e3ea15e7818a0d9442e34272a0b39c8fcacfafc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Wed, 27 Oct 2021 15:47:02 -0300 Subject: [PATCH 06/16] removing cookiebot plugin --- .nvmrc | 1 - gatsby-config.js | 8 +------- package.json | 3 +-- yarn.lock | 7 ------- 4 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc deleted file mode 100644 index d4cf210a5..000000000 --- a/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -14.15.5 \ No newline at end of file diff --git a/gatsby-config.js b/gatsby-config.js index af57a69b9..30710689b 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -214,13 +214,7 @@ module.exports = { // Defaults to https://www.googletagmanager.com // selfHostedOrigin: "YOUR_SELF_HOSTED_ORIGIN", }, - }, - { - resolve: "gatsby-plugin-cookiebot", - options: { - cookiebotId: "e11e4375-71b9-426d-a76d-61eae3ddc08f", // Required. Site's Cookiebot ID. - }, - }, + }, { resolve: `gatsby-plugin-manifest`, options: { diff --git a/package.json b/package.json index 2a3fba6c4..53783e97a 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,7 @@ "font-awesome": "^4.7.0", "gatsby": "^2.32.13", "gatsby-cli": "^2.11.5", - "gatsby-image": "^2.3.1", - "gatsby-plugin-cookiebot": "^1.0.1", + "gatsby-image": "^2.3.1", "gatsby-plugin-create-client-paths": "^2.3.1", "gatsby-plugin-feed": "^3.4.0", "gatsby-plugin-google-analytics": "^2.10.0", diff --git a/yarn.lock b/yarn.lock index 46169e5ed..09c979c41 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8601,13 +8601,6 @@ gatsby-page-utils@^0.9.1: lodash "^4.17.20" micromatch "^4.0.2" -gatsby-plugin-cookiebot@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/gatsby-plugin-cookiebot/-/gatsby-plugin-cookiebot-1.0.1.tgz#f388d3704f89ccfe8c7581da73d65c7549755c4c" - integrity sha512-kCi2XzlIc9r7qxlz1uQe03NwrbvL/k415lQ8u4j5wA20jyI3oq+g7FtOUpNB/y6IeNUyA3kMC9BlzS2X2YhCPQ== - dependencies: - react "^17.0.2" - gatsby-plugin-create-client-paths@^2.3.1: version "2.8.0" resolved "https://registry.yarnpkg.com/gatsby-plugin-create-client-paths/-/gatsby-plugin-create-client-paths-2.8.0.tgz#17b0811c3e5dbb2f940b7bc7212817f37524e366" From 4133b2d74698358e5215721f746458044a2c6020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Wed, 27 Oct 2021 19:12:10 -0300 Subject: [PATCH 07/16] adding data-src --- gatsby-config.js | 2 +- package.json | 2 +- src/templates/openinfra-live.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gatsby-config.js b/gatsby-config.js index 30710689b..c95282ddc 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -214,7 +214,7 @@ module.exports = { // Defaults to https://www.googletagmanager.com // selfHostedOrigin: "YOUR_SELF_HOSTED_ORIGIN", }, - }, + }, { resolve: `gatsby-plugin-manifest`, options: { diff --git a/package.json b/package.json index 53783e97a..7c82b7a03 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "font-awesome": "^4.7.0", "gatsby": "^2.32.13", "gatsby-cli": "^2.11.5", - "gatsby-image": "^2.3.1", + "gatsby-image": "^2.3.1", "gatsby-plugin-create-client-paths": "^2.3.1", "gatsby-plugin-feed": "^3.4.0", "gatsby-plugin-google-analytics": "^2.10.0", diff --git a/src/templates/openinfra-live.js b/src/templates/openinfra-live.js index 0c14f0c50..4e64a6544 100644 --- a/src/templates/openinfra-live.js +++ b/src/templates/openinfra-live.js @@ -49,7 +49,7 @@ export const OpenInfraLiveTemplate = ({
- +
@@ -167,7 +167,7 @@ export const OpenInfraLiveTemplate = ({
{moment.utc(episode.date).format("dddd, MMMM DD, YYYY")}
- +
@@ -248,7 +248,7 @@ export const OpenInfraLiveTemplate = ({
- +
From a3e54e50e83d0d4d60d3920b833750e57e84be7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Fri, 29 Oct 2021 11:03:29 -0300 Subject: [PATCH 08/16] testing headers in ssr --- gatsby-ssr.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/gatsby-ssr.js b/gatsby-ssr.js index d4c762c12..22ff6b4a4 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -1,3 +1,4 @@ +import React from "react" import { SSRWrapper } from "./src/state/ReduxWrapper" // @see https://www.gatsbyjs.com/docs/adding-redux-store/ export const wrapRootElement = SSRWrapper; @@ -20,4 +21,55 @@ global.window.matchMedia = function () { } global.Blob = Blob -global.XMLHttpRequest = XMLHttpRequest \ No newline at end of file +global.XMLHttpRequest = XMLHttpRequest + +const isProduction = process.env.NODE_ENV === "production"; + +console.log('is production?', isProduction); + +export const onPreRenderHTML = (args, pluginOptions) => { + const { blockGtm = true, manualMode = true, includeInDevelopment = true, } = pluginOptions; + // Do not modify scripts when in development. Can be overriden with plugin options. + if (!isProduction || !includeInDevelopment) + return; + const { getHeadComponents, replaceHeadComponents, getPreBodyComponents, replacePreBodyComponents, } = args; + const headComponents = getHeadComponents(); + // Headcomponents needs to be assigned to a new + const newHeadComponents = headComponents.map((component) => { + if (component.type === "script") { + if (component.key === "plugin-google-tagmanager" && + manualMode && + blockGtm && + isProduction // gatsby-plugin-google-tagmanager will thrown an error if the script has not been loaded in development + ) { + // Add Cookiebot manual mode data attribute to GTM script + return (React.createElement("script", Object.assign({ "data-cookieconsent": "statistics", type: "text/plain", key: component.key }, component.props))); + } + } + return component; + }); + replaceHeadComponents(newHeadComponents); + const preBodyComponents = getPreBodyComponents(); + const newPreBodyComponents = preBodyComponents.map((component) => { + if (component.type === "noscript") { + if (component.key === "plugin-google-tagmanager" && + manualMode && + blockGtm && + isProduction // gatsby-plugin-google-tagmanager will thrown an error if the script has not been loaded in development + ) { + // Add Cookiebot manual mode data attribute to GTM noscript's iframe script + const gtmIframeStr = component.props.dangerouslySetInnerHTML.__html; + // Add data attribute to string + const gtmIframeStrWithCookiebotManualMode = gtmIframeStr.substr(0, 8) + + 'data-cookieconsent="statistics" ' + + gtmIframeStr.substr(8); + const newProps = Object.assign({}, component.props); + newProps.dangerouslySetInnerHTML.__html = + gtmIframeStrWithCookiebotManualMode; + return React.createElement("noscript", Object.assign({ key: component.key }, newProps)); + } + } + return component; + }); + replacePreBodyComponents(newPreBodyComponents); +}; \ No newline at end of file From fa58175f1f40642d562e86c02b28cbdad99ed538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Fri, 29 Oct 2021 11:13:34 -0300 Subject: [PATCH 09/16] change cookiebot id add linkedin plugin to ssr --- gatsby-ssr.js | 2 +- src/components/SEO.js | 2 +- src/pages/legal/privacy-policy/index.md | 2 +- src/templates/blog-post.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gatsby-ssr.js b/gatsby-ssr.js index 22ff6b4a4..04e2a4182 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -37,7 +37,7 @@ export const onPreRenderHTML = (args, pluginOptions) => { // Headcomponents needs to be assigned to a new const newHeadComponents = headComponents.map((component) => { if (component.type === "script") { - if (component.key === "plugin-google-tagmanager" && + if ((component.key === "plugin-google-tagmanager" || component.key === "gatsby-plugin-linkedin-insight") && manualMode && blockGtm && isProduction // gatsby-plugin-google-tagmanager will thrown an error if the script has not been loaded in development diff --git a/src/components/SEO.js b/src/components/SEO.js index db3c2e079..431e0c9e8 100644 --- a/src/components/SEO.js +++ b/src/components/SEO.js @@ -20,7 +20,7 @@ const SEO = ({ seo = {} }) => { return ( <> - + diff --git a/src/pages/legal/privacy-policy/index.md b/src/pages/legal/privacy-policy/index.md index b3b31a2aa..42adfc67e 100644 --- a/src/pages/legal/privacy-policy/index.md +++ b/src/pages/legal/privacy-policy/index.md @@ -381,4 +381,4 @@ We may revise our Privacy Policy at any time by posting a revision on our websit ##### Cookies - + diff --git a/src/templates/blog-post.js b/src/templates/blog-post.js index 6c99aa4d7..39b4078e0 100644 --- a/src/templates/blog-post.js +++ b/src/templates/blog-post.js @@ -83,7 +83,7 @@ const BlogPost = ({ isLoggedUser, data }) => { contentComponent={HTMLContent} helmet={ - + {`${post.frontmatter.seo.title ? post.frontmatter.seo.title : post.frontmatter.title}`} From a445b91fd21cdc8489a362c31b1c2fe0ad79bb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Fri, 29 Oct 2021 11:28:45 -0300 Subject: [PATCH 10/16] testing another approach for ssr --- gatsby-ssr.js | 78 ++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 47 deletions(-) diff --git a/gatsby-ssr.js b/gatsby-ssr.js index 04e2a4182..18ad5c850 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -23,53 +23,37 @@ global.window.matchMedia = function () { global.Blob = Blob global.XMLHttpRequest = XMLHttpRequest -const isProduction = process.env.NODE_ENV === "production"; - -console.log('is production?', isProduction); - -export const onPreRenderHTML = (args, pluginOptions) => { - const { blockGtm = true, manualMode = true, includeInDevelopment = true, } = pluginOptions; - // Do not modify scripts when in development. Can be overriden with plugin options. - if (!isProduction || !includeInDevelopment) - return; - const { getHeadComponents, replaceHeadComponents, getPreBodyComponents, replacePreBodyComponents, } = args; - const headComponents = getHeadComponents(); - // Headcomponents needs to be assigned to a new - const newHeadComponents = headComponents.map((component) => { - if (component.type === "script") { - if ((component.key === "plugin-google-tagmanager" || component.key === "gatsby-plugin-linkedin-insight") && - manualMode && - blockGtm && - isProduction // gatsby-plugin-google-tagmanager will thrown an error if the script has not been loaded in development - ) { - // Add Cookiebot manual mode data attribute to GTM script - return (React.createElement("script", Object.assign({ "data-cookieconsent": "statistics", type: "text/plain", key: component.key }, component.props))); - } +export const onPreRenderHTML = ({ + getHeadComponents, + replaceHeadComponents, + getPreBodyComponents, + replacePreBodyComponents, + getPostBodyComponents, + replacePostBodyComponents +}) => { + console.log("onPreRenderHTML"); + let headComponents = getHeadComponents() + console.log("onPreRenderHTML::getHeadComponents"); + headComponents = headComponents.map(h => { + console.log(h) + if (h.type === 'script') { + return { ...h, props: { ...h.props, 'data-cookieconsent': 'ignore' } } } - return component; + return h; }); - replaceHeadComponents(newHeadComponents); - const preBodyComponents = getPreBodyComponents(); - const newPreBodyComponents = preBodyComponents.map((component) => { - if (component.type === "noscript") { - if (component.key === "plugin-google-tagmanager" && - manualMode && - blockGtm && - isProduction // gatsby-plugin-google-tagmanager will thrown an error if the script has not been loaded in development - ) { - // Add Cookiebot manual mode data attribute to GTM noscript's iframe script - const gtmIframeStr = component.props.dangerouslySetInnerHTML.__html; - // Add data attribute to string - const gtmIframeStrWithCookiebotManualMode = gtmIframeStr.substr(0, 8) + - 'data-cookieconsent="statistics" ' + - gtmIframeStr.substr(8); - const newProps = Object.assign({}, component.props); - newProps.dangerouslySetInnerHTML.__html = - gtmIframeStrWithCookiebotManualMode; - return React.createElement("noscript", Object.assign({ key: component.key }, newProps)); - } - } - return component; + replaceHeadComponents(headComponents); + let preBodyComponents = getPreBodyComponents(); + console.log("onPreRenderHTML::getPreBodyComponents"); + preBodyComponents = preBodyComponents.map(bc => { + console.log(bc) + return bc; + }); + replacePreBodyComponents(preBodyComponents) + let postBodyComponents = getPostBodyComponents(); + console.log("onPreRenderHTML::getPostBodyComponents"); + postBodyComponents = postBodyComponents.map(bc => { + console.log(bc) + return bc; }); - replacePreBodyComponents(newPreBodyComponents); -}; \ No newline at end of file + replacePostBodyComponents(postBodyComponents) +} \ No newline at end of file From a51a00c8d066740ee7d193c707e8247536a19525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Fri, 29 Oct 2021 11:31:34 -0300 Subject: [PATCH 11/16] testing add localforage --- package.json | 1 + src/state/ReduxWrapper.js | 3 ++- yarn.lock | 15 +++++++-------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 7c82b7a03..2dfd070ea 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "immutability-helper": "2.9.1", "immutable": "^3.7.6", "jsdom": "^16.2.2", + "localforage": "^1.10.0", "lodash": "^4.17.15", "lodash-webpack-plugin": "^0.11.4", "moment": "^2.24.0", diff --git a/src/state/ReduxWrapper.js b/src/state/ReduxWrapper.js index 93bf60d40..4011acce0 100644 --- a/src/state/ReduxWrapper.js +++ b/src/state/ReduxWrapper.js @@ -1,4 +1,5 @@ import React from 'react'; +import localforage from 'localforage'; import { Provider } from 'react-redux'; import { createStore, applyMiddleware, compose } from 'redux'; import { loggedUserReducer } from 'openstack-uicore-foundation/lib/reducers'; @@ -17,7 +18,7 @@ const clientId = typeof window === 'object' ? window.OAUTH2_CLIENT_ID : process. const config = { key: `root_${clientId}`, - storage, + storage: localforage, } const persistedReducers = persistCombineReducers(config, { diff --git a/yarn.lock b/yarn.lock index 09c979c41..ff20d7be8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11975,6 +11975,13 @@ loader-utils@^1.0.1, loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2 emojis-list "^3.0.0" json5 "^1.0.1" +localforage@^1.10.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.10.0.tgz#5c465dc5f62b2807c3a84c0c6a1b1b3212781dd4" + integrity sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg== + dependencies: + lie "3.1.1" + localforage@^1.7.3: version "1.7.3" resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.7.3.tgz#0082b3ca9734679e1bd534995bdd3b24cf10f204" @@ -16110,14 +16117,6 @@ react@^16.13.1, react@^16.8.0, react@^16.8.4, react@^16.8.6: object-assign "^4.1.1" prop-types "^15.6.2" -react@^17.0.2: - version "17.0.2" - resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037" - integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - reactcss@^1.2.0: version "1.2.3" resolved "https://registry.yarnpkg.com/reactcss/-/reactcss-1.2.3.tgz#c00013875e557b1cf0dfd9a368a1c3dab3b548dd" From 882838bee0a73d01122e4e18113d076481d23a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Fri, 29 Oct 2021 11:45:26 -0300 Subject: [PATCH 12/16] revert ssr changes --- gatsby-ssr.js | 78 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/gatsby-ssr.js b/gatsby-ssr.js index 18ad5c850..04e2a4182 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -23,37 +23,53 @@ global.window.matchMedia = function () { global.Blob = Blob global.XMLHttpRequest = XMLHttpRequest -export const onPreRenderHTML = ({ - getHeadComponents, - replaceHeadComponents, - getPreBodyComponents, - replacePreBodyComponents, - getPostBodyComponents, - replacePostBodyComponents -}) => { - console.log("onPreRenderHTML"); - let headComponents = getHeadComponents() - console.log("onPreRenderHTML::getHeadComponents"); - headComponents = headComponents.map(h => { - console.log(h) - if (h.type === 'script') { - return { ...h, props: { ...h.props, 'data-cookieconsent': 'ignore' } } +const isProduction = process.env.NODE_ENV === "production"; + +console.log('is production?', isProduction); + +export const onPreRenderHTML = (args, pluginOptions) => { + const { blockGtm = true, manualMode = true, includeInDevelopment = true, } = pluginOptions; + // Do not modify scripts when in development. Can be overriden with plugin options. + if (!isProduction || !includeInDevelopment) + return; + const { getHeadComponents, replaceHeadComponents, getPreBodyComponents, replacePreBodyComponents, } = args; + const headComponents = getHeadComponents(); + // Headcomponents needs to be assigned to a new + const newHeadComponents = headComponents.map((component) => { + if (component.type === "script") { + if ((component.key === "plugin-google-tagmanager" || component.key === "gatsby-plugin-linkedin-insight") && + manualMode && + blockGtm && + isProduction // gatsby-plugin-google-tagmanager will thrown an error if the script has not been loaded in development + ) { + // Add Cookiebot manual mode data attribute to GTM script + return (React.createElement("script", Object.assign({ "data-cookieconsent": "statistics", type: "text/plain", key: component.key }, component.props))); + } } - return h; + return component; }); - replaceHeadComponents(headComponents); - let preBodyComponents = getPreBodyComponents(); - console.log("onPreRenderHTML::getPreBodyComponents"); - preBodyComponents = preBodyComponents.map(bc => { - console.log(bc) - return bc; - }); - replacePreBodyComponents(preBodyComponents) - let postBodyComponents = getPostBodyComponents(); - console.log("onPreRenderHTML::getPostBodyComponents"); - postBodyComponents = postBodyComponents.map(bc => { - console.log(bc) - return bc; + replaceHeadComponents(newHeadComponents); + const preBodyComponents = getPreBodyComponents(); + const newPreBodyComponents = preBodyComponents.map((component) => { + if (component.type === "noscript") { + if (component.key === "plugin-google-tagmanager" && + manualMode && + blockGtm && + isProduction // gatsby-plugin-google-tagmanager will thrown an error if the script has not been loaded in development + ) { + // Add Cookiebot manual mode data attribute to GTM noscript's iframe script + const gtmIframeStr = component.props.dangerouslySetInnerHTML.__html; + // Add data attribute to string + const gtmIframeStrWithCookiebotManualMode = gtmIframeStr.substr(0, 8) + + 'data-cookieconsent="statistics" ' + + gtmIframeStr.substr(8); + const newProps = Object.assign({}, component.props); + newProps.dangerouslySetInnerHTML.__html = + gtmIframeStrWithCookiebotManualMode; + return React.createElement("noscript", Object.assign({ key: component.key }, newProps)); + } + } + return component; }); - replacePostBodyComponents(postBodyComponents) -} \ No newline at end of file + replacePreBodyComponents(newPreBodyComponents); +}; \ No newline at end of file From b9bdfb9acf90ab4c20654c8836990bcb29e25fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Fri, 29 Oct 2021 14:07:25 -0300 Subject: [PATCH 13/16] cookiebot blocking mode --- src/components/SEO.js | 2 +- src/templates/blog-post.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/SEO.js b/src/components/SEO.js index 431e0c9e8..533a75dff 100644 --- a/src/components/SEO.js +++ b/src/components/SEO.js @@ -20,7 +20,7 @@ const SEO = ({ seo = {} }) => { return ( <> - + diff --git a/src/templates/blog-post.js b/src/templates/blog-post.js index 39b4078e0..e7f136439 100644 --- a/src/templates/blog-post.js +++ b/src/templates/blog-post.js @@ -83,7 +83,7 @@ const BlogPost = ({ isLoggedUser, data }) => { contentComponent={HTMLContent} helmet={ - + {`${post.frontmatter.seo.title ? post.frontmatter.seo.title : post.frontmatter.title}`} From 9692639d8a7e6037127f4163bf530debe0a543b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Mon, 1 Nov 2021 13:30:04 -0300 Subject: [PATCH 14/16] using cookiebot id for openinfra --- src/components/SEO.js | 2 +- src/pages/legal/privacy-policy/index.md | 2 +- src/templates/blog-post.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/SEO.js b/src/components/SEO.js index 533a75dff..9796a2570 100644 --- a/src/components/SEO.js +++ b/src/components/SEO.js @@ -20,7 +20,7 @@ const SEO = ({ seo = {} }) => { return ( <> - + diff --git a/src/pages/legal/privacy-policy/index.md b/src/pages/legal/privacy-policy/index.md index 42adfc67e..b3b31a2aa 100644 --- a/src/pages/legal/privacy-policy/index.md +++ b/src/pages/legal/privacy-policy/index.md @@ -381,4 +381,4 @@ We may revise our Privacy Policy at any time by posting a revision on our websit ##### Cookies - + diff --git a/src/templates/blog-post.js b/src/templates/blog-post.js index e7f136439..8a167594b 100644 --- a/src/templates/blog-post.js +++ b/src/templates/blog-post.js @@ -83,7 +83,7 @@ const BlogPost = ({ isLoggedUser, data }) => { contentComponent={HTMLContent} helmet={ - + {`${post.frontmatter.seo.title ? post.frontmatter.seo.title : post.frontmatter.title}`} From 1c051a810b83246aa98683bb5915532f49bca1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Mon, 1 Nov 2021 18:10:31 -0300 Subject: [PATCH 15/16] using nocookie youtube for no consent --- src/templates/openinfra-live.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/templates/openinfra-live.js b/src/templates/openinfra-live.js index 4e64a6544..886d9f72f 100644 --- a/src/templates/openinfra-live.js +++ b/src/templates/openinfra-live.js @@ -27,6 +27,11 @@ export const OpenInfraLiveTemplate = ({ const [today, setToday] = useState(moment().utc().unix()) const [ready, setReady] = useState(false) + const noCookieYoutube = (url) => { + const regex = /youtube/; + return url.replace(regex, 'youtube-nocookie'); + } + useEffect(() => { fetch(`https://timeintervalsince1970.appspot.com/`) .then(response => response.json()) @@ -49,7 +54,8 @@ export const OpenInfraLiveTemplate = ({
- + +
@@ -142,7 +148,7 @@ export const OpenInfraLiveTemplate = ({
- +
@@ -167,7 +173,8 @@ export const OpenInfraLiveTemplate = ({
{moment.utc(episode.date).format("dddd, MMMM DD, YYYY")}
- + +
@@ -235,7 +242,7 @@ export const OpenInfraLiveTemplate = ({ })} {/* End single episode */}
- +
@@ -248,7 +255,8 @@ export const OpenInfraLiveTemplate = ({
- + +
From 5a27f5d19b6db7c12593a852d691d1e823847215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Fri, 5 Nov 2021 12:12:05 -0300 Subject: [PATCH 16/16] update clientId --- src/state/ReduxWrapper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/state/ReduxWrapper.js b/src/state/ReduxWrapper.js index 4011acce0..2e864356a 100644 --- a/src/state/ReduxWrapper.js +++ b/src/state/ReduxWrapper.js @@ -14,7 +14,7 @@ const onBeforeLift = () => { console.log("reading state ...") } -const clientId = typeof window === 'object' ? window.OAUTH2_CLIENT_ID : process.env.OAUTH2_CLIENT_ID +const clientId = process.env.OAUTH2_CLIENT_ID; const config = { key: `root_${clientId}`,