GoatCounter will automatically bind a click event on any element with the data-goatcounter-click attribute; for example to track clicks to an external link as

<a href="" data-goatcounter-click="">Example</a>

The name or id attribute will be used if data-goatcounter-click is empty, in that order.

You can use data-goatcounter-title and data-goatcounter-referrer to set the title and/or referrer:

<a href=""
   data-goatcounter-title="Example event"

The regular title attribute or the element’s HTML (capped to 200 characters) is used if data-goatcounter-title is empty. There is no default for the referrer.

Sending events from JavaScript

You can send an event by setting the event parameter to true in count(). For example:

$('#banana').on('click', function(e) {
        path:  'click-banana',
        title: 'Yellow curvy fruit',
        event: true,

The path doubles as the event name. This cannot have / as the first character.

There is currently no real way to record the path with the event, although you can send it as part of the event name:

    path:  function(p) { return 'click-banana-' + p },
    event: true,

The callback will have the regular path passed to it, and you can add an event name there; you can also use window.location.pathname directly; the biggest difference with the passed value is that <link rel="canonical"> is taken in to account.

Questions or problems?

Feel free to get in touch if you’ve got any questions or having any problems; a lot of times they can be resolved without too much problems.

Ways to contact me: show