Adwords Call Forwarding in Google Tag Manager
Get your conversion code from adwords.
Define a CSS selector for the HTML element that contains the phone number to be converted.
Create a new tag in GTM
Select a tag configuration of Custom HTML <>
Paste the JS conversion code into the textarea.
Define a trigger of All Pages.
Just before the closing tag, paste the number replacement script:
//Change the values in this section to customize for your implementation. //Replace with business's phone number EXACTLY as it appears on the website. var business_number = "(555) 555-5555"; //Replace with business's phone number without spaces or symbols. var business_number_unformatted = "5555555555"; //Replace this value with the CSS selector for the phone number's element. var business_number_identifier = "h2.site-description"; //End customization section var callback = function(formatted_number, unformatted_number) { var numberElement = document.querySelector(business_number_identifier); var numberString = numberElement.innerHTML; numberString = numberString.replace(business_number,formatted_number); numberElement.innerHTML = numberString; }; //The line of code below is for testing with GTM's debug mode. //It replaces the business phone number with a testing number (666-666-6666). window.onload = callback('666-666-6666', business_number_unformatted); //This code executes everything. When you're done testing and you're ready to publish the //GTM container, place '//' in front of the code above, and remove the '//' below. //window.onload = _googWcmGet(callback, business_number);
Save the tag and select GTM’s Preview and Debug mode. Then test the website. If the tag is configured successfully, the phone number should be the debug number:666-666-6666.
Now disable the debug number and activate the Google number:
Comment this: //window.onload = callback('666-666-6666', business_number_unformatted); Uncomment this: window.onload = _googWcmGet(callback, business_number);
Publish Tag Manager and conclude the task.