@mattab opened this Issue on February 25th 2012 Member

Some CMS/Ecommerce shops generate ugly URLs, but might specify a rel=canonical URL. Some users would benefit from using this URL instead of the URL in the address bar, so that it looks better in Piwik Actions > Pages report.

From this blog post - it would be interesting to have this in a FAQ!

<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$URL}/" : "http://{$URL}/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$SITE_ID});

var canonical = "";
var links = document.getElementsByTagName("link"); // alle <link>-Elemente der Seite auslesen
for (var i = 0; i < links.length; i ++) { // alle gefundenen <link>-Elemente durchlaufen
  if (links[i].getAttribute("rel") === "canonical") { // <link rel="canonical"> gefunden
    canonical = links[i].getAttribute("href"); // Variable canonical mit Canonical-URL belegen
    piwikTracker.setCustomUrl(canonical); // Piwik anweisen die URL aus unserer Variable zu nutzen

} catch( err ) {}
@marclaporte commented on August 15th 2014 Contributor


It seems to me taking advantage of the canonical URL should be a built-in option in Piwik.

Canonical tells search engines that these two are equivalent:

So why would we want our analytics to think differently?

There could be a debate if it should be turned on or off by default.


@mattab commented on August 20th 2014 Member

@marclaporte good point, maybe it should be enabled by default in Piwik. Maybe one drawback would be in case of the website implemented canonical URLs with some bugs, then the Piwik reporting would look buggy as well.

@marclaporte commented on March 2nd 2015 Contributor

If there are bugs with the canonicals of the web app, anything that can help detect them early is a good thing. As this feature would be optional, they could turn off until they fix the canonical feature.


@dmarcelino commented on February 1st 2018

Another scenario where it can be good to map multiple URLs to a single one is on multilingual websites where each language has its own URL (good SEO practice). I'm currently working on such a project and had to resort to setCustomUrl and setDocumentTitle to work around this issue. For the URL, at least, it would be nice if Matomo could look at hreflang links, for example, to derive which URL to use.

I agree with @marclaporte, Matomo should do this for the user, probably contingent on some configuration.

Powered by GitHub Issue Mirror