matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.93k stars 2.66k forks source link

Add FAQ: How to use the rel=canonical URL instead of the page URL? #2974

Open mattab opened 12 years ago

mattab commented 12 years ago

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
  }
}

piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script>
marclaporte commented 10 years ago

Hi!

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: example.org/ABC example.org/index.php?page=ABC

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.

Thanks!

mattab commented 10 years ago

@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 9 years ago

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.

Thanks!

dmarcelino commented 6 years ago

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.