Expand my Community achievements bar.

Canonical Tags

Avatar

Level 3

Good day to all!

May I know if there's a way to add canonical tag on a specific page in AEM?

<link rel="canonical" href="https://www.samplelink.com/en/contactus.html" />

6 Replies

Avatar

Community Advisor

Yes, you can do it by using Java/JS/HTL

In head, you can do something like below:

Head.js

use(function () {

    return {

        canonical:"https://aem63app.com"+currentPage.getPath()+".html"

    };

});

head.html

<sly data-sly-use.head="head.js">

<link rel="canonical" href="${head.canonical}"/>

<!--/* Include Context Hub */-->

Or you can use java and apply your business logic and return href value.

Thanks

Arun



Arun Patidar

Avatar

Level 3

Hi Sir,

I don't have access to update/edit AEM templates.

I have tried adding canonical tag <link rel="canonical" href="https://www.samplelink.com/en/contactus.html" /> thru Adobe DTM but it is not reflecting on "view page source" and also on elements tab of Devtools.

regards

Avatar

Community Advisor

Hi,

I have no idea about DTM but other people in forum can help. but how did you injected canonical tag in the page? If you are injecting canonical tag on runtime using javascript, then It won't be appears in page source but it will be added in page and you can check using inspect element in browser.

Are you able to put javascript logger , e.g. console.log("Canonical Added" ) something like that, so that you can be sure code is executing or not.

Thanks

Arun



Arun Patidar

Avatar

Level 3

Hi Arun,

Actually, I have not added the canonical tag on the page since this tag needs to go inside the head tag which I don't have access to.

I am not able to put js logger also =(

Avatar

Community Advisor

Hi,

I want to understand how you are planning to implement Canonical Tag using DTM? Are you going to write something in DTM client script and injecting canonical tags like other tags? You can't add logger in below client side script or something to check if canonical tag is executing or not?

Dynamic Tag Management - Digital Marketing cloud service that allows a marketer to manage Adobe and third-party tags used for tracking or other analytic purposes. It is done through client-side scripting that injects tag related code throughout the pages of the site.

I am not aware of DTM, so not sure if you can inject other tags from DTM or you need to implement something in AEM.

Thanks

Arun



Arun Patidar

Avatar

Level 3

It is thru DTM we add those Google Analytics and other SEO codes which our AEM pages needed(ie. inside head tags, bottom of the page etc.).

We just paste the code and specify trigger rule and that's it.