blob: 7dc1c44ac28902e11c3e1ce432a0556ffcbc0560 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2019 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5const TITLE = 'title';
6const LOCATION = 'location';
7const DIMENSION1 = 'dimension1';
8const SET = 'set';
9
10/**
11 * Track page-to-page navigation via google analytics. Global window.ga
12 * is set in server rendered HTML.
13 *
14 * @param {string} page
15 * @param {string} userDisplayName
16 */
17export const trackPageChange = (page = '', userDisplayName = '') => {
18 ga(SET, TITLE, `Issue ${page}`);
19 if (page.startsWith('user')) {
20 ga(SET, TITLE, 'A user page');
21 ga(SET, LOCATION, 'A user page URL');
22 }
23
24 if (userDisplayName) {
25 ga(SET, DIMENSION1, 'Logged in');
26 } else {
27 ga(SET, DIMENSION1, 'Not logged in');
28 }
29
30 ga('send', 'pageview');
31};