Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Using Launch to populate data elements from an AEM data layer.

ZombieLor
Level 1
Level 1

I have an issue in Launch accessing the AEM data layer. The some of the data elements are not being populated. Here's the DL object:

Annotation 2021-07-01 094617.jpg

I added pageName to a data element and pageTemplateName to another one, but they are not being populated.  I tried a "direct" approach:

   return window.adeptDataLayer.getState().page.pageInfo.pageName;

I got this error message:

   Cannot read property 'pageName' of undefined TypeError: Cannot read property 'pageName' of undefined

I tried various ways to convert the object to text but it didn't solve the problem. Currently the s.pageName variable is populated by this other data element but it's pulling the wrong object:

var tx = adeptDataLayer.getState().page;

   for (var key1 in tx){

      var myPage="";

      myPage=tx[key1]["dc:title"];

    }

return myPage;

 

I tried changing the "dc:title" element to "pageName" but that also gave me the type error.

What should I try?

1 Accepted Solution
amgup
Correct answer by
Level 7
Level 7

@ZombieLor Can you try executing the below in console ?

window.adeptDataLayer.getState().page[1].pageInfo.pageName

View solution in original post

6 Replies
amgup
Correct answer by
Level 7
Level 7

@ZombieLor Can you try executing the below in console ?

window.adeptDataLayer.getState().page[1].pageInfo.pageName

View solution in original post

ZombieLor
Level 1
Level 1
Uncaught TypeError: Cannot read property 'pageInfo' of undefined at <anonymous>:1:41
ZombieLor
Level 1
Level 1
VM5719:1 Uncaught TypeError: Cannot read property 'pageInfo' of undefined at <anonymous>:1:41
ZombieLor
Level 1
Level 1
If I set the rule to firee on Window load, the data elements are populated. It was originally set on DOM loaded. I tried the code here https://experienceleague.adobe.com/docs/experience-manager-learn/sites/integrations/analytics/collec.... The site is done in AEM the dataLayer is created there. Window load solved this one problem and has created others I have to go stomp out.
yuhuisg
Community Advisor
Community Advisor

By "AEM data layer", I assume that you're referring to the Adobe Client Data Layer.

Since you're using Adobe Launch, you can install the Adobe Client Data Layer extension to help you with your operations. In your case, you'll want to create a data element based on the data layer's computed state.

By the way, if this is really the Adobe Client Data Layer, you're advised to keep the data layer's name as "adobeDataLayer". Changing it can cause things to break.

ZombieLor
Level 1
Level 1
I specifically am avoiding the extension specifically because of the data layer name limitation.