From 2f93c600874499d9df5e97afd8e98b8e684ec671 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdin Date: Thu, 3 Feb 2022 13:49:05 +0100 Subject: [PATCH] Merge pull request #6597 from overleaf/ab-send-events-ga4 Send some events to GA4 GitOrigin-RevId: 7927cea14e6717aea033faa3d5f3e0f9efd6e672 --- services/web/app/views/layout.pug | 4 +++- services/web/frontend/js/infrastructure/event-tracking.js | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/services/web/app/views/layout.pug b/services/web/app/views/layout.pug index 99137db290..d5483e1979 100644 --- a/services/web/app/views/layout.pug +++ b/services/web/app/views/layout.pug @@ -57,8 +57,10 @@ html( window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); - gtag('config', '#{gaTokenV4}'); + else + script(type = "text/javascript", nonce = scriptNonce). + window.gtag = function() { console.log("would send to GA4", arguments) }; block meta meta(name="ol-csrfToken" content=csrfToken) diff --git a/services/web/frontend/js/infrastructure/event-tracking.js b/services/web/frontend/js/infrastructure/event-tracking.js index a864769665..83b3e8dfaf 100644 --- a/services/web/frontend/js/infrastructure/event-tracking.js +++ b/services/web/frontend/js/infrastructure/event-tracking.js @@ -28,6 +28,11 @@ export function sendOnce(category, action, label, value) { export function sendMB(key, segmentation = {}) { sendBeacon(key, segmentation) + + if (typeof window.gtag !== 'function') return + if (['paywall-click', 'paywall-prompt', 'plans-page-click'].includes(key)) { + window.gtag('event', key, segmentation) + } } export function sendMBOnce(key, segmentation = {}) {