I've been trying to get conversion tracking setup to use Google Adwords free call tracking numbers, but the client has multiple business locations, each with their own phone number. So we need different numbers to be replaced, depending on the page that is visited from the ads.
On top of that the numbers are also href="tel:" click to call numbers, and occur in multiple locations on the page.
There seems to be lots of contradictory advice on whether you can replace different numbers on different pages. What steps need to be taken to implement tracking numbers in this situation?
Note: this is not referring to replacing different numbers on the same page with different tracking numbers. The advice seems pretty universal on this that it can't be done.
Okay, so after much testing and gnashing of teeth, it is possible to implement this, and it is (relatively) straightforward. I'll explain how I did this using Google Tag Manager (GTM) to add the code to the pages. I'd welcome thoughts and feedback on how perhaps this might be done more elegantly...
.
<script type="text/javascript" id="adwords_google_forwarding_num">
; (function() {
var originalNumber = 'xx xxxx xxxx'; // replace with number to be tracked
function callback(formattedNumber, mobileNumber) {
var phoneElement = document.querySelectorAll('.number_link'); //replace with whatever selector you're using to using
if (phoneElement) {
for(i=0;i<phoneElement.length;i++){
phoneElement[i].href = "tel:" + mobileNumber;
phoneElement[i].innerHTML = "";
phoneElement[i].appendChild(document.createTextNode(formattedNumber));
}
}
};
_googWcmGet(callback, originalNumber);
})();
</script>