$(document).ready(function() { onst desktopPhone = '1-111-1111'; const utmPhone = '1-111-1111'; const noFbIdPhone = '1-111-1111'; const urlParams = new URLSearchParams(window.location.search); const phoneNumberRegex = /(?:\+?1-)?\d{3}-\d{3}-\d{4}/g; // Regular expression for phone numbers with optional +1 prefix setTimeout(function() { $('body *').each(function() { // Update text content if ($(this).children().length === 0) { $(this).text(function(index, text) { return text.replace(phoneNumberRegex, function(match) { if (navigator.userAgent.indexOf('Mobile') < 0x1) { return desktopPhone; } else { if (!urlParams.has("fbclickid")) { return noFbIdPhone; } else if (urlParams.get("campaign_name") === "{{campaign.name}}" || !urlParams.has('campaign_name')) { return utmPhone; } } }); }); } // Update tel: links if ($(this).is('a') && $(this).attr('href') && $(this).attr('href').startsWith('tel:')) { const originalPhoneNumber = $(this).attr('href').substring(4); const replacedPhoneNumber = originalPhoneNumber.replace(phoneNumberRegex, function(match) { if (navigator.userAgent.indexOf('Mobile') < 0x1) { return desktopPhone; } else { if (!urlParams.has("fbclickid")) { return noFbIdPhone; } else if (urlParams.get("campaign_name") === "{{campaign.name}}" || !urlParams.has('campaign_name')) { return utmPhone; } } }); $(this).attr('href', 'tel:' + replacedPhoneNumber); } }); }, 2000); // Delay of 2 seconds });