Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Created February 8, 2026 12:36
Show Gist options
  • Select an option

  • Save vanaf1979/fabac9ff72bc189e3ab7526199998e71 to your computer and use it in GitHub Desktop.

Select an option

Save vanaf1979/fabac9ff72bc189e3ab7526199998e71 to your computer and use it in GitHub Desktop.
GA4 email phone clicks
// Track Telephone Clicks
const phoneLinks = document.querySelectorAll('a[href^="tel:"]');
phoneLinks.forEach(link => {
link.addEventListener('click', () => {
gtag('event', 'contact_click', {
'type': 'phone',
'number': link.href
});
}, { once: true });
});
// Track Email Clicks
const emailLinks = document.querySelectorAll('a[href^="mailto:"]');
emailLinks.forEach(link => {
link.addEventListener('click', () => {
gtag('event', 'contact_click', {
'type': 'email',
'address': link.href
});
}, { once: true });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment