Просмотр исходного кода

Merge pull request #6597 from overleaf/ab-send-events-ga4

Send some events to GA4

GitOrigin-RevId: 7927cea14e6717aea033faa3d5f3e0f9efd6e672
Alexandre Bourdin 4 лет назад
Родитель
Сommit
6ce0df3106

+ 3 - 1
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)

+ 5 - 0
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 = {}) {