simple way to track all outgoing clicks to other domains?

I realize we can track clicks on individual links using client side JS.

But my WP site has tons of links , I dont want to instrument each one individually.

Is there is a simple way to say "fire tracking event on all link clicks"?

1reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hey Robin, and thanks so much for writing in! That's a good question. Although you can use a Javascript function to snag all the links on your page to fire a track call on click, we typically don't suggest this. First, it's a good idea to limit the data you're collecting by setting up a strict tracking plan. That way, come analysis time, you're not overwhelmed.

    That said, you could implement Javascript to fire these events programmatically, customizing the code depending on what information you want to send with each track call. For example, the following code block would fire a track event on click of any DOM element tagged with <a>:

    var links = document.getElementsByTagName('a');
    for (i = 0; i < links.length; i++) {
      links[i].addEventListener('click', function() {
        analytics.track('Clicked a Link');
    Reply Upvote