blocks
4 years ago
admin.js
2 weeks ago
asset_manager_core_js.js
6 days ago
iframeResizer.contentWindow.min.js
2 years ago
iframeResizer.min.js
2 years ago
marketplace_setup_wizard.js
1 month ago
optout.js
1 year ago
settings.js
1 year ago
optout.js
106 lines
| 1 | (function () { |
| 2 | var cookiename = 'mtm_consent_removed'; |
| 3 | |
| 4 | function listen_event(e, type, callback) { |
| 5 | if (e.addEventListener) { |
| 6 | return e.addEventListener(type, callback, false); |
| 7 | } |
| 8 | |
| 9 | if (e.attachEvent) { |
| 10 | return e.attachEvent('on' + type, callback); |
| 11 | } |
| 12 | |
| 13 | e['on' + type] = callback; |
| 14 | } |
| 15 | function by_id(id) { |
| 16 | return document.getElementById(id); |
| 17 | } |
| 18 | function are_cookies_disabled() { |
| 19 | return navigator && !navigator.cookieEnabled; |
| 20 | } |
| 21 | function set_display(id, status) |
| 22 | { |
| 23 | var e = by_id(id); |
| 24 | if (e) { |
| 25 | e.style.display = status; |
| 26 | } |
| 27 | } |
| 28 | function is_opted_out() { |
| 29 | // piwik_ignore check for BC. |
| 30 | return document.cookie && (document.cookie.indexOf(cookiename + '=1') !== -1 || document.cookie.indexOf('piwik_ignore=') !== -1); |
| 31 | } |
| 32 | function update_status() |
| 33 | { |
| 34 | if (are_cookies_disabled()) { |
| 35 | set_display('matomo_outout_err_cookies', 'block'); |
| 36 | set_display('matomo_optout_checkbox', 'none'); |
| 37 | } else if (is_opted_out()) { |
| 38 | set_display('matomo_opted_out_intro', 'block'); |
| 39 | set_display('matomo_opted_in_intro', 'none'); |
| 40 | set_display('matomo_opted_out_label', 'inline'); |
| 41 | set_display('matomo_opted_in_label', 'none'); |
| 42 | by_id('matomo_optout_checkbox').checked = false; |
| 43 | } else { |
| 44 | set_display('matomo_opted_out_intro', 'none'); |
| 45 | set_display('matomo_opted_in_intro', 'block'); |
| 46 | set_display('matomo_opted_out_label', 'none'); |
| 47 | set_display('matomo_opted_in_label', 'inline'); |
| 48 | by_id('matomo_optout_checkbox').checked = true; |
| 49 | } |
| 50 | } |
| 51 | function on_ready(callback) { |
| 52 | if (document.readyState === 'complete' || document.readyState === 'interactive') { |
| 53 | setTimeout(callback, 1); |
| 54 | } else { |
| 55 | document.addEventListener('DOMContentLoaded', callback); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | function set_cookie(name, val, expires, path, domain) |
| 60 | { |
| 61 | var cookie = name + '=' + val + ';expires=' + expires + ';SameSite=Lax;path=' + (path || '/'); |
| 62 | if (domain) { |
| 63 | cookie += ';domain=' + domain; |
| 64 | } |
| 65 | document.cookie = cookie; |
| 66 | } |
| 67 | |
| 68 | on_ready(function () { |
| 69 | update_status(); |
| 70 | |
| 71 | if (are_cookies_disabled()) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | listen_event(by_id('matomo_optout_checkbox'),'change', function () { |
| 76 | var trackers = []; |
| 77 | if ('object' === typeof window.Piwik && 'function' === typeof Piwik.getAsyncTrackers) { |
| 78 | trackers = Piwik.getAsyncTrackers(); |
| 79 | } |
| 80 | var value = 0; |
| 81 | var expires = 'Thu, 01 Jan 1970 00:00:01 GMT' |
| 82 | if (is_opted_out()) { |
| 83 | // for BC additionally remove any set piwik_ignore cookie |
| 84 | set_cookie('piwik_ignore', 0, expires, '/'); |
| 85 | } else { |
| 86 | value = 1; |
| 87 | var expire = new Date(); |
| 88 | expire.setTime(expire.getTime() + (86400 * 365 * 30 * 1000)); |
| 89 | expires = expire.toGMTString(); |
| 90 | } |
| 91 | |
| 92 | if (trackers.length) { |
| 93 | // respect tracker settings |
| 94 | for (var i = 0; i < trackers.length; i++) { |
| 95 | set_cookie(cookiename, value, expires, trackers[i].getCookiePath(), trackers[i].getCookieDomain()); |
| 96 | } |
| 97 | } else { |
| 98 | // fallback |
| 99 | set_cookie(cookiename, value, expires, '/'); |
| 100 | } |
| 101 | |
| 102 | update_status(); |
| 103 | }); |
| 104 | }) |
| 105 | })(); |
| 106 |