# Track Phone, Email and WhatsApp Link Clicks

> Sends an event to Google Analytics 4 (or the GTM dataLayer) whenever a visitor clicks a phone number, email address or WhatsApp link, so you can count leads from these contacts.

- Type: PHP
- Runs: Frontend only
- Category: [Analytics & Tracking](https://wpide.com/library/category/analytics/)
- Tags: google-analytics, ga4, events, leads
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/analytics-contact-click-events/

## Code

```php
add_action( 'wp_footer', function () {
    ?>
<script>
document.addEventListener('click', function (e) {
    var link = e.target.closest ? e.target.closest('a[href]') : null;
    if (!link) { return; }
    var href = link.getAttribute('href') || '';
    var method = /^tel:/i.test(href) ? 'phone' : /^mailto:/i.test(href) ? 'email' : /(wa\.me|api\.whatsapp\.com|whatsapp:)/i.test(href) ? 'whatsapp' : '';
    if (!method) { return; }
    var params = { method: method, link_url: href.replace(/^(tel:|mailto:)/i, ''), link_text: (link.textContent || '').trim().slice(0, 100) };
    if (typeof gtag === 'function') {
        gtag('event', 'contact_click', params);
    } else {
        window.dataLayer = window.dataLayer || [];
        window.dataLayer.push(Object.assign({ event: 'contact_click' }, params));
    }
}, true);
</script>
    <?php
} );
```

## Notes

Events are named contact_click with a method parameter (phone, email, whatsapp). Mark contact_click as a key event in GA4 to count it as a conversion.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Track Phone, Email and WhatsApp Link Clicks" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
