|
1 | | -/* Simple Analytics - Privacy friendly analytics (docs.simpleanalytics.com/script; 2021-04-13; bb7c) */ |
| 1 | +/* Simple Analytics - Privacy friendly analytics (docs.simpleanalytics.com/script; 2021-04-20; 9833) */ |
2 | 2 | /* eslint-env browser */ |
3 | 3 |
|
4 | 4 | (function (window, overwriteOptions, baseUrl, apiUrlPrefix, version, saGlobal) { |
|
19 | 19 | var https = "https:"; |
20 | 20 | var pageviewsText = "pageview"; |
21 | 21 | var errorText = "error"; |
| 22 | + var slash = "/"; |
22 | 23 | var protocol = https + "//"; |
23 | 24 | var con = window.console; |
24 | 25 | var doNotTrack = "doNotTrack"; |
25 | | - var slash = "/"; |
26 | 26 | var nav = window.navigator; |
27 | 27 | var loc = window.location; |
28 | 28 | var locationHostname = loc.hostname; |
|
118 | 118 | return typeof func == "function"; |
119 | 119 | }; |
120 | 120 |
|
| 121 | + var isString = function (string) { |
| 122 | + return typeof string == "string"; |
| 123 | + }; |
| 124 | + |
121 | 125 | var assign = function () { |
122 | 126 | var to = {}; |
123 | 127 | var arg = arguments; |
|
159 | 163 |
|
160 | 164 | // Prepend a slash when it's missing |
161 | 165 | var ignorePage = |
162 | | - ignorePageRaw[0] == "/" ? ignorePageRaw : "/" + ignorePageRaw; |
| 166 | + ignorePageRaw[0] == slash ? ignorePageRaw : slash + ignorePageRaw; |
163 | 167 |
|
164 | 168 | try { |
165 | 169 | if ( |
|
181 | 185 | // Send data via image |
182 | 186 | var sendData = function (data, callback) { |
183 | 187 | data = assign(payload, data); |
| 188 | + |
184 | 189 | var image = new Image(); |
185 | 190 | if (callback) { |
186 | 191 | image.onerror = callback; |
|
200 | 205 | encodeURIComponentFunc(data[key]) |
201 | 206 | ); |
202 | 207 | }) |
203 | | - .join("&"); |
| 208 | + .join("&") + |
| 209 | + "&time=" + |
| 210 | + Date.now(); |
204 | 211 | }; |
205 | 212 |
|
206 | 213 | ///////////////////// |
|
292 | 299 | // Make sure ignore pages is an array |
293 | 300 | var ignorePages = Array.isArray(ignorePagesRaw) |
294 | 301 | ? ignorePagesRaw |
295 | | - : typeof ignorePagesRaw == "string" && ignorePagesRaw.length |
| 302 | + : isString(ignorePagesRaw) && ignorePagesRaw.length |
296 | 303 | ? ignorePagesRaw.split(/, ?/) |
297 | 304 | : []; |
298 | 305 |
|
|
531 | 538 |
|
532 | 539 | // Check if referrer is the same as current real hostname (not the defined hostname!) |
533 | 540 | var sameSite = referrer |
534 | | - ? doc.referrer.split("/")[2] == locationHostname |
| 541 | + ? doc.referrer.split(slash)[2] == locationHostname |
535 | 542 | : false; |
536 | 543 |
|
537 | 544 | // We set unique variable based on pushstate or back navigation, if no match we check the referrer |
|
663 | 670 |
|
664 | 671 | event = ("" + event).replace(/[^a-z0-9]+/gi, "_").replace(/(^_|_$)/g, ""); |
665 | 672 |
|
666 | | - if (event) |
| 673 | + if (event) { |
667 | 674 | sendData( |
668 | 675 | assign(source, bot ? { bot: true } : {}, { |
669 | 676 | type: "event", |
|
673 | 680 | }), |
674 | 681 | callback |
675 | 682 | ); |
| 683 | + } |
676 | 684 | }; |
677 | 685 |
|
678 | 686 | var defaultEventFunc = function (event, callback) { |
|
691 | 699 | window[functionName] = defaultEventFunc; |
692 | 700 |
|
693 | 701 | // Post events from the queue of the user defined function |
694 | | - for (var event in queue) sendEvent(queue[event]); |
| 702 | + for (var event in queue) { |
| 703 | + Array.isArray(queue[event]) |
| 704 | + ? sendEvent.apply(null, queue[event]) |
| 705 | + : sendEvent(queue[event]); |
| 706 | + } |
695 | 707 | } catch (e) { |
696 | 708 | sendError(e); |
697 | 709 | } |
|
0 commit comments