@@ -28,10 +28,12 @@ var endsWith = function (str, suffix) {
28
28
29
29
// Check if the origin looks like a production, non-development host (i.e., public and served over HTTPS).
30
30
// Relevant reading: https://w3c.github.io/webappsec-secure-contexts/#localhost
31
- var isSecureOrigin = function ( win ) {
32
- return ! (
33
- win . isSecureContext === false ||
34
- win . location . protocol === 'http:' ||
31
+ var isInsecureOrigin = function ( win ) {
32
+ // Allow HTTPS and HTTP.
33
+ if ( win . isSecureContext === true || win . location . protocol === 'http:' ) {
34
+ return false ;
35
+ }
36
+ return (
35
37
win . location . hostname === 'localhost' ||
36
38
endsWith ( win . location . hostname , '.localhost' ) ||
37
39
win . location . hostname === '127.0.1' ||
@@ -42,17 +44,6 @@ var isSecureOrigin = function (win) {
42
44
) ;
43
45
} ;
44
46
45
- // IE9/IE10 uses a prefixed version while MS Edge sets the property in
46
- // `window` instead of `navigator`:
47
- // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/doNotTrack#Browser_compatibility
48
- var doNotTrack = onlyOnce ( function ( ) {
49
- // We also will not engage Telemetry if the origin appears to be in a development (i.e., non-production) environment.
50
- return navigator . doNotTrack === '1' ||
51
- navigator . msDoNotTrack === '1' ||
52
- window . doNotTrack === '1' ||
53
- ! isSecureOrigin ( window ) ;
54
- } ) ;
55
-
56
47
var CURRENT_VERSION = '1.1.0' ;
57
48
var MOZILLA_RESEARCH_TRACKER = 'UA-77033033-6' ;
58
49
@@ -96,7 +87,7 @@ telemetry.start = onlyOnce(function (config) {
96
87
setupAnalytics ( ) ;
97
88
98
89
function setupAnalytics ( ) {
99
- if ( doNotTrack ( ) ) { return ; }
90
+ if ( isTelemetryDisabled ( ) ) { return ; }
100
91
101
92
window . dataLayer = window . dataLayer || [ ] ;
102
93
window . gtag = window . gtag || function ( ) { dataLayer . push ( arguments ) ; } ;
@@ -111,7 +102,7 @@ function setupAnalytics() {
111
102
}
112
103
113
104
function setupErrorLogging ( ) {
114
- if ( doNotTrack ( ) ) { return ; }
105
+ if ( isTelemetryDisabled ( ) ) { return ; }
115
106
116
107
injectScript ( 'https://cdn.ravenjs.com/3.22.3/console/raven.min.js' , function ( err ) {
117
108
if ( err ) {
@@ -145,13 +136,13 @@ function startAnalytics() {
145
136
function setupPerformanceAPI ( tracker ) {
146
137
telemetry . performance = {
147
138
mark : function ( name ) {
148
- if ( doNotTrack ( ) ) { return ; }
139
+ if ( isTelemetryDisabled ( ) ) { return ; }
149
140
150
141
performance . mark ( name ) ;
151
142
} ,
152
143
153
144
measure : function ( name , start , end ) {
154
- if ( doNotTrack ( ) ) { return ; }
145
+ if ( isTelemetryDisabled ( ) ) { return ; }
155
146
156
147
performance . measure ( name , start , end ) ;
157
148
var performanceEntry = performance . getEntriesByName ( name ) [ 0 ] ;
@@ -180,15 +171,15 @@ function setupPerformanceAPI(tracker) {
180
171
* commands [2].
181
172
*/
182
173
function configureBoundTracker ( trackingId , options ) {
183
- if ( doNotTrack ( ) ) { return NO_OP ; }
174
+ if ( isTelemetryDisabled ( ) ) { return NO_OP ; }
184
175
185
176
options = options || { } ;
186
177
var groups = options . groups ;
187
178
telemetry . _gtag ( 'config' , trackingId , options ) ;
188
179
return trackingFunction ;
189
180
190
181
function trackingFunction ( command , label , options ) {
191
- if ( doNotTrack ( ) ) { return ; }
182
+ if ( isTelemetryDisabled ( ) ) { return ; }
192
183
193
184
options = options || { } ;
194
185
if ( groups ) {
@@ -226,4 +217,18 @@ function onlyOnce(fn) {
226
217
} ;
227
218
}
228
219
220
+ // IE9/IE10 uses a prefixed version while MS Edge sets the property in
221
+ // `window` instead of `navigator`:
222
+ // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/doNotTrack#Browser_compatibility
223
+ function doNotTrack ( ) {
224
+ return navigator . doNotTrack === '1' ||
225
+ navigator . msDoNotTrack === '1' ||
226
+ window . doNotTrack === '1' ;
227
+ }
228
+
229
+ function isTelemetryDisabled ( ) {
230
+ // Telemetry is disabled if DNT is enabled or if the origin appears to be for a development environment.
231
+ return doNotTrack ( ) || isInsecureOrigin ( window ) ;
232
+ }
233
+
229
234
} ) ( window ) ;
0 commit comments