Skip to content

Commit ffc56fd

Browse files
author
Alex Ross
committed
Fix broken analytics.js reference after script has loaded
1 parent 8ee6f6e commit ffc56fd

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ The `segment` service and `segmentProvider` implement most methods from [Analyti
224224

225225
### Page tracking
226226
```js
227-
$rootScope.$on('$routeChangeSuccess', function () {
228-
segment.pageview($location.path());
229-
});
227+
$rootScope.$on('$routeChangeSuccess', segment.pageview);
230228
```
231229

232230
### Event tracking

example.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
// Provider configuration
1616
angular.module('example', ['ngSegment']).config(function (segmentProvider, ExampleEvents) {
17-
segmentProvider.setDebug(true).setAutoload(false).setEvents(ExampleEvents);
17+
segmentProvider.setDebug(true).setEvents(ExampleEvents);
1818
segmentProvider.track('test');
1919
});
2020

2121
// Events constant example. This is optional.
2222
angular.module('example').constant('ExampleEvents', {
23-
TEST_EVENT: 'test'
23+
TEST_EVENT: 'Test Event'
2424
});
2525

2626
angular.module('example').constant('segmentConfig', {
@@ -29,9 +29,12 @@
2929
});
3030

3131
// Service configuration and usage
32-
angular.module('example').controller('ExampleController', function (segment, segmentLoader) {
32+
angular.module('example').controller('ExampleController', function ($scope, segment, segmentLoader) {
3333
segment.track('controller test');
34-
segment.track('2');
34+
35+
$scope.test = function () {
36+
segment.track(segment.events.TEST_EVENT, { foo: 'bar' });
37+
};
3538

3639
// segmentLoader.load(segment.config.apiKey);
3740
});
@@ -47,7 +50,7 @@ <h1>Example</h1>
4750
</div>
4851
</div>
4952
<div class="container">
50-
53+
<button class="btn btn-primary" ng-click="test()">Test</button>
5154
</div>
5255
</body>
5356
</html>

segment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ angular.module('ngSegment').constant('segmentDefaultConfig', {
157157

158158
// No condition set, call the Segment method
159159
this.debug('Calling method ' + method + ' with arguments:', arguments);
160-
return analytics[method].apply(analytics, arguments);
160+
return window.analytics[method].apply(analytics, arguments);
161161
}).bind(this);
162162
};
163163
}

segment.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/provider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
// No condition set, call the Segment method
4949
this.debug('Calling method ' + method + ' with arguments:', arguments);
50-
return analytics[method].apply(analytics, arguments);
50+
return window.analytics[method].apply(analytics, arguments);
5151
}).bind(this);
5252
};
5353
}

0 commit comments

Comments
 (0)