Callback after tracking a goal with javascript?

For the evaluation of an intranet search I need to track user clicks on search results. Since I do not want to modify the URL and track the event on the target page, I’m trying to track the click in javascript and call piwikTracker.trackGoal(…). However, in some browsers I have to wait a short time after calling trackGoal before following the actual link, otherwise the goal is not tracked. Is it possible to get a callback, when the goal is tracked, so I do not have to wait a fixed amount of time (without being sure that all goals are tracked).

Best Regards
Alex

This was asked a while ago, yet I feel this is very relevant not just to me but to anyone who adds click events to buttons that are links or form buttons (a task that’s very common). I believe that without an appropriate callback function there’s a lot of lost data.

So I’d like to re-ask this question:

  • Is there a callback function in Piwik for events? (Assuming there isn’t, can we add that to the next release please!)
  • If not, could someone give me an idea how I could write it either for my front-end or as a plugin for Piwik? As I understand Piwik tracks using a pixel so this should be as simple (or as complex) as firing an event once that pixel is loaded by the browser.

Thank you!!!

Please check this Pull request which maybe implements what you need: Add callback ability to trackEvent by er314 · Pull Request #10337 · matomo-org/piwik · GitHub

if it does not, can you leave a comment on this pull request, so we can improve it ?

This is it! I’ll test it and let you know tonight. Thank you.

OK this wasn’t “tonight” at all, not even close. Sorry about that.

But I’ve used the code from that branch and it seems to work. I’ve tested the front-end (JavaScript) and the fact that the events are actually being recorded in database (via Piwik dashboard). Works with Piwik 2.16.1

I do not know how to use this callback function in my own JavaScript. Can you insert an example please?

function logEvent(category, action, name, value, customData, callback)

Callback is where you add your function.

It would be a nice thing to read about this feature in the official documentation. Here it has only an experimental character.