An AngularJS module for Segment, the Analytics API and customer data hub.
This module automatically includes Segment's Analytics.js library, you do not need to include it yourself.
At the moment, the name angular-segment
has been taken up by another project.
So you need to include this project via Git:
bower install --save https://github.com/glints-dev/angular-segment#master
Inject SegmentProvider
into your .config()
block, then configure as
follows:
SegmentProvider.setWriteKey('<your write key>');
Then in everywhere else, you just need to inject Segment
.
angular.module('myApp')
.controller('AwesomeController', function (Segment) {
Segment.track('Signed Up', {
plan: 'Startup',
source: 'Analytics Academy'
});
});
If you use ui-router and would like to track virtual page views, you can simply do:
$rootScope.on('$stateChangeSuccess', function () {
Segment.page();
});
There is currently one directive to simply tracking.
<button type="submit"
data-segment-track="Signed Up"
data-segment-track-options="{
plan: 'Startup',
source: 'Analytics Academy'
}">
</button>