Skip to content

Commit 70b683c

Browse files
Stefen Alpergregberge
authored andcommitted
feat: track page titles (#22)
1 parent dc3d614 commit 70b683c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

packages/smooth-plugin-google-analytics/src/smooth-browser.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-env browser */
22
export function onRouteUpdate({ location }) {
33
// Don't track while developing.
4-
if (process.env.NODE_ENV === `production` && typeof ga === `function`) {
4+
if (process.env.NODE_ENV === 'production' && typeof ga === 'function') {
55
if (
66
location &&
7-
typeof window.excludeGAPaths !== `undefined` &&
7+
typeof window.excludeGAPaths !== 'undefined' &&
88
window.excludeGAPaths.some(rx => rx.test(location.pathname))
99
) {
1010
return
@@ -13,17 +13,16 @@ export function onRouteUpdate({ location }) {
1313
// wrap inside a timeout to make sure react-helmet is done with it's changes (https://github.com/gatsbyjs/gatsby/issues/9139)
1414
// 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
1515
const sendPageView = () => {
16-
window.ga(
17-
`set`,
18-
`page`,
19-
location
16+
window.ga('set', {
17+
page: location
2018
? location.pathname + location.search + location.hash
2119
: undefined,
22-
)
23-
window.ga(`send`, `pageview`)
20+
title: document.title,
21+
})
22+
window.ga('send', 'pageview')
2423
}
2524

26-
if (`requestAnimationFrame` in window) {
25+
if ('requestAnimationFrame' in window) {
2726
requestAnimationFrame(() => {
2827
requestAnimationFrame(sendPageView)
2928
})

0 commit comments

Comments
 (0)