How to track external link clicks

In the early days of Bento, we went hard on tracking everything we could.

From rage clicking to external clicks to form submissions — we went for it.

We believed that more data lead to more action.

That was until we saw our Elastic (where we store our events for indexing and searching) bills.

The influx of events being captured completely overloaded our system, which usually isn't too bad because we can scale up, but we also started to see that our users were getting overloaded too.

The data made things noisy.

During any given visitor session they would fire off 5-10 events per second which, when analysed, would often be duplicates as far as visitor intent or classifying was concerned. A click to a page expresses very similar intent, from a segmentation perspective, than a view event on that next page. Why track it twice?

Removing tracking clicks as a default made sense to us so we turned it off.

Once we turned this off by default things became clearer again. 

But there were still a few users who wanted to track everything and we didn't want to get in their way. 

Below is a quick guide on how to track external and internal link clicks across your web properties.

Basic external link tracking


<script>
$('a:not([href^="https://yourwebsite.com"])').on('click', function() {
    bento.track("$externalClick", {url: this.href});
    console.log("Clicked External Link!");
});
</script>

The script above you can copy and paste directly as a personalisation in Bento and just target everyone.

The script will load on each pageview once Bento is initiated.

Now, whenever someone clicks a link that doesn't contain your websites URL it will fire off a custom event in Bento and log it.

Why would you use this? 

Let's say you ran a job board and wanted to track which subscribers clicked on a specific job. With the above being tracked 
you could easily dig up who clicked on what link. 

Another example is publishing affiliates who want to track outbound clicks from their subscribers on specific offers.

Basic internal link tracking

<script>
$('a([href^="https://yourwebsite.com"])').on('click', function() {
    bento.track("$internalClick", {url: this.href});
    console.log("Clicked External Link!");
});
</script>

With one quick amendment to the script, we're now tracking every internal click happening on the site.

We recommend that most people **do not use this script** as it will just create a bunch of noise inside your data.

In most cases a view event isn't really that different from a click as far as segmentation is concerned (i.e segmenting based on who visited the pricing page or who clicked on a link to the pricing page are basically the same thing).

But what if we want to also track clicks in GA or Mixpanel?

Well, given you use Bento, you shouldn't need to but we understand 😂 

Just remove the bento.track lines and replace with your custom event tracking from Mixpanel or Google Analytics. Done! 
Leave a reply