Installing & Troubleshooting Google Analytics 2013 (ga / analytics.js)

Setting up the new Google Universal Analytics (still in beta) is not completely obvious. You normally won't be able to send events from localhost and it will claim that "Tracking Not Installed." Here are some tips how to use Analytics from localhost and test it.

Enabling GA on a site running at localhost

You need to set cookieDomain to 'none' as suggested by BenSwayne as SO (see the docs):

ga('create', 'UA-XXXX-Y', { 'cookieDomain': 'none' });

Testing GA

To check that GA works:
  1. Enable GA from localhost as described above
  2. Open the Real-Time view in Analytics (GA - Reporting - Real-Time - Events) and
  3. In another window, open your webpage and use the Chrome Dev Tools' Console to send an event, f.ex.:
    ga('send', 'event', 'my_ga_test', 'it is working!')
  4. In the Network panel of Chrome Dev Tools, you should see a GET request for
    http://www.google-analytics.com/collect?...
  5. The event should appear on the dashboard in no/short time

Why is GA reporting "Status: Tracking Not Installed"?!

The status report is not reliable and can take up to 72 hrs (or even infinity) to be updated according to this post at the Google Product Forums. So do not rely on it. You should be able to check whether GA works as suggested above - or see below.

Tip: Use the Google Analytics Debugger

Google Analytics Debugger is a Chrome plugin that provides you with information about what GA is doing and errors in it.

Alternatives

You might also consider using Segment.io's analytics.js (docs), a NPM component that provides "hassle-free way to integrate analytics into any web application" - it supports GA, KISSmetrics, and many others (via @barlindh). (You might also want to try Segment.io itself - it "lets you send your analytics data to any service you want, without you having to integrate with each one individually.")

Tags: webdev troubleshooting


Copyright © 2024 Jakub Holý
Powered by Cryogen
Theme by KingMob