Expand my Community achievements bar.

Join us for the next Community Q&A Coffee Break on Tuesday April 23, 2024 with Eric Matisoff, Principal Evangelist, Analytics & Data Science, who will join us to discuss all the big news and announcements from Summit 2024!
SOLVED

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

Avatar

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

Avatar

Correct answer by
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

Avatar

Correct answer by
Level 7

@ZombieLor Can you try executing the below in console ?

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

Avatar

Level 1
Uncaught TypeError: Cannot read property 'pageInfo' of undefined at <anonymous>:1:41

Avatar

Level 1
VM5719:1 Uncaught TypeError: Cannot read property 'pageInfo' of undefined at <anonymous>:1:41

Avatar

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.

Avatar

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.

Avatar

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