Mapping dataLayer array to Data Elements | Community
Skip to main content
New Participant
October 16, 2023
Solved

Mapping dataLayer array to Data Elements

  • October 16, 2023
  • 1 reply
  • 1492 views

I have the following dataLayer array set in the <head> of my HTML page and I have the Adobe Launch script set after it. However when I try to pull the values via Data Element's JavaScript Variable it doesn't work. I tried putting both dataLayer[0].variable1 and dataLayer.variable1 into the "JavaScript variable name" field but both don't work. Does Launch not support dataLayers that are set as an array or is there something I'm missing in the Data Elements set up?

 

<head>

<script>
dataLayer = [{
'variable1': 'value-of-variable-1',
'variable2': 'value-of-variable-2',
'variable3': 'value-of-variable-3'
}];
</script>

<script src="<adobe launch.js" async></script>

</head>

 

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 mattcheng1

I was able to figure this out. Since the dataLayer is implemented as an array, the Javascript Variable data element needs to be dataLayer.0.[dataLayer element]

1 reply

New Participant
October 16, 2023

To map your data elements, you would pick up the individual data elements as  a 'javascript variable' and the javascript variable name would be window.dataLayer.variable1

New Participant
October 16, 2023

This didn't work for me since my dataLayer is set as an array vs as an object. 

 

I did use the Analytics contextData Tools extension and it returned the variables as context variables in the following format:

  • 0.variable1 = "value-of-variable-1"
  • 0.variable2 = "value-of-variable-2"
  • 0.variable3 = "value-of-variable-3"

This works for me for now, but wondering if there's a more optimized way of doing this. Thanks!

mattcheng1AuthorAccepted solution
New Participant
October 16, 2023

I was able to figure this out. Since the dataLayer is implemented as an array, the Javascript Variable data element needs to be dataLayer.0.[dataLayer element]