The purpose of the data-content-target attribute

In the Content Tracking guide an example of how to set the Content-Target is given as follows:

<div data-track-content>
     <input type="submit" data-content-target=""/>

What is not understood is the nature and the purpose of the value of the data-content-target attribute.

Neither is this value set with an href attribute, nor does it appear to point to a PHP or some other processing file to which input control statements of the submit type typically point. In fact, the value appears to be little more than a named string with no function other than to provide the content-block with a known identity.

Ich verstehe nicht.



I have not much experience with Content Tracking, so I can only quote the docs:

Content target:
For instance the URL of a landing page where the user was led to after interacting with the content block. In a single page website it could be also the name of an anchor. In a mobile app it could be the name of the screen you are going to open.

The data-something-attributes don’t change the HTML itself but rather tell Matomo what to do with this element.

OK. So, if I have understood correctly the value of the data-content-target attribute in the above context is merely a copied link with no functionality of its own. Is this correct?

On the same page, a reference is made to the difference between links with the same domain, links that are either outlinks or downloads, and links that point to anchors. What I have been able to understand with some degree of confidence is the following:

If link tracking is not enabled, then

  1. Target links having the same domain are redirected to the piwik.php file before they are made available to the interacting user and
  2. Outlinks and links that point to anchors and downloads are not redirected and their reported information is handled via the XHR event object.

QUESTION: What happens when link-tracking is enabled.

The passages in question are provided below. Perhaps someone is better able to sort through the confusion than I.

The way we track interactions varies based on the type of the link.

Links to the same domain

In case we detect a link element having an href attribute to the same domain as the current page we will replace the href attribute with a link to the piwik.php tracker URL. Whenever a user clicks on such a link we will first send the user to the piwik.php of your Matomo installation and then redirect the user from there to the actual page. This makes sure to track an interaction even if someone opens the URL with a right click.

If the URL of the replaced href attribute changes meanwhile by your code we will respect the new link.

Note: The referrer information will get lost when redirecting from piwik.php to your page. If you depend on this you need to disable automatic tracking of an interaction see below.

Outlinks and downloads

Outlinks and downloads are handled as before via XHR. If a user clicks on a download or outlink we will track this action as usual along with some information related to the content interaction. If link tracking is not enabled we will track downloads having the same domain via piwik.php and all others via XHR.

Tracking via XHR can delay loading a new page by a few hundred ms as we have to track the outlink before moving the user to the new page.

Anchor links

Anchor and all other kind of links will be tracked using an XHR.