From 247125cc2033a204355105b4f7c4d12ff9b25c68 Mon Sep 17 00:00:00 2001 From: Kohei Yoshino Date: Tue, 6 Aug 2019 12:51:23 -0400 Subject: [PATCH] =?utf8?q?Bug=201529406=20-=20Record=20user=E2=80=99s=20lo?= =?utf8?q?gged-in/out=20status=20and=20track=20insiders=20with=20Google=20?= =?utf8?q?Analytics?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../global/header-additional_header.html.tmpl | 4 +-- .../hook/global/header-start.html.tmpl | 4 +-- .../GoogleAnalytics/web/js/analytics.js | 33 +++++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/extensions/GoogleAnalytics/template/en/default/hook/global/header-additional_header.html.tmpl b/extensions/GoogleAnalytics/template/en/default/hook/global/header-additional_header.html.tmpl index e1763dd98..f96e0d0f9 100644 --- a/extensions/GoogleAnalytics/template/en/default/hook/global/header-additional_header.html.tmpl +++ b/extensions/GoogleAnalytics/template/en/default/hook/global/header-additional_header.html.tmpl @@ -6,9 +6,9 @@ # defined by the Mozilla Public License, v. 2.0. #%] -[%# Disable tracking of DNT-enabled users, security group members as well as private bugs #%] +[%# Disable tracking of DNT-enabled users as well as private bugs #%] [% RETURN IF !Bugzilla.params.google_analytics_tracking_id || Bugzilla.cgi.http('dnt') == '1' || - user.in_group(Param('insidergroup')) || (bug.defined && bug.groups_in.size) %] + (bug.defined && bug.groups_in.size) %] { + 'use strict'; - if (meta.length) { - // Activate Google Analytics - window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; - ga('create', meta.attr('content'), 'auto'); - ga('set', 'anonymizeIp', true); - ga('set', 'location', meta.data('location')); - ga('set', 'title', meta.data('title')); - ga('set', 'transport', 'beacon'); - // Track page view - ga('send', 'pageview'); + const $meta = document.querySelector('meta[name="google-analytics"]'); + + if (!$meta) { + return; } -}); + + // Activate Google Analytics + window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; + ga('create', $meta.content, 'auto'); + ga('set', 'anonymizeIp', true); + ga('set', 'transport', 'beacon'); + // Record a crafted location (template name) and title instead of actual URL + ga('set', 'location', $meta.dataset.location); + ga('set', 'title', $meta.dataset.title); + // Custom Dimension: logged in (true) or out (false) + ga('set', 'dimension1', !!BUGZILLA.user.login); + // Track page view + ga('send', 'pageview'); +}, { once: true }); -- 2.47.3