Add data-cmp-data-layer-enabled attribute to body element | Community
Skip to main content
February 8, 2023
Solved

Add data-cmp-data-layer-enabled attribute to body element

  • February 8, 2023
  • 1 reply
  • 1866 views

Hi all,

I need to add data-cmp-data-layer-enabled attribute to body element.

I follow the tutorial which creates /conf/<mySite>/sling:configs/com.adobe.cq.wcm.core.components.internal.DataLayerConfig.

And set the enabled property, added sling:configRef property under my site

 

However, I still couldn't see the attribute data-cmp-data-layer-enabled in body.

there's a thread with a reply suggested adding some javascript code on page.html, but I don't get what exactly should I do next.

 

Do you guys have any ideas about this?

I'm using aem 6.5.5 with com.adobe.granite.archetypes version 20

 

Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by lukasz-m

Hi @yusheng,

The root cause off the issue is connect with core components version. Please be aware that data-cmp-data-layer-enabled attribute appears in page.html renderer has been exposed in core components 2.9.0. OOTB archetype version 20 provide 2.5.0 core components version. Here is the difference in the code:

As you can see 2.9.0 not only adds data-cmp-data-layer-enabled attribute but also additional section with JS code.

Summarizing, what you have to do to get it work, you should upgrade core components version to 2.9.0 or higher. I do not think you should do any changes in page.html, as it will not be so simple, because changes in page.html will require some changes on Sling models level as well to provide proper information that can be consumed on the page.html.

As an alternative solution you can generate project once again using never archetype version (24+)

1 reply

lukasz-m
Community Advisor
lukasz-mCommunity AdvisorAccepted solution
Community Advisor
February 10, 2023

Hi @yusheng,

The root cause off the issue is connect with core components version. Please be aware that data-cmp-data-layer-enabled attribute appears in page.html renderer has been exposed in core components 2.9.0. OOTB archetype version 20 provide 2.5.0 core components version. Here is the difference in the code:

As you can see 2.9.0 not only adds data-cmp-data-layer-enabled attribute but also additional section with JS code.

Summarizing, what you have to do to get it work, you should upgrade core components version to 2.9.0 or higher. I do not think you should do any changes in page.html, as it will not be so simple, because changes in page.html will require some changes on Sling models level as well to provide proper information that can be consumed on the page.html.

As an alternative solution you can generate project once again using never archetype version (24+)

YuShengAuthor
February 13, 2023

Thank you @lukasz-m 
I updated the archetype to latest (40) and the issue solved.