This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 447
/
navtiming.js
76 lines (68 loc) · 2.03 KB
/
navtiming.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Copyright (c), Buddy Brewer.
*/
/**
\file navtiming.js
Plugin to collect metrics from the W3C Navigation Timing API. For more information about Navigation Timing,
see: http://www.w3.org/TR/navigation-timing/
*/
// w is the window object
(function(w) {
// First make sure BOOMR is actually defined. It's possible that your plugin is loaded before boomerang, in which case
// you'll need this.
BOOMR = BOOMR || {};
BOOMR.plugins = BOOMR.plugins || {};
// A private object to encapsulate all your implementation details
var impl = {
complete: false,
done: function() {
var p, pn, pt, data;
p = w.performance || w.msPerformance || w.webkitPerformance || w.mozPerformance;
if(p && p.timing && p.navigation) {
BOOMR.info("This user agent supports NavigationTiming.", "nt");
pn = w.performance.navigation;
pt = w.performance.timing;
data = {
nt_red_cnt: pn.redirectCount,
nt_nav_type: pn.type,
nt_nav_st: pt.navigationStart,
nt_red_st: pt.redirectStart,
nt_red_end: pt.redirectEnd,
nt_fet_st: pt.fetchStart,
nt_dns_st: pt.domainLookupStart,
nt_dns_end: pt.domainLookupEnd,
nt_con_st: pt.connectStart,
nt_con_end: pt.connectEnd,
nt_req_st: pt.requestStart,
nt_res_st: pt.responseStart,
nt_res_end: pt.responseEnd,
nt_domloading: pt.domLoading,
nt_domint: pt.domInteractive,
nt_domcontloaded_st: pt.domContentLoadedEventStart,
nt_domcontloaded_end: pt.domContentLoadedEventEnd,
nt_domcomp: pt.domComplete,
nt_load_st: pt.loadEventStart,
nt_load_end: pt.loadEventEnd,
nt_unload_st: pt.unloadEventStart,
nt_unload_end: pt.unloadEventEnd
};
if (pt.secureConnectionStart) {
// secureConnectionStart is OPTIONAL in the spec
data.nt_ssl_st = pt.secureConnectionStart;
}
BOOMR.addVar(data);
}
this.complete = true;
BOOMR.sendBeacon();
}
};
BOOMR.plugins.NavigationTiming = {
init: function() {
BOOMR.subscribe("page_ready", impl.done, null, impl);
return this;
},
is_complete: function() {
return impl.complete;
}
};
}(window));