Workaround for CTFX v2 not swapping due to excess spaces

gerard_reyes Posted by: Gerard Reyes Date Posted: April 22, 2025
Back to Case Studies

Issue

The phone number on the client’s site has an extra space like this: (800)   999-9999.

CTFX v2 cannot swap this number. Even entering the exact format in the target to swap it still does not work.

R&D confirmed this is a bug.

Solution

I added a code in GTM to fix the original phone number. Once it is fixed, CTFX v2 worked in the background to swap it to the correct number.

This is a workaround while the bug is not fixed in CTFX v2. Best solution is to fix the number on the client site, but unfortunately we do not have access to the client’s site.

 

<script>
(function() {
     // Select all <a> elements with href starting with "tel:"
     var telLinks = document.querySelectorAll('a[href^="tel:"]');

     // Loop through the selected elements
     telLinks.forEach(function(link) {
         // Get the href value
         var hrefValue = link.getAttribute('href');

         // Trim spaces from the href value
         var trimmedHref = hrefValue.replace(/\s/g, '');

         // Update the href attribute with the trimmed value
         link.setAttribute('href', trimmedHref);

         // Get the text content of the link
         var textContent = link.textContent;

         // Trim spaces from the text content
         var trimmedText = textContent.replace(/\s/g, '');

         // Update the text content of the link
         link.textContent = trimmedText;
     });
})();
</script>

Achievement

Number was swapped by CTFX v2.

Snippet/Screenshot/Link

Task: Link

Code: Screenshot