Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 1.27 KB

README.md

File metadata and controls

60 lines (44 loc) · 1.27 KB

angular-segment

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.

Installing

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

Example

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();
});

Directives

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>