Content Tracking stops working when trackVisibleContentImpressions

Hello,
I’m facing an issue with content tracking. The goal is to track the impressions on a block of html code.

A div is placed (initially hidden) on a page with the correct html attributes.
If in the tracking snippet I do not include any statement about content tracking, the content is tracked correctly, regardless whether the content is visible or not.

However, if I add “_paq.push([‘trackVisibleContentImpressions’, true, 750]);” to the page, content tracking stops working, even after the content becomes visible and scrolls into view.

Worth noting that the content is loaded dynaically, and there fore the statement “_paq.push([‘trackContentImpressionsWithinNode’, domNode]);” is executed every time a new div is added.

If anybody can shed some light on this, it would be highly appreciated.

Hi,

You’ve probably come to a solution since you asked, but I’ve also come across this issue, and from what I can determine by reading their documentation and source, it’s actually by design. Their documentation makes an ambiguous reference to this, though it’s really poorly worded, while the source for this particular method is slightly more useful but equally cryptic.

See https://developer.matomo.org/guides/tracking-javascript-guide#content-tracking and scroll to the “Track content impressions only for a part of the page” header and review the text beneath the example. The emphasis is my own:

We would detect two new content impressions in this example. In case you have enabled to track only visible content blocks we will respect this.

Ambiguous? Yeah. Let’s see what the source states.

Again, emphasis my own:

If you have called trackVisibleContentImpressions() upfront only visible content blocks will be tracked. You can use this method if you, for instance, dynamically add an element using JavaScript to your DOM after we have tracked the initial impressions.

Reviewing the actual source for this method also suggests that they are keeping track of everything that would have been initially discovered on the page that was visible, and so when dynamically adding more content and instructing Matomo to discover additional content within the specified node, it cannot operate on it because it is not part of the initial group of discovered visible nodes.

Taking all this information together, and from my testing, it’s clear that Content Tracking will not work on content that was dynamically added if the trackVisibleContentImpressions method was called initially.

While their official Content Tracking guide (https://developer.matomo.org/guides/content-tracking) states pretty clearly this should work, it definitely does not.

The only way to track impressions and interactions for dynamically added content is to initially call trackAllContentImpressions and NOT trackVisibleContentImpressions, and then the trackContentImpressionsWithinNode method will work as expected.

1 Like