blob: 52d117621252468f4aecb0a8cf8de124775a8564 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// 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};