forked from red-ant/angular-ra-newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-ra-newrelic.js
59 lines (46 loc) · 1.44 KB
/
angular-ra-newrelic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*!
* angular-ra-newrelic.js v0.1.4
* https://github.com/red-ant/angular-ra-newrelic
*/
(function(angular, NewrelicTiming) {
'use strict';
if (typeof angular === 'undefined' || angular === null || typeof angular.module !== 'function') {
return;
}
if (NewrelicTiming === 'undefined') {
throw new Error('NewrelicTiming is not loaded');
}
angular.module('ra.newrelic', ['ra.pageload']).
run(function($rootScope, $location, newrelicTiming) {
var path;
function changeStart() {
path = $location.path();
resetMarks();
newrelicTiming.mark('navStart');
}
function changeSuccess() {
newrelicTiming.mark('domLoaded');
}
function pageLoad() {
if (path === $location.path()) {
newrelicTiming.mark('pageRendered');
newrelicTiming.sendNRBeacon(path);
}
resetMarks();
}
function resetMarks() {
newrelicTiming.marks = {};
}
// ngRoute
$rootScope.$on('$routeChangeStart', changeStart);
$rootScope.$on('$routeChangeSuccess', changeSuccess);
// ui-router
$rootScope.$on('$stateChangeStart', changeStart);
$rootScope.$on('$stateChangeSuccess', changeSuccess);
// custom ra.pageload event
$rootScope.$on('pageload:ready', pageLoad);
}).
factory('newrelicTiming', function() {
return new NewrelicTiming();
});
})(window.angular, window.NewrelicTiming);