Skip to content

Commit

Permalink
[1.0] Fixes 1317 Google Analytics plugin; updates attachHistory liste…
Browse files Browse the repository at this point in the history
…ner logic (gatsbyjs#1318)

* fixing expected object usage based on new api, addined editorconfig, preventing duplicate counting of pageviews

* remove lastpath backup

* update with destructuring

* issue-1317 prevents additional history listeners from being added

* also update development version
  • Loading branch information
camsjams authored and KyleAMathews committed Jul 1, 2017
1 parent b3975a5 commit f3eeb11
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{*.json, *.svg}]
indent_style = space
indent_size = 4

# Matches the exact package.json, or *rc
[{package.json,*.yml,*rc}]
indent_style = space
indent_size = 2
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-google-analytics/src/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exports.onRouteUpdate = function(location) {
exports.onRouteUpdate = function({ location }) {
// Don't track while developing.
if (process.env.NODE_ENV === `production`) {
ga(`set`, `page`, location.pathname)
ga(`set`, `page`, (location || {}).pathname)
ga(`send`, `pageview`)
}
}
10 changes: 6 additions & 4 deletions packages/gatsby/src/cache-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ window.___navigateTo = navigateTo
const history = createHistory()

function attachToHistory(history) {
window.___history = history
if(!window.___history) {
window.___history = history

history.listen((location, action) => {
apiRunner(`onRouteUpdate`, { location, action })
})
history.listen((location, action) => {
apiRunner(`onRouteUpdate`, { location, action })
})
}
}

function shouldUpdateScroll(prevRouterProps, { location: { pathname } }) {
Expand Down
10 changes: 6 additions & 4 deletions packages/gatsby/src/cache-dir/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ window.___loader = loader
const history = createHistory()

function attachToHistory(history) {
window.___history = history
if(!window.___history) {
window.___history = history

history.listen((location, action) => {
apiRunner(`onRouteUpdate`, { location, action })
})
history.listen((location, action) => {
apiRunner(`onRouteUpdate`, { location, action })
})
}
}

function shouldUpdateScroll(prevRouterProps, { location: { pathname } }) {
Expand Down

0 comments on commit f3eeb11

Please sign in to comment.