Track fancybox images with matomo

Only the click on the first thumbnail is being tracked but I would like to track all impressions of images within the fancybox gallery. I tried it with visible elements but somehow it doens’t record anything.

Could anyone point me in the right direction. I suppose it’s the same for all kinds of lightbox galleries.

Kind regards

Hi,

Check out the API section of the fancybox docs.
It tells you that you can listen to the event that an image is being viewed with

$("[data-fancybox]").fancybox({
    afterShow: function( instance, slide ) {
        console.log("slide is being viewed")
    }
});

So all you need to do to track an event in Matomo is to replace the console.log with something similar to _paq.push(['trackEvent', 'Documentary', 'Play', 'Thrive']);. If you try around a bit, you should be able to extract the open image title or filename (maybe look into slide.opts).

As you put this in the #tag-manager category, I’d also recommend you to look into Data Layer: Integrate - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3 on how to send an event to the tag manager instead.

Hi Lukas,

Thanks a million. I will give it a try. Seems straigt forward enough!

1 Like

Hi,
I just recorded this video for you. It does not show the content tracking but how you can do it with events:


if it fits your needs, could you please mark the post as solved?

Have a great day,

1 Like

Thank you so much for all your help Ronan! This works perfectly for me

Ps, I am making progress :slight_smile: One other thing I wanted was to track logged in users. I was quite surprised I got it right straight away :slight_smile:

https://discourse.getgrav.org/t/tracking-logged-in-users-in-matomo-or-google-analytics/9835/3