|
1 | 1 | /* eslint-env browser */
|
2 | 2 | export function onRouteUpdate({ location }) {
|
3 | 3 | // Don't track while developing.
|
4 |
| - if (process.env.NODE_ENV === 'production' && typeof ga === 'function') { |
5 |
| - if ( |
6 |
| - location && |
7 |
| - typeof window.excludeGAPaths !== 'undefined' && |
8 |
| - window.excludeGAPaths.some(rx => rx.test(location.pathname)) |
9 |
| - ) { |
10 |
| - return |
11 |
| - } |
| 4 | + if (typeof ga !== 'function') return |
12 | 5 |
|
13 |
| - // wrap inside a timeout to make sure react-helmet is done with it's changes (https://github.com/gatsbyjs/gatsby/issues/9139) |
14 |
| - // reactHelmet is using requestAnimationFrame so we should use it too: https://github.com/nfl/react-helmet/blob/5.2.0/src/HelmetUtils.js#L296-L299 |
15 |
| - const sendPageView = () => { |
16 |
| - window.ga('set', { |
17 |
| - page: location |
18 |
| - ? location.pathname + location.search + location.hash |
19 |
| - : undefined, |
20 |
| - title: document.title, |
21 |
| - }) |
22 |
| - window.ga('send', 'pageview') |
23 |
| - } |
| 6 | + if ( |
| 7 | + location && |
| 8 | + typeof window.excludeGAPaths !== 'undefined' && |
| 9 | + window.excludeGAPaths.some(rx => rx.test(location.pathname)) |
| 10 | + ) { |
| 11 | + return |
| 12 | + } |
| 13 | + |
| 14 | + // wrap inside a timeout to make sure react-helmet is done with it's changes (https://github.com/gatsbyjs/gatsby/issues/9139) |
| 15 | + // reactHelmet is using requestAnimationFrame so we should use it too: https://github.com/nfl/react-helmet/blob/5.2.0/src/HelmetUtils.js#L296-L299 |
| 16 | + function sendPageView() { |
| 17 | + window.ga('set', { |
| 18 | + page: location |
| 19 | + ? location.pathname + location.search + location.hash |
| 20 | + : undefined, |
| 21 | + title: document.title, |
| 22 | + }) |
| 23 | + window.ga('send', 'pageview') |
| 24 | + } |
24 | 25 |
|
25 |
| - if ('requestAnimationFrame' in window) { |
26 |
| - requestAnimationFrame(() => { |
27 |
| - requestAnimationFrame(sendPageView) |
28 |
| - }) |
29 |
| - } else { |
30 |
| - // simulate 2 rAF calls |
31 |
| - setTimeout(sendPageView, 32) |
32 |
| - } |
| 26 | + if ('requestAnimationFrame' in window) { |
| 27 | + requestAnimationFrame(() => { |
| 28 | + requestAnimationFrame(sendPageView) |
| 29 | + }) |
| 30 | + } else { |
| 31 | + // simulate 2 rAF calls |
| 32 | + setTimeout(sendPageView, 32) |
33 | 33 | }
|
34 | 34 | }
|
0 commit comments