Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | // 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 | |
| 5 | const TITLE = 'title'; |
| 6 | const LOCATION = 'location'; |
| 7 | const DIMENSION1 = 'dimension1'; |
| 8 | const 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 | */ |
| 17 | export 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 | }; |