How to integrate analytics script in meteor?

EDIT: Just found this solution.

Tracking user behaviour is super important. So what’s the standard way to implement an analytics script tag? For example, if I want to use something like hotjar or amplitude.

You could take a look at astronomer. This is a small instrumentation package which posts to astronomer.io, which has integrations for hotjar and amplitude among others. We use it and can recommend it. However, you should be aware that it is a freemium model.

1 Like

Excellent. I will check this out for sure. Have you seen any advantages to using something like amplitude over Google Analytics? I’ve got both set up for my app and have only been using GA. Not seeing the point in something like amplitude…?

@robfallows I just set up an account on astronomer.io and added the necessary fields and app id to my settings.json but I’m not seeing any events. I see their documentation is missing which doesn’t help, is there something else I am missing to register events and have them show up on the livestream?

I’m using the following code which I import in imports/server/main.js

import { Inject } from 'meteor/meteorhacks:inject-initial';
import { Meteor } from 'meteor/meteor';

let gaInit = '';
if (Meteor.settings.public.mode !== 'test') {
  gaInit = `
  <!-- Start Google Analytics -->
  <script>
    var trackingId = '${Meteor.settings.public.googleAnalytics.trackingId}';
    if (trackingId) {
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
      ga('create', trackingId, 'auto');
    }
  </script>
  <!-- End Google Analytics -->`;
}

Inject.rawHead('Inject the Google Analytics script at the beginning of the head', gaInit);

Sorry for the delay - this was a bug with the astronomer cdn. I’m assured it’s now fixed (it is for me), so your livestream should be working now.

Related question - I’m using reywood:iron-router-ga successfully. I can fire events to Google Analytics that are tracked to goals, etc.

I use Google Ads (formerly Adwords) to track conversions from the imported goals from Analytics. The conversion tracking works on my static landing page and associates events to ads/campaigns/etc in Google Ads. However, all of my in-app events fired in Meteor, while tracking successfully in Analytics, do not get populated or attributed in Google Ads. My app is on a different subdomain (e.g. app.myapp.com) and it must be clicked and logged into from the landing page, but I figured Google Ads should be smart enough to handle this. Doesn’t is use a cookie?

Anyone have any ideas? I’m using the Google Ads “import goals from analytics” strategy of conversion tracking versus using Google Ads direct conversion tracking. @reywood Any ideas?

EDIT: It looks like the conversion tracking is actually working in Google Ads for my in-app events imported via Analytics, but it’s WAY less than the actual amount of events being fired. So for example, if I have 20 paid upgrades in June, Analytics shows 20 paid upgrade goals, but Google Ads is only showing 3 conversions. So for some reason it’s not attributing the conversions to ads. I know not all upgrades are necessarily rooted in seeing a Google search ad, but I’m pretty sure it’s way higher than 15%. Will talk to the Google Ads folks. It may be my attribution model or something on the conversions. There’s a lot settings in Google Ads.

EDIT 2: It turns out the issue is actually Google Analytics not attributing my down-funnel paid upgrades to Google Ads. Upon deeper inspection Google Ads is reporting exactly what Analytics is telling it. The early-funnel actions (e.g. signups) are getting attributed to my PPC ads correctly, but not the later events (which happen later after using the freemium product, going to email, typing in the domain over again, etc.). Analytics is losing the connection to the PPC ad. The problem is I need to those to properly attribute in order to optimize ads and keywords to paid upgrades. Investigating now.

Sorry, I don’t have any experience with Google Ads, so I can’t be much help. Sounds like you’re on the right track though. Good luck!

1 Like