WPLytic
  • What is WPLytic?
  • Get WPLytic
  • Guides
    • Installing WPLytic
    • Tracking Current WordPress Site
    • Tracking External Websites
    • Updating WPLytic
  • API
    • Tags
    • Events
    • Track pageviews for SPAs
  • Examples
    • External Link Click Tracking
  • Features
    • Statistics and Graphs
      • Realtime Visitors Count
      • Multi-domain view
      • Visitor Stats
      • Top Countries
      • Top Pages
      • Top Referrers
    • Individual Session Explorer
    • Filters - User Segments
    • Tracking and Privacy Settings
  • Extras
    • Troubleshoot
      • Updating fails
    • Support
    • License Terms
  • Guides
    • Tracking UTM parameters
Powered by GitBook
On this page
  1. Examples

External Link Click Tracking

PreviousExamplesNextStatistics and Graphs

Last updated 5 months ago

Example of tracking all outbound clicks on links, using and .

document.querySelectorAll('a').forEach(link => {
  link.addEventListener('click', (event) => {
    const url = event.target.href;

    if (url && !url.includes(location.hostname)) { // Outbound link check
      WPLY.addEvent({
        category: 'LINK', // REQUIRED
        action: 'OUTBOUNT_CLICK', // REQUIRED
        label: url, // OPTIONAL: URL of the link
        data: { text: event.target.innerText || 'No Label' } // OPTIONAL: Extra details
      });
     WPLY.addTag('outbout_click');
    }
  });
});
Events
Tags