Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mattab opened this issue Feb 25, 2012 · 4 comments
Open

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

mattab opened this issue Feb 25, 2012 · 4 comments
Labels
c: Website matomo.org For issues related to our matomo.org website. Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.

Comments

@mattab
Copy link
Member

mattab commented Feb 25, 2012

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>
@mattab mattab added this to the Future releases milestone Jul 8, 2014
@marclaporte
Copy link
Contributor

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
Copy link
Member Author

mattab commented Aug 20, 2014

@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
Copy link
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.

Thanks!

@mattab mattab modified the milestones: Long term, Mid term Dec 23, 2015
@mattab mattab modified the milestones: Long term, Mid term Dec 5, 2016
@dmarcelino
Copy link

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.

@Findus23 Findus23 added the c: Website matomo.org For issues related to our matomo.org website. label Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Website matomo.org For issues related to our matomo.org website. Task Indicates an issue is neither a feature nor a bug and it's purely a "technical" change.
Projects
None yet
Development

No branches or pull requests

4 participants