Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

RTE Href - Additional Attributes

Avatar

Level 5

Hello Community - We have a requirement to add some additional tags (highlighted below) as part of href link. Currently we have an plugin/option in Rich Text Editor to specify the target/href url and target (self/blank). We don't need to show the highlighted attributes/options in the plugin UI for authors and should generated once the link is authored. I see some articles that specify some changes related to "link-options.js". Not sure if this is correct. These additional data is required for analytics. Can someone provide some details on how to implement this?

 

<a title="Privacy Policy" href="https://www.adobe.com"
data-asset-id="container-727741347-link-0"
data-asset-type="LINK"
data-asset-name="Privacy Policy"
target="_blank">
Privacy Policy</a>

1 Accepted Solution

Avatar

Correct answer by
Level 8

If you have good knowledge on JS then you can customize this "link-options.js", I have done similar implementation in classic UI, but not in Touch UI. you need to put some additional effort for R&D

 

Another approach is you can write a sling model, that reads the content of the rich text editor, and inside the sling model use regex to find out anchor links and replace anchor links by adding custom attributes.

 

My preferable approach is, you are adding custom attributes for analytics tracking, I feel, on click on the anchor link you can call below function, link name you can read from the anchor link title. Link type and id either you can hardcode or you can write some logic.

 

function trackLink(link) {
if (typeof _satellite !== "undefined" && typeof digitalData !== "undefined" ) {
digitalData.page.link.name = "Privacy Policy";
digitalData.page.link.type = "LINK";
digitalData.page.link.id = "your custom id specific logic";
_satellite.track('anchorLink');
}
}

View solution in original post

5 Replies

Avatar

Community Advisor

@v1101 From where will the Values for the additional attributes be pulled ? 

Avatar

Level 5
@VeenaVikraman - ID is the unique field which is assigned with some quto-generated value. Other fields, we can get the values from the link text value.

Avatar

Correct answer by
Level 8

If you have good knowledge on JS then you can customize this "link-options.js", I have done similar implementation in classic UI, but not in Touch UI. you need to put some additional effort for R&D

 

Another approach is you can write a sling model, that reads the content of the rich text editor, and inside the sling model use regex to find out anchor links and replace anchor links by adding custom attributes.

 

My preferable approach is, you are adding custom attributes for analytics tracking, I feel, on click on the anchor link you can call below function, link name you can read from the anchor link title. Link type and id either you can hardcode or you can write some logic.

 

function trackLink(link) {
if (typeof _satellite !== "undefined" && typeof digitalData !== "undefined" ) {
digitalData.page.link.name = "Privacy Policy";
digitalData.page.link.type = "LINK";
digitalData.page.link.id = "your custom id specific logic";
_satellite.track('anchorLink');
}
}

Avatar

Community Advisor

I think may be a better approach is to handle it with FE of that is possible.