Architect reported that the phone numbers were not swapping on the website. The RCFX Pixel was not installed, and the phone number format (301) 200 – 9030 was not swapping even after it was installed.
I installed the RCFX Pixel in layout/theme.liquid in the Shopify Theme Editor.
The number still did not swap because of its format (301) 200 – 9030, so I added a custom code that normalizes the phone number format in the paragraphs and then runs the CallTrackerFX number replacement on them.
var interval;
var attempts = 0;
var phoneRe = /((d{3}))s*(d{3})s*-s*(d{4})/g;
function normalizePhones(el) {
var found = [];
var walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
var nodes = [];
var n;
while ((n = walker.nextNode())) {
nodes.push(n);
}
for (var j = 0; j < nodes.length; j++) {
var txt = nodes[j].nodeValue;
phoneRe.lastIndex = 0;
if (!phoneRe.test(txt)) {
continue;
}
phoneRe.lastIndex = 0;
var matches = txt.match(phoneRe);
for (var k = 0; k < matches.length; k++) {
found.push(matches[k]);
}
phoneRe.lastIndex = 0;
nodes[j].nodeValue = txt.replace(phoneRe, function (m, a, b, c) {
return '(' + a + ') ' + b + '-' + c;
});
}
return found;
}
function checkAnchors() {
var els = document.querySelectorAll('p');
try {
mcfx(function (t) {
for (var i = 0; i < els.length; i++) {
var hits = normalizePhones(els[i]);
if (hits.length) {
console.log('matched:', hits, els[i]);
}
t.modules.calltracking.replaceNumbers(els[i]);
}
});
} catch (err) {
}
attempts++;
if (attempts > 100) {
clearInterval(interval);
}
}
checkAnchors();
interval = setInterval(checkAnchors, 1000);
Phone numbers now swap on the website for all sources, even with the spaced format.
Task: Link
Code: Screenshot