AAngulartics | Web analytics for AngularJS applications

Vendor-agnostic & extensible

Avoid dealing with vendor-specific code. If your provider of choice is not among the existing plugins, just write your own.

Ready to use

Google Analytics, Kissmetrics, Mixpanel, Flurry, Piwik, Segment.io and more are supported out of the box.

Google Analytics Kissmetrics Mixpanel Chartbeat Flurry Segment.io

1-line setup

Just add Angulartics to your app dependencies and you'll get automatic pageview tracking for your application routes.


Download Angulartics and the Angulartics plugin for your vendor. Note: All plugins list Angulartics as a dependency, so they will be downloaded together.

$ bower install angulartics-google-analytics --save

Load the relevant files in your applications html (or include them in your build script).

<script src="/bower_components/angulartics/dist/angulartics.min.js"></script>
<script src="/bower_components/angulartics-google-analytics/dist/angulartics-ga.min.js"></script>

In your application dependencies, inject Angulartics and the Angulartics plugin for your vendor.

angular.module('myApp', ['angulartics', 'angulartics.google.analytics'])

Make sure you delete any automatic tracking line from your vendor snippet code!

// Google Analytics example
ga('send', 'pageview'); // <---- delete this line!

Virtual pageviews

Angulartics does automatic virtual pageview tracking by default, meaning the entire user navigation across the different routes of your application is tracked. You can turn it off with virtualPageviews(false).

module.config(function ($analyticsProvider) {
  // turn off automatic tracking

Declarative event tracking

The simplest way to do event tracking is by adding the attributes analytics-on and analytics-event to the element. Think of it as: on 'click', track event 'name'.

<a href="file.pdf" analytics-on="click" analytics-event="Download">Download</a>
Depending on your analytics provider, the analytics-event attribute is automatically mapped to its respective vendor field. For example, with Google Analytics, the event is used for the 'action' parameter.

Inferred values

analytics-on always needs to be present, because it is the attribute that enables event tracking for the element. All other attributes will be inferred if omitted.

<!-- infers analytics-event from the element inner text -->
<a href="file.pdf" analytics-on="click">Download</a>

<!-- infers the analytics-on value from the element type; for anchor is 'click' -->
<a href="file.pdf" analytics-on>Download</a>

<!-- same as adding analytics-event="Step 3" -->
<input type="submit" value="Step 3" analytics-on>

Additional parameters

Each vendor has its own set of tracking properties. For example, Google Analytics have category and label. You can set these properties with analytics- attributes.

<button analytics-on analytics-event="Play" analytics-category="Videos" analytics-label="Gone with the Wind">Play</button>

Scroll tracking

In the same way you can track an action by catching any valid DOM event (click, hover, etc), you can also track any element that appears into the viewport while scrolling the page. To achieve this, Angulartics uses jQuery Waypoints and provides you with a scrollby event that you can use for analytics-on.

First, you need to include the plugin script named angulartics-scroll.js, and inject angulartics.scroll into your module.

angular.module('myApp', [..., 'angulartics.scroll'])
<section id="features" analytics-on="scrollby">

Remember what we learned about inferred values: in the example above we didn't specify an event name so in this case the id attribute ("features") will be used.

jQuery Waypoints have a set of options to customize its behavior; you can specify any of them by adding scrollby-* attributes. For more information you can take a look at this sample.

Using the API

In order to track pageviews and events from within your application logic, inject $analytics and invoke either the pageTrack() or eventTrack() methods.

module.controller('SampleCtrl', function ($analytics) {
  $analytics.eventTrack('eventName', {  category: 'category', label: 'label' });
Vendor Page Tracking support Event Tracking support Script Module
Adobe Analytics (Omniture) Yes Yes angulartics-adobe angulartics.adobe.analytics
Baidu Yes Yes angulartics-baidu angulartics.baidu
Chartbeat Yes No angulartics-chartbeat angulartics.chartbeat Sample
Clicky Yes Yes angulartics-clicky angulartics.clicky
CNZZ Yes Yes angulartics-cnzz angulartics.cnzz
Flurry No Yes angulartics-flurry angulartics.flurry
Google Analytics Yes Yes angulartics-ga angulartics.google.analytics Sample
Google Analytics (Cordova) Yes Yes angulartics-ga-cordova angulartics.google.analytics.cordova
Google Tag Manager Yes Yes angulartics-gtm angulartics.google.tagmanager
GoSquared Yes Yes angulartics-gosquared angulartics.gosquared
Hubspot Yes Yes angulartics-hubspot angulartics.hubspot
Inspectlet Yes Yes angulartics-inspectlet angulartics.inspectlet
Intercom No Yes angulartics-intercom angulartics.intercom
Kissmetrics Yes (via event tracking) Yes angulartics-kissmetrics angulartics.kissmetrics Sample
Localytics Yes Yes angulartics-localytics angulartics.localytics
Loggly Yes Yes angulartics-loggly angulartics.loggly
Marketo Yes Yes angulartics-marketo angulartics.marketo
Mixpanel Yes (via event tracking) Yes angulartics-mixpanel angulartics.mixpanel Sample
New Relic Insights No Yes angulartics-newrelic-insights angulartics.newrelic.insights
Piwik Yes Yes angulartics-piwik angulartics.piwik
Segment.io Yes Yes angulartics-segmentio.js angulartics.segment.io Sample
Splunk Yes Yes angulartics-splunk angulartics.splunk
Woopra Yes Yes angulartics-woopra angulartics.woopra

What about you?

You have an analytics vendor of choice and there's no Angulartics plugin for it? Please feel free to write your implementation and PR'it on GitHub. It'll be most welcomed!