araphiel
(Armon Raphiel)
1
Can Piwik automatically track information if javascript is used to get to that page?
Lets say we want to go from example.com to example.com/page-2
If we click on a regular link, this gets tracked by Piwik automatically.
If we use javascript to switch pages, will Piwik detect this?
You can try this on this page by dropping this in your console & clicking any button here.
$('button').on('click', function(event){
event.preventDefault;
document.location = "https://www.example.com/page-2";
});
Lukas
(Lukas Winkler)
2
Hi,
There is no way to detect it automatically, but it’s quite easy to track it manually with _paq.push(['trackPageView']);
.
https://matomo.org/blog/2017/02/how-to-track-single-page-websites-using-piwik-analytics/
araphiel
(Armon Raphiel)
3
Thank you Lukas!
So to confirm, something like this would track the movement to /page-2?
& is document title absolutely required?
$('button').on('click', function(event){
event.preventDefault;
_paq.push(['setCustomUrl', 'https://www.example.com/page-2']);
_paq.push(['setDocumentTitle', 'Page 2']);
_paq.push(['trackPageView']);
document.location = "https://www.example.com/page-2";
});
Edit: For future readers, this is unnecessary unless you are building an SPA or a single page site &
Lukas
(Lukas Winkler)
4
Hi,
I just noticed I misread your question. My answer is only valid for single page application (when you switch to another URL without an page load).
If you load pages “traditionally” it doesn’t matter how the visitor gets to the page-2, it will be tracked as a normal page view.
1 Like