Skip to content

Commit

Permalink
Track page views on router history change
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Parisot committed Nov 30, 2021
1 parent 4d52691 commit 0abed93
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion front/gatsby/src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { lazy } from 'react'
import { render } from 'react-dom'
import { BrowserRouter as Router, Route, Switch, useParams, } from 'react-router-dom'
import { BrowserRouter as Router, Route, Switch, useParams, useHistory } from 'react-router-dom'
import { Provider } from 'react-redux'
import 'whatwg-fetch'

Expand Down Expand Up @@ -47,10 +47,24 @@ const ArticleID = (props) => {
)
}

const TrackPageViews = () => {
const history = useHistory()

history.listen(({ pathname, search, state }, action) => {
/* global _paq */
_paq.push(['setCustomUrl', '/' + pathname])
//_paq.push(['setDocumentTitle', 'My New Title'])
_paq.push(['trackPageView'])
})

return null
}

render(
<React.StrictMode>
<Provider store={store}>
<Router>
<TrackPageViews />
<Switch>
<Route path="/register">
<App layout="centered">
Expand Down

0 comments on commit 0abed93

Please sign in to comment.