I have tried all the ways to install Google analytics in meteor. But, it does not work. I get tracking not installed. Has anyone successfully used Google analytics in meteor? Please let us know how you did it. Thanks
Steps followed while installing Google analytics
-
meteor add reywood:iron-router-ga
-
Router.configure({
trackPageView: true
}); -
Add settings.json
{
âpublicâ: {
âgaâ: {
âidâ: âUA-11551129-4â
}
}
} -
meteor deploy ***.com --settings settings.json
Why is it not working? Where did I go wrong? Thanks
also many are looking for flow router support.
You need a listener. The google tracker is a function which you need to invoke yourself whenever you need to. Be it a page change or another type of event (scroll into a view, press a button etc).
So, you need to listen to page changes.
Wherever you can console.log(âyour new page changedâ), you can invoke the google tracker function.
You can do this for instance in the first template you load, just to make sure the âwindowâ object has been already created.
You can even use a window.addEventListener(type, listener [, options])
Tracking with google or others is ârouter agnosticâ, web or Node technologies are sufficient to listen to changes.
const handleGoogleAnalytics = () => {
if (!window.GoogleAnalyticsObject) {
import('react-ga') // or your tracker
.then(ReactGA => {
ReactGA.initialize('xxxxxx')
ReactGA.set({ page: window.location.pathname }) // this will send to google your page of entry in the webapp
ReactGA.pageview(window.location.pathname)
history.listen(location => { // your page change listener . In this case here, 'history' comes from the
// 'history' npm.
ReactGA.set({ page: location.pathname })
ReactGA.pageview(location.pathname)
})
})
}
}
I had just run into this issue⌠basically, you need to make sure youâre using the latest GA plug-in and run this snippet for each route:
gtag('config', 'UA-XXXXXXXXXX', { page_path: CURRENT_ROUTE });