|
6 | 6 | [](https://david-dm.org/aleross/angular-segment-analytics/dev-status.png) |
7 | 7 | [](https://github.com/aleross/angular-segment-analytics/blob/master/LICENSE) |
8 | 8 |
|
9 | | -A highly configurable module for adding Segment analytics to any Angular app. |
| 9 | +A highly configurable module for easily adding Segment analytics to any Angular app. |
10 | 10 |
|
11 | 11 | ## Table of Contents |
12 | 12 | - [Get Started](#get-started) |
13 | 13 | - [Usage](#usage) |
14 | 14 | - [Configuration](#configuration) |
15 | 15 | - [Provider](#provider) |
16 | 16 | - [Constant](#constant) |
17 | | - - [Service](#service) |
18 | 17 | - [API Documentation](#api-documentation) |
19 | 18 | - [Examples](#examples) |
20 | 19 |
|
@@ -42,17 +41,17 @@ segmentProvider.setKey('abc'); |
42 | 41 | Most Segment methods (see [Analytics.js](https://segment.com/docs/libraries/analytics.js/)) are available on the `segment` service created by ngSegment. |
43 | 42 |
|
44 | 43 | ```js |
45 | | -segment.track('action', { prop: 'value' }); |
| 44 | +segment.track('event', { prop: 'value' }); |
46 | 45 | ``` |
47 | 46 |
|
48 | 47 | Continue reading about the configuration options, or jump to the [Examples](#examples). |
49 | 48 |
|
50 | 49 |
|
51 | 50 | ## Configuration |
52 | 51 |
|
53 | | -ngSegment can be configured in any of 3 ways: using a provider, constant or service. These 3 options are available so you can pick the mechanism that fits your application best. The provider or constant are recommended because typically it's best to configure 3rd party libraries in the config phase of your application. |
| 52 | +ngSegment provides two configuration mechanisms: using a provider or constant. These options are available so you can pick the mechanism that fits your application best. |
54 | 53 |
|
55 | | -It is not recommended to mix configuration mechanisms, but if you do they're applied in the order listed in this documentation (provider, constant then service) and conflicting settings will be overridden. |
| 54 | +It is not recommended to mix configuration mechanisms, but if you do configuration via constant will take precedence. |
56 | 55 |
|
57 | 56 | ### Provider |
58 | 57 |
|
@@ -93,26 +92,9 @@ angular.module('myApp').constant('segmentConfig', { |
93 | 92 |
|
94 | 93 | Read more about [AngularJS constants](https://docs.angularjs.org/api/auto/service/$provide#constant). |
95 | 94 |
|
96 | | -### Service |
97 | | - |
98 | | -If your API key or other configuration parameters are only available in the run phase of your application then you can load Analytics.js using `segmentLoader.load(apiKey)`, and configure using the `segment` service: |
99 | | -```js |
100 | | -angular.module('myApp').controller(function (segment, segmentLoader) { |
101 | | - segment.setCondition(function ($rootScope) { |
102 | | - return $rootScope.isProduction; |
103 | | - }); |
104 | | - |
105 | | - // If you don't set the API key using the provider or constant |
106 | | - // then you need to manually load Analytics.js |
107 | | - segmentLoader.load('abc'); |
108 | | -}); |
109 | | -``` |
110 | | - |
111 | | -Typically you should configure 3rd party libraries before the `run()` phase of your AngularJS application, so it's recommended that you use the **provider** or **constant** mechanism for configuring `ngSegment` instead of the service. |
112 | | - |
113 | 95 | ## API Documentation |
114 | 96 |
|
115 | | -The configuration API is available on the `segmentProvider` and `segment` service. For configuring via a constant, see [`defaultSegmentConfig`](https://github.com/aleross/angular-segment-analytics/blob/master/src/config.js) for the property names to override. |
| 97 | +The configuration API is available on the `segmentProvider`. For configuring via a constant, see [`defaultSegmentConfig`](https://github.com/aleross/angular-segment-analytics/blob/master/src/config.js) for the property names to override. |
116 | 98 |
|
117 | 99 | All configuration methods are chainable: |
118 | 100 | ```js |
@@ -150,7 +132,7 @@ segmentProvider.setCondition(function ($rootScope, method, arguments) { |
150 | 132 | ### setAutoload(boolean) |
151 | 133 | **Default:** `true` |
152 | 134 |
|
153 | | -ngSegment autoloads Segment's Analytics.js before the AngularJS `.run()` phase if an API key has been set. Set autoload to false if you're including analytics.js in your build script. |
| 135 | +ngSegment autoloads Segment's Analytics.js before the AngularJS `.run()` phase if an API key has been set. Set autoload to false if you already include analytics.js in your build script. |
154 | 136 |
|
155 | 137 | If you need to load the Segment analytics.js script on-demand, you can use the `segmentLoader` or `segmentLoaderProvider`: |
156 | 138 |
|
|
0 commit comments