Using google analytics

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

  1. meteor add reywood:iron-router-ga

  2. Router.configure({
    trackPageView: true

  3. Add settings.json
    “public”: {
    “ga”: {
    “id”: “UA-11551129-4”

  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.

1 Like

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.set({ page: window.location.pathname }) // this will send to google your page of entry in the webapp

          history.listen(location => { // your page change listener . In this case here, 'history' comes from the
          // 'history' npm.
            ReactGA.set({ page: location.pathname })

1 Like

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 });
1 Like