Disable CallTrackerFX on specific page

gerard_reyes Posted by: Gerard Reyes Date Posted: November 18, 2024
Back to Case Studies

Issue

The client doesn’t want their support number (found on this page: https://www.tims.com/contact-support) to swap.

 

CallTrackerFX does not have the capability to be disabled for a specific page.

Solution

I created a custom script to overwrite the number swapping after CallTrackerFX has swapped numbers.

<script>
(function() {
if (window.location.href.includes('tims.com/contact-support')) {
     console.log('The current URL contains tims.com/contact-support');

     // Initialize a counter to keep track of the number of times the message has been logged
     var count = 0;

     var phoneNumbers = [
         '978-480-6748',
         '978-473-8101',
         '978-391-6057',
         '978-391-2194'
     ];

     var replacementNumber = '(978) 458-4624';

     // Set a timeout for 1 second and start logging messages every 1 second for 5 seconds
     setTimeout(function() {
         var intervalId = setInterval(function() {
         console.log('Message logged after 1 second.');
         count++;

         // Get all <p> elements with class "preFade" and "fadeIn"
         var paragraphs = document.querySelectorAll('p.preFade.fadeIn');

         paragraphs.forEach(function(paragraph) {
             var originalContent = paragraph.innerHTML;
             var updatedContent = originalContent.replace(new RegExp(phoneNumbers.join('|'), 'g'), replacementNumber);

             if (originalContent !== updatedContent) {
                 paragraph.innerHTML = updatedContent;
                 console.log('Number swapped!');
             }
         });

         if (count >= 5) {
             console.log('Interval stopped');
             clearInterval(intervalId); // Stop the interval after logging 5 messages
         }
         }, 1000);
     }, 500);
}
})();
</script>

Achievement

CallTrackerFX number swapping was not applied to the specific page

Snippet/Screenshot/Link

Code: Screenshot

Task: Link