Expand my Community achievements bar.

Help shape the future of AI assistance by participating in this quick card sorting activity. Your input will help create a more effective system that better serves your needs and those of your colleagues.
SOLVED

Mapping dataLayer array to Data Elements

Avatar

Level 2

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>

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

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]

View solution in original post

3 Replies

Avatar

Level 2

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

Avatar

Level 2

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!

Avatar

Correct answer by
Level 2

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]