metallissimus wrote:
The titles don't match the URLs (except for the entry page).
Yes, likely because the event is tracked before the document.title changes to the new page. It can be resolved by adding a tiny 100ms delay:
function x3_load_page(){
setTimeout(() => {
console.log('_paq.push', document.title);
_paq.push(['setCustomUrl', window.location.pathname]);
_paq.push(['setDocumentTitle', document.title]);
_paq.push(['trackPageView']);
}, 100);
}
metallissimus wrote:Also I noticed the entry page always gets reloaded (or Matomo counts it as reloaded). Why is that?
Not quite sure what you mean "gets reloaded". The x3_load_page function will trigger ONCE for each page, including on the entry page, and this is of course as it's supposed to work. If Matoto triggers TWICE for the entry page, then I assume this is what is happening: It automatically tracks the current page (entry page) when the Matomo Javascript loads, and then we are also tracking all pages (including current page) manually ... This would lead to the entry page being tracked twice.
This is a bit stupid, but doesn't Matomo have options for this? Surely some option "don't automatically track". Or is the developer supposed to integrate custom tracking with "track all page, but don't track the first page!" I don't feel it's my responsibility to resolve this. Their documentation seems dated.
It would be quite easy to fix with a not-so-elegant solution.
let _paq_first = true;
function x3_load_page(){
if(_paq_first) return _paq_first = false;
setTimeout(() => {
console.log('_paq.push', document.title);
_paq.push(['setCustomUrl', window.location.pathname]);
_paq.push(['setDocumentTitle', document.title]);
_paq.push(['trackPageView']);
}, 100);
}
In the above, it won't track on the first page (where I assume Matomo automatically tracks from the loaded javascript).