264 }
265
266 if (!goatcounter.no_events)
267 goatcounter.bind_events()268 })
269})();
263 document.addEventListener('visibilitychange', f)
264 }
265
266 if (!goatcounter.no_events)267 goatcounter.bind_events()
268 })
269})();
258 if (document.visibilityState !== 'visible')
259 return
260 document.removeEventListener('visibilitychange', f)
261 goatcounter.count()262 }
263 document.addEventListener('visibilitychange', f)
264 }
252 // 2. Page is not yet visible; wait until it switches to 'visible' and count.
253 // See #487
254 if (!('visibilityState' in document) || document.visibilityState === 'visible')
255 goatcounter.count()256 else {
257 var f = function(e) {
258 if (document.visibilityState !== 'visible')
246 }
247 }
248
249 if (!goatcounter.no_onload)250 on_load(function() {
251 // 1. Page is visible, count request.
252 // 2. Page is not yet visible; wait until it switches to 'visible' and count.
180
181 var send = function(elem) {
182 return function() {
183 goatcounter.count({184 event: true,
185 path: (elem.dataset.goatcounterClick || elem.name || elem.id || ''),
186 title: (elem.dataset.goatcounterTitle || elem.title || (elem.innerHTML || '').substr(0, 200) || ''),
146 if (f)
147 return warn('not counting because of: ' + f)
148
149 var url = goatcounter.url(vars)150 if (!url)
151 return warn('not counting because path callback returned null')
152
142
143 // Count a hit.
144 window.goatcounter.count = function(vars) {
145 var f = goatcounter.filter()146 if (f)
147 return warn('not counting because of: ' + f)
148
119 return 'frame'
120 if (!goatcounter.allow_local && location.hostname.match(/(localhost$|^127\.|^10\.|^172\.(1[6-9]|2[0-9]|3[0-1])\.|^192\.168\.|^0\.0\.0\.0$)/))
121 return 'localhost'
122 if (!goatcounter.allow_local && location.protocol === 'file:')123 return 'localfile'
124 if (localStorage && localStorage.getItem('skipgc') === 't')
125 return 'disabled with #toggle-goatcounter'
117 return 'visibilityState'
118 if (!goatcounter.allow_frame && location !== parent.location)
119 return 'frame'
120 if (!goatcounter.allow_local && location.hostname.match(/(localhost$|^127\.|^10\.|^172\.(1[6-9]|2[0-9]|3[0-1])\.|^192\.168\.|^0\.0\.0\.0$)/))121 return 'localhost'
122 if (!goatcounter.allow_local && location.protocol === 'file:')
123 return 'localfile'
115 goatcounter.filter = function() {
116 if ('visibilityState' in document && document.visibilityState === 'prerender')
117 return 'visibilityState'
118 if (!goatcounter.allow_frame && location !== parent.location)119 return 'frame'
120 if (!goatcounter.allow_local && location.hostname.match(/(localhost$|^127\.|^10\.|^172\.(1[6-9]|2[0-9]|3[0-1])\.|^192\.168\.|^0\.0\.0\.0$)/))
121 return 'localhost'
112 }
113
114 // Filter some requests that we (probably) don't want to count.
115 goatcounter.filter = function() {116 if ('visibilityState' in document && document.visibilityState === 'prerender')
117 return 'visibilityState'
118 if (!goatcounter.allow_frame && location !== parent.location)
87 var s = document.querySelector('script[data-goatcounter]')
88 if (s && s.dataset.goatcounter)
89 return s.dataset.goatcounter
90 return (goatcounter.endpoint || window.counter) // counter is for compat; don't use. 91 }
92
93 // Get current path.
27 p: (vars.path === undefined ? goatcounter.path : vars.path),
28 r: (vars.referrer === undefined ? goatcounter.referrer : vars.referrer),
29 t: (vars.title === undefined ? goatcounter.title : vars.title),
30 e: !!(vars.event || goatcounter.event), 31 s: [window.screen.width, window.screen.height, (window.devicePixelRatio || 1)],
32 b: is_bot(),
33 q: location.search,
26 var data = {
27 p: (vars.path === undefined ? goatcounter.path : vars.path),
28 r: (vars.referrer === undefined ? goatcounter.referrer : vars.referrer),
29 t: (vars.title === undefined ? goatcounter.title : vars.title), 30 e: !!(vars.event || goatcounter.event),
31 s: [window.screen.width, window.screen.height, (window.devicePixelRatio || 1)],
32 b: is_bot(),
25 var get_data = function(vars) {
26 var data = {
27 p: (vars.path === undefined ? goatcounter.path : vars.path),
28 r: (vars.referrer === undefined ? goatcounter.referrer : vars.referrer), 29 t: (vars.title === undefined ? goatcounter.title : vars.title),
30 e: !!(vars.event || goatcounter.event),
31 s: [window.screen.width, window.screen.height, (window.devicePixelRatio || 1)],
24 // Get all data we're going to send off to the counter endpoint.
25 var get_data = function(vars) {
26 var data = {
27 p: (vars.path === undefined ? goatcounter.path : vars.path), 28 r: (vars.referrer === undefined ? goatcounter.referrer : vars.referrer),
29 t: (vars.title === undefined ? goatcounter.title : vars.title),
30 e: !!(vars.event || goatcounter.event),
Variables that aren't defined, but accessed may throw reference errors at runtime.
NOTE: In browser applications, DeepSource recommends the use of ESModules over regular
text/javascript
scripts. Using variables that are injected by scripts included in an HTML file is currently not supported.
Potential ReferenceError
s may result from misspellings of variable and parameter names, or accidental implicit globals (for example, forgetting the var
keyword in a for
loop initializer).
Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a /*global ...*/
comment, or specified in the globals key in the ESLint configuration file.
A common use case for these is if you intentionally use globals that are defined elsewhere (e.g. in a script sourced from HTML).
Bad Practice
const foo = someFunction(); // `someFunction` is not defined
const bar = baz + 1; // 'baz' is undeclared
Recommended
import { someFunction } from 'some-file';
const baz = Math.random();
const foo = someFunction();
const bar = baz + 1;