From 0f564ba459528cfa98320d5853c742549b9b30c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Alby?= Date: Fri, 22 Oct 2021 10:02:41 +0200 Subject: [PATCH] Merge pull request #5442 from overleaf/ta-ga-v4 Add Google Analytics V4 Tags GitOrigin-RevId: 8841bd6a902efa15399b1a219ff7740635898fa1 --- services/web/app/src/infrastructure/ExpressLocals.js | 4 ++++ services/web/app/views/layout-marketing.pug | 8 ++++++++ services/web/app/views/layout.pug | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/services/web/app/src/infrastructure/ExpressLocals.js b/services/web/app/src/infrastructure/ExpressLocals.js index 72c1380b3c..526a4cbd03 100644 --- a/services/web/app/src/infrastructure/ExpressLocals.js +++ b/services/web/app/src/infrastructure/ExpressLocals.js @@ -280,6 +280,10 @@ module.exports = function (webRouter, privateApiRouter, publicApiRouter) { webRouter.use(function (req, res, next) { res.locals.gaToken = Settings.analytics && Settings.analytics.ga && Settings.analytics.ga.token + res.locals.gaTokenV4 = + Settings.analytics && + Settings.analytics.ga && + Settings.analytics.ga.tokenV4 res.locals.gaOptimizeId = _.get(Settings, ['analytics', 'gaOptimize', 'id']) next() }) diff --git a/services/web/app/views/layout-marketing.pug b/services/web/app/views/layout-marketing.pug index 356bd132da..23d5c6f56e 100644 --- a/services/web/app/views/layout-marketing.pug +++ b/services/web/app/views/layout-marketing.pug @@ -71,6 +71,14 @@ html( script(type="text/javascript", nonce=scriptNonce). window.ga = function() { console.log("would send to GA", arguments) }; + if (typeof(gaTokenV4) != "undefined") + script(async, nonce=scriptNonce, src='https://www.googletagmanager.com/gtag/js?id=' + gaTokenV4) + script(type="text/javascript", nonce=scriptNonce). + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', '#{gaTokenV4}'); + block meta meta(name="ol-csrfToken" content=csrfToken) //- Configure dynamically loaded assets (via webpack) to be downloaded from CDN diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index f9dae17e71..cffd0b58e7 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -68,6 +68,15 @@ html( script(type="text/javascript", nonce=scriptNonce). window.ga = function() { console.log("would send to GA", arguments) }; + if (typeof(gaTokenV4) != "undefined") + script(async, nonce=scriptNonce, src='https://www.googletagmanager.com/gtag/js?id=' + gaTokenV4) + script(type="text/javascript", nonce=scriptNonce). + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + + gtag('config', '#{gaTokenV4}'); + block meta meta(name="ol-csrfToken" content=csrfToken) //- Configure dynamically loaded assets (via webpack) to be downloaded from CDN