How to track custom event with data

Hi, I’m new to Matomo.

I want to use Matomo for all its classic analytics features but also for tracking custom events and add custom data to this events.
And I don’t think that this sort of tracking is possible with Matomo. I’ve seen the trackEvent or contentTracking but it seems to limited for my use case.

example of custom event I want to track : Track a click on a button to add an item to a wish list.
on this event I want to add data like the current user id doing the action, the item id, the current item category id, the type of page, a custom context, …
And the important part is that I want to retrieve the raw data of the event via the API. For now, displaying this event on matomo UI is not necessary.

Is this feature is natively feasible with Matomo, or via a Matomo plugin ?

If not, can you think it’s possible to develop a plugin to do it ?
and quite easily for a medium/good php developer ?

will it require a JS developer to integrate this new feature to a website or a code like this will succeed (if PHP part is develop) :

<a href="#" onclick="_paq.push(['trackMyDataEvent', {'action': 'wishlist', 'page': 'home', 'context': 'new', 'id': '123e4567-e89b-...', ...}]);">Add to wishlist page</a>

Thanks,
Julien.

Hi @jch
By default, if you track the page before the event, the event stays attached to the page (URL / title).
Then, you can also add custom dimensions to the tracked event:

https://developer.matomo.org/guides/tracking-javascript-guide#custom-dimensions

Please note that your event tracking code seems wrong. You should use:

<a href="mailto:name@example.com"
   title="Email Us"
   onclick="_paq.push(['trackEvent', 'Contact', 'Email Link Click', 'name@example.com']);"
   >Email Us</a>

I use this code to track activities on my website:

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  _paq.push(['setUserId', 'USER_ID_HERE']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//{$MATOMO_URL}/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', {$IDSITE}]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

However, in 200 out of 42,000 cases, the user_id is not tracked, but all other information is tracked.
It is impossible to log in to the page without authorization and the user_id must be tracked.
Help me :slight_smile: