Tracking Events and Pageviews with Segment.io (http://segment.io)
Follow these steps:
- Add the service to your angular js app module:
var app = angular.module('myapp', ['segmentio']) {
...
});
- In your application config block, use the
load
method to get your analytics script from segmentio.
app.config(function($stateProvider) {
$stateProvider.state('app', {
resolve: {
// Note that this should be in a resolve block as it return a promise
analytics: segmentio.load('MY_API_KEY')
}
});
});
- Now just have analytics to be injected in your controller.
someAppSubmodule.controller(function ($rootScope, $scope, $http, analytics) {
...
});
- Call any method documented here: https://segment.io/libraries/analytics.js
Via Bower (http://bower.io/)
Run bower install ng-segmentio
in a terminal
-
Install dependencies via npm:
npm install
(in the project folder) -
Run grunt:
grunt
-
The build result is in the build directory
Run tests with grunt test
. The test files are in the test/unit
directory.
- Added Standard for JS style linting.
- Switched to annotated angular dependencies.
- Fixed a dep issue with the minified version.