PluginProbe
WebberZone Top 10 — Popular Posts / 4.5.2
WebberZone Top 10 — Popular Posts v4.5.2
4.5.2 4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 All 118 releases
top-10 / includes / js / top-10.js

top-10.js in WebberZone Top 10 — Popular Posts 4.5.2, at includes/js/top-10.js

68 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 if ('undefined' === typeof ajax_tptn_tracker) {
3 return;
4 }
5
6 var tracker = ajax_tptn_tracker;
7 var tracked = false;
8
9 function send(id, context) {
10 var params = new URLSearchParams({
11 action: 'tptn_tracker',
12 top_ten_id: id,
13 top_ten_blog_id: tracker.top_ten_blog_id,
14 activate_counter: tracker.activate_counter,
15 top_ten_debug: tracker.top_ten_debug
16 });
17
18 if (context) {
19 params.append('top_ten_sitewide_context', context);
20 }
21
22 var url = tracker.ajax_url;
23 if ('query_based' === tracker.tracker_type) {
24 url += (url.includes('?') ? '&' : '?') + params;
25 }
26
27 // Keep URLSearchParams as the beacon body so WordPress parses the payload as form data.
28 if ('1' === tracker.top_ten_debug || !navigator.sendBeacon || !navigator.sendBeacon(url, params)) {
29 fetch(url, { method: 'POST', body: params, keepalive: true }).catch(function () {});
30 }
31 }
32
33 function track() {
34 if (tracked) {
35 return;
36 }
37 if (document.prerendering) {
38 document.addEventListener('prerenderingchange', track, { once: true });
39 return;
40 }
41 if ('hidden' === document.visibilityState) {
42 document.addEventListener('visibilitychange', track, { once: true });
43 return;
44 }
45
46 tracked = true;
47 if (tracker.top_ten_id > 0) {
48 send(tracker.top_ten_id, '');
49 }
50 if (tracker.top_ten_sitewide_context) {
51 send(0, tracker.top_ten_sitewide_context);
52 }
53 }
54
55 if ('loading' === document.readyState) {
56 document.addEventListener('DOMContentLoaded', track);
57 } else {
58 track();
59 }
60
61 window.addEventListener('pageshow', function (event) {
62 if (event.persisted) {
63 tracked = false;
64 track();
65 }
66 });
67 })();
68