David Grenier
David Grenier

Reputation: 1241

Canonical URL in Analytics

As far as I know, canonical URLs are only recognized by search engines - a way to ensure that when a search engine crawls your page, no matter which URL got it there, all of the "link juice" points to one canonical URL. So on a DNN site when example.com/, example.com/Default.aspx, example.com/tabid/36/Default.aspx, example.com/home/tabid/36/Default.aspx are all URLS for the homepage, a search engine can compress them all into one listing in it's index rather than diluting the PageRank across several URLs.

My question is whether canonical URLs are recognized by Google Analytics, or if there is any other trick to keep that same home page from showing up as 5 or 6 different pages (URLs) in Analytics.

Upvotes: 21

Views: 8230

Answers (3)

Aaron Sherman
Aaron Sherman

Reputation: 3887

Per https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#location

...
ga('create', 'YOUR ID', 'auto');
ga('set', 'page', 'http://yourdomain/foo');
ga('set', 'title', 'New Title'); //optional to change title too!
ga('send', 'pageview');
...

Note you need to use a fully qualified url (include your domain) otherwise GA will ignore it

Upvotes: 0

Grant Thomas
Grant Thomas

Reputation: 45058

From what I recall, Matt Cutts of Google does recommend using 301 Redirects proper instead of relying on canonicalising through the introduced meta-element, and I would certainly prefer it over adding yet more complexity even to that (for example, such as some contrived JavaScript to do the Analytics submission).

Bottom line, treat the disease and not the symptoms: look closer to home and get Analytics to respect your implementation instead of disrespectingly shoehorning into that system.

This might not be viable if you actually need one page to be accessible using multiple URLs, but in that case I would scarecly see the value in combining them in Analytics in the first place.

Upvotes: 1

Eduardo
Eduardo

Reputation: 22832

Not recognized by default. But it's easy to setup GA to track the canonical urls when they are available.

instead of calling

_gaq.push(['_trackPageview']);

You can use:

var canonical_link;
try{
  canonical_link = jQuery('link[rel=canonical]').attr('href').split(location.hostname)[1] || undefined;
}
catch(e){
  canonical_link = undefined;
}
_gaq.push(['_trackPageview', canonical_link]);

Upvotes: 30

Related Questions