Angulartics
Analytics for AngularJS applications.
Install / Use
/learn @angulartics/AngularticsREADME
angulartics
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-downloads-url] [![Bower version][bower-image]][bower-url] [![Dependencies status][dep-status-image]][dep-status-url] [![MIT license][license-image]][license-url]
Vendor-agnostic analytics for AngularJS applications. angulartics.github.io
Please Read!
This is Angulartics, not Angularytics. There's been some complains about the unfortunate similarity in the names of both projects (this is actually a funny story), so we hear you guys and are making this clarification here. Just make sure Angulartics is the library you actually want to use, and if you work in a team, make sure this is the library they are using!
Install
npm
npm install angulartics
Bower
To install angulartics core module:
bower install angulartics
NuGet
**Note: we are dropping support for NuGet.
Full path tracking (for pages without a router)
Introduced in 0.15.19 - support websites that do not use Angular routes or states on every page and still want to track full paths. The modifications lead to the following behavior:
- Viewing page
http://host.com/routes#/routewill be tracked as/routes#/route. The original version would only track the page as/route - Viewing page
http://host.com/norouteswill be tracked as/noroutes. This is useful for pages that do not contain Angular code besides initializing the base module. - Viewing page
http://host.com/routes2that loads a default route and changes the path tohttp://host.com/routes2#/will be tracked as/routes2#/. This will only fire one pageview, whereas earlier versions would have fired two.
To enable this behavior, add the following to your configuration:
...
var yourApp = angular.module('YourApp', ['angulartics', 'angulartics.google.analytics'])
.config(function ($analyticsProvider) {
$analyticsProvider.firstPageview(true); /* Records pages that don't use $state or $route */
$analyticsProvider.withAutoBase(true); /* Records full path */
});
You can also use $analyticsProvider.withBase(true) instead of $analyticsProvider.withAutoBase(true) if you are using a <base> HTML tag.
Minimal setup
for Google Analytics
See angulartics-google-analytics documentation.
for Google Tag Manager (new interface)
angular.module('myApp', ['angulartics', 'angulartics.google.tagmanager'])
Add the full tracking code from Google Tag Manager to the beginning of your body tag.
Setup listeners in Google Tag Manager
6 Variables
Naming and case must match.
- angulartics page path Type: Data Layer Variable Data Layer Variable Name: content-name
- angulartics event category Type: Data Layer Variable Data Layer Variable Name: target
- angulartics event action Type: Data Layer Variable Data Layer Variable Name: action
- angulartics event label Type: Data Layer Variable Data Layer Variable Name: target-properties
- angulartics event value Macro Type: Data Layer Variable Data Layer Variable Name: value
- angulartics event interaction type Type: Data Layer Variable Data Layer Variable Name: interaction-type
2 Triggers
Name and case must match
- Angulartics events Event: Custom Event Fire on: interaction
- Angulartics pageviews Event: Custom Event Fire on: content-view
2 Tags
- Angulartics Events Product: Google Analytics Type: Universal Analytics Tracking ID: YourGoogleAnalyticsID Track Type: Event Category: {{angulartics event category}} Action: {{angulartics event action}} Label: {{angulartics event label}} Value: {{angulartics event value}} Non-Interaction Hit: {{angulartics event interaction type}} Fire On: Angulartics events
- Angulartics Pageviews Product: Google Analytics Type: Universal Analytics Tracking ID: YourGoogleAnalyticsID Track Type: Page View More settings > Field to Set > name: page, value: {{angulartics page path}} Fire On: Angulartics pageviews
for Google Tag Manager (old interface)
angular.module('myApp', ['angulartics', 'angulartics.google.tagmanager'])
Add the full tracking code from Google Tag Manager to the beginning of your body tag.
Setup listeners in Google Tag Manager
6 Macros
Naming and case must match.
- angulartics page path Type: Data Layer Variable Data Layer Variable Name: content-name
- angulartics event category Type: Data Layer Variable Data Layer Variable Name: target
- angulartics event action Type: Data Layer Variable Data Layer Variable Name: action
- angulartics event label Type: Data Layer Variable Data Layer Variable Name: target-properties
- angulartics event value Macro Type: Data Layer Variable Data Layer Variable Name: value
- angulartics event interaction type Type: Data Layer Variable Data Layer Variable Name: interaction-type
2 Rules
Name and case must match
- Angulartics events Condition: {{event}} equals interaction
- Angulartics pageviews Condition: {{event}} equals content-view
2 Tags
- Angulartics Events Product: Google Analytics Type: Universal Analytics Tracking ID: YourGoogleAnalyticsID Track Type: Event Category: {{angulartics event category}} Action: {{angulartics event action}} Label: {{angulartics event label}} Value: {{angulartics event value}} Non-Interaction Hit: {{angulartics event interaction type}} Firing Rules: Angulartics events
- Angulartics Pageviews Product: Google Analytics Type: Universal Analytics Tracking ID: YourGoogleAnalyticsID Track Type: Page View More settings > Basic Configuration > Document Path: {{angulartics page path}} Firing Rules: Angulartics pageviews
for Piwik
See angulartics-piwik for more details.
for other providers
Browse the website for detailed instructions.
Supported providers
- Adobe Analytics
- Chartbeat
- Clicky
- [Facebook Pixel] (https://github.com/mooyoul/angulartics-facebook-pixel)
- Flurry
- Google Analytics
- Google Tag Manager
- GoSquared
- HubSpot
- IBM Digital Analytics
- Kissmetrics
- Localytics
- Loggly
- Marketo
- Mixpanel
- Piwik
- Scout
- Scroll tracking
- Segment
- Splunk
- Woopra
If there's no Angulartics plugin for your analytics vendor of choice, please feel free to write yours and PR' it! Here's how to do it.
Creating your own vendor plugin
Make sure you follow the Plugin contribution guidelines. You can also use any of the existing plugins as a starter template.
It's very easy to write your own plugin. First, create your module and inject $analyticsProvider:
angular.module('angulartics.myplugin', ['angulartics'])
.config(['$analyticsProvider', function ($analyticsProvider) {
Please follow the style angulartics.{vendorname}.
Next, you register either the page track function, event track function, or both. You do it by calling the registerPageTrack and registerEventTrack methods. Let's take a look at page tracking first:
$analyticsProvider.registerPageTrack(function (path) {
// your implementation here
}
By calling registerPageTrack, you tell Angulartics to invoke your function on $routeChangeSuccess or $stateChangeSuccess. Angulartics will send the new path as an argument.
$analyticsProvider.registerEventTrack(function (action, properties) {
// your implementation here
This is very similar to page tracking. Angulartics will invoke your function every time the event (analytics-on attribute) is fired, passing the action (analytics-event attribute) and an object composed of any analytics-* attributes you put in the element.
If the analytics provider is created async, you can wrap you code with:
angulartics.waitForVendorApi("var", 1000, function(window.var) {
...
});
which will polls every 1000ms for window.var, and fire function(window.var) once window.var is not undefined. Calls made by $analytics will be buffered until function(window.var) fires.
Yo
Related Skills
feishu-drive
343.3k|
things-mac
343.3kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
343.3kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
postkit
PostgreSQL-native identity, configuration, metering, and job queues. SQL functions that work with any language or driver
