1(function () { 2 'use strict'; 3 4 var config = window.TomUtmConversionConfig || {}; 5 var endpoint = String(config.endpoint || ''); 6 var token = String(config.token || ''); 7 var enabled = Array.isArray(config.enabled) ? config.enabled : []; 8 9 function resolved(value) { 10 return window.Promise ? window.Promise.resolve(value) : value; 11 } 12 13 function uuid() { 14 if (window.crypto && typeof window.crypto.randomUUID === 'function') { 15 return window.crypto.randomUUID(); 16 } 17 18 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (character) { 19 var random = Math.random() * 16 | 0; 20 var value = character === 'x' ? random : (random & 0x3 | 0x8); 21 return value.toString(16); 22 }); 23 } 24 25 function normalizeDetails(details) { 26 details = details && typeof details === 'object' ? details : {}; 27 return { 28 form_id: String(details.form_id || '').substring(0, 100), 29 form_name: String(details.form_name || '').substring(0, 100), 30 form_action: String(details.form_action || '').substring(0, 450), 31 form_method: String(details.form_method || '').substring(0, 20) 32 }; 33 } 34 35 function encodePayload(payload) { 36 var parts = []; 37 var key; 38 39 for (key in payload) { 40 if (Object.prototype.hasOwnProperty.call(payload, key)) { 41 parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(String(payload[key] == null ? '' : payload[key]))); 42 } 43 } 44 45 return parts.join('&'); 46 } 47 48 function sendWithXhr(body) { 49 if (!window.XMLHttpRequest) { 50 return resolved(false); 51 } 52 53 if (!window.Promise) { 54 try { 55 var request = new XMLHttpRequest(); 56 request.open('POST', endpoint, true); 57 request.withCredentials = true; 58 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8'); 59 request.send(body); 60 return true; 61 } catch (error) { 62 return false; 63 } 64 } 65 66 return new Promise(function (resolve) { 67 var request = new XMLHttpRequest(); 68 request.open('POST', endpoint, true); 69 request.withCredentials = true; 70 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8'); 71 request.onreadystatechange = function () { 72 if (request.readyState === 4) { 73 resolve(request.status >= 200 && request.status < 300); 74 } 75 }; 76 request.onerror = function () { 77 resolve(false); 78 }; 79 request.send(body); 80 }); 81 } 82 83 function send(target, details) { 84 var payload; 85 var body; 86 87 if (!endpoint || !token) { 88 return resolved(false); 89 } 90 91 details = normalizeDetails(details); 92 payload = { 93 token: token, 94 event_id: uuid(), 95 target: String(target || 'HTML-Formular').substring(0, 190), 96 page_url: window.location.href.substring(0, 450), 97 form_id: details.form_id, 98 form_name: details.form_name, 99 form_action: details.form_action, 100 form_method: details.form_method 101 }; 102 body = encodePayload(payload); 103 104 if (navigator.sendBeacon) { 105 try { 106 var blob = new Blob([body], { type: 'application/x-www-form-urlencoded;charset=UTF-8' }); 107 if (navigator.sendBeacon(endpoint, blob)) { 108 return resolved(true); 109 } 110 } catch (error) { 111 // Continue with fetch or XMLHttpRequest. 112 } 113 } 114 115 if (window.fetch) { 116 return fetch(endpoint, { 117 method: 'POST', 118 credentials: 'same-origin', 119 keepalive: true, 120 headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }, 121 body: body 122 }).then(function (response) { 123 return response.ok; 124 }).catch(function () { 125 return false;
126 }); 127 } 128 129 return sendWithXhr(body); 130 } 131 132 function formDetails(form) { 133 return { 134 form_id: form.id || '', 135 form_name: form.getAttribute('name') || '', 136 form_action: form.action || '', 137 form_method: form.method || 'get' 138 }; 139 } 140 141 function normalizeName(value) { 142 return String(value || '').toLowerCase().replace(/[\s_-]+/g, ''); 143 } 144 145 function containsTrackingField(form) { 146 var fields; 147 var fieldIndex; 148 var nameIndex; 149 var field; 150 var directName; 151 var dataName; 152 153 if (!enabled.length) { 154 return false; 155 } 156 157 fields = form.querySelectorAll('[name], [data-tom-utm], [data-name]'); 158 159 for (fieldIndex = 0; fieldIndex < fields.length; fieldIndex++) { 160 field = fields[fieldIndex]; 161 directName = field.getAttribute('data-tom-utm') || field.getAttribute('name') || ''; 162 dataName = normalizeName(field.getAttribute('data-name')); 163 164 for (nameIndex = 0; nameIndex < enabled.length; nameIndex++) { 165 if (directName === enabled[nameIndex] || (dataName && dataName === normalizeName(enabled[nameIndex]))) { 166 return true; 167 } 168 } 169 } 170 171 return false; 172 } 173 174 document.addEventListener('submit', function (event) { 175 var form = event.target; 176 var target; 177 178 if (!form || form.nodeName !== 'FORM') { 179 return; 180 } 181 182 if (form.classList.contains('wpcf7-form')) { 183 return; 184 } 185 186 if (form.getAttribute('data-tom-utm-conversion-mode') === 'manual') { 187 return; 188 } 189 190 if (!form.hasAttribute('data-tom-utm-conversion') && !containsTrackingField(form)) { 191 return; 192 } 193 194 if (form.getAttribute('data-tom-utm-conversion-logged') === '1') { 195 return; 196 } 197 198 form.setAttribute('data-tom-utm-conversion-logged', '1'); 199 target = form.getAttribute('data-tom-utm-conversion') || form.id || form.getAttribute('name') || 'HTML-Formular'; 200 send(target, formDetails(form)); 201 }, true); 202 203 window.TomUtmConversions = window.TomUtmConversions || {}; 204 window.TomUtmConversions.log = function (target, details) { 205 return send(target, details || {}); 206 }; 207}());
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.