Skip to content

Instantly share code, notes, and snippets.

@undfine
Created July 20, 2026 22:53
Show Gist options
  • Select an option

  • Save undfine/9ec0b9185a28c4a0f9c993d5e184eae3 to your computer and use it in GitHub Desktop.

Select an option

Save undfine/9ec0b9185a28c4a0f9c993d5e184eae3 to your computer and use it in GitHub Desktop.
google ads call tracking script
var gtagPhoneCallback = function(display_number, linked_number) {
// Replace the number as needed.
var targetLinks = document.querySelectorAll('a[href^="tel:+11231231234"]');
// Swap only the exact matching elements found
for (var i = 0; i < targetLinks.length; i++) {
targetedLinks[i].href = "tel:" + linked_number;
targetedLinks[i].innerText = display_number;
}
};
// 2. Initialize the Google Ads configuration
gtag('config', 'AW-CONVERSION_ID/CONVERSION_LABEL', {
'phone_conversion_number': '123.123.1234',
'phone_conversion_callback': gtagPhoneCallback
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment