Expand my Community achievements bar.

SOLVED

Adobe Data Layer Implementation

Avatar

Level 2

Hi Everybody, 

 

I have a client that implemented the dataLayer like this (See the pictures):

1) He made a dataLayer push that is going to sent the information

2) He  put this code "window.adobeDataLayer = Object.assign({}, window.dataLayer)"

 

The problem is that when i tried to use the adobeDataLayer i dont have any connection between Tags and the adobeDataLayer you now if this problem is because we use this code or it's any other thing?

 

Thanks

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Using Object.assign() like that might result in an error.

Use this instead:

// create adobeDataLayer
window.adobeDataLayer = window.adobeDataLayer || [];
// push your existing key-value dataLayer into adobeDataLayer
window.adobeDataLayer.push(window.dataLayer);
// push any other variables that you want to track into adobeDataLayer
window.adobeDataLayer.push({
  "event": "pageView",
  "page": {
    "name": "test", //conventional naming format
    "server": "test",
    "URL": "test",
  },
});

View solution in original post

2 Replies

Avatar

Employee

Hi @david_92 , 
You need to create datalayer on array format for push method to work. Instead of using "window.adobeDataLayer = Object.assign({}, window.dataLayer)" use "window.adobeDataLayer = Object.assign([], window.dataLayer);"

You can try below code on browser console:
window.adobeDataLayer = Object.assign([], window.dataLayer);
window.adobeDataLayer.push({
"event":"pageView",
"page": {
"name":"test", //conventional naming format
"server":"test",
"URL": "test",
}
});

Avatar

Correct answer by
Community Advisor

Using Object.assign() like that might result in an error.

Use this instead:

// create adobeDataLayer
window.adobeDataLayer = window.adobeDataLayer || [];
// push your existing key-value dataLayer into adobeDataLayer
window.adobeDataLayer.push(window.dataLayer);
// push any other variables that you want to track into adobeDataLayer
window.adobeDataLayer.push({
  "event": "pageView",
  "page": {
    "name": "test", //conventional naming format
    "server": "test",
    "URL": "test",
  },
});