Days on site

Showing 1 property

Map
(function() { // Utility: check if URL matches our endpoint. function isTargetUrl(url) { return typeof url === 'string' && url.indexOf('/api/leads/me') !== -1; } // Process JSON: extract email and push to dataLayer. function processJsonData(responseJson) { try { if (responseJson && responseJson.data && responseJson.data.email) { var email = responseJson.data.email; if (window.dataLayer && typeof window.dataLayer.push === 'function') { window.dataLayer.push({ 'event': 'generate_lead', 'user_data': email }); } else { console.warn('dataLayer is not defined on the page.'); } } } catch (e) { console.error('Error processing JSON data:', e); } } // Intercept XMLHttpRequest calls. (function() { var originalOpen = XMLHttpRequest.prototype.open; var originalSend = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.open = function(method, url, async, user, password) { try { this._targetUrl = url; } catch (e) { console.error('Error in XHR open interception:', e); } return originalOpen.apply(this, arguments); }; XMLHttpRequest.prototype.send = function(body) { try { if (isTargetUrl(this._targetUrl)) { this.addEventListener('readystatechange', function() { if (this.readyState === 4) { try { // Do nothing if unauthorized. if (this.status !== 401) { var contentType = this.getResponseHeader('Content-Type') || ''; if (contentType.indexOf('application/json') !== -1) { var responseJson; try { responseJson = JSON.parse(this.responseText); } catch (jsonError) { console.error('Error parsing JSON response:', jsonError); } if (responseJson) { processJsonData(responseJson); } } } } catch (ex) { console.error('Error during XHR interception:', ex); } } }); } } catch (ex) { console.error('Error in XHR send interception setup:', ex); } return originalSend.apply(this, arguments); }; })(); // Intercept fetch requests. if (window.fetch) { var originalFetch = window.fetch; window.fetch = function(input, init) { // Capture URL early. var fetchUrl = ''; if (typeof input === 'string') { fetchUrl = input; } else if (input && input.url) { fetchUrl = input.url; } return originalFetch.apply(this, arguments).then(function(response) { try { if (isTargetUrl(fetchUrl)) { if (response.status !== 401) { var contentType = response.headers.get('Content-Type') || ''; if (contentType.indexOf('application/json') !== -1) { // Clone the response to avoid disturbing other consumers. response.clone().json().then(function(responseJson) { processJsonData(responseJson); }).catch(function(fetchJsonError) { console.error('Error parsing JSON in fetch response:', fetchJsonError); }); } } } } catch (ex) { console.error('Error during fetch interception:', ex); } return response; }).catch(function(fetchError) { console.error('Fetch error:', fetchError); throw fetchError; }); }; } })();