Job Function Email Database

Here’s How to Generate and Insert Rel Canonical With Google Tag Manager

The author’s views are entirely their own (excluding the unlikely event of hypnosis) and may not always reflect the views of moz. We’ll do it using google tag manager and its variables.

Why send a canonical from each page to itself?
Javier lorente gave us a very good explanation/reminder at the 2015 seo salad event in zaragoza (spain). In short, there may be various factors that cause google to index unexpected variants of a url, and this is often beyond our control:

External pages that display our website but use another url (e.G., google’s own cache, other search engines and content aggregators, archive.Org, etc.). This way, google will know which one is the original page at all times.
Parameters that are irrelevant to seo/content such as certain filters and order sequences
By including this “standard” canonical in every url, we are making it easy for google to identify the original content.

How Do We Generate the Dynamic Value of the Canonical Url?

To generate the canonical url, dynamically we need to force it to always correspond to the “clean” (I.E., absolute, unique, and simplified) url of each page (taking into account the www, url query string parameters, anchors, etc.).

Remember that, in summary, the url variables that can be created in gtm (google tag manager) correspond to the following components:

Url variables in google tag manager
We want to create a unique url for each page, without queries or anchors. We need a “clean” url variable, and we can’t use the {{page url}} built-in variable, for two reasons:

Although fragment doesn’t form part of the url Loan Officer Email List by default, query string params does
Potential problems with protocol and hostname, if different options are admitted (e.G., ssl and www)
Therefore, we need to combine protocol + host + path into a single variable.

Now, Let’s Take a Step-by-step Look at How to Create Our {{page Url Canonical}} Variable

Job Function Email Database

1. Create {{page protocol}} to compile the EL Leads section of the url according to whether it’s an http:// or https://
Page protocol
Note: we’re assuming that the entire website will always function under a single protocol. If that’s not the case, then we should substitute the {{page protocol}} variable for plain text in the final variable of step #4. (this will allow us to force it to always be http/https, without exception.)
2. Create {{page hostname canonical}}
The hostname canonical must always be the same, regardless of whether or not it has the www. We can decide based on which one of the domains is redirected to the other, and then keep the original as the canonical.

Leave a Reply

Your email address will not be published. Required fields are marked *