aalan

Dynamically Populate Value In dataLayer

While checking about dataLayer I came across: https://www.optimizesmart.com/google-tag-manager-data-layer-explained-like-never/

Example of dataLayer

On any web page test yourself by pasting the code

1.Paste the following code

<script>

  var dataLayer = {

‘pageName’: document.title,

‘pageURL’: document.URL

                                };

</script>

You can check these in console via

  • dataLayer.PageName
  • datLayer.pageURL

2.If you paste the following:

<script>

dataLayer = [{

‘pageCategory’: ‘Statistics’,

‘visitorType’: ‘high-value’

}];

</script>

You can check these in console via

  • dataLayer[0].pageCategory
  • dataLayer[0].visitorType

3.If you paste the following :

<script>

dataLayer = [{

‘pageCategory’: ‘Statistics’,

‘visitorType’: ‘high-value’

},

{‘nameA’:’salena’,

‘nameB’:’gomes’

}];

</script>

You can check these in console via

  • dataLayer[0].pageCategory
  • dataLayer[0].visitorType
  • dataLayer[1].nameA
  • dataLayer[1].nameB

4.

5.

digitalData.page = {};

digitalData.page.pageInfo = {};

digitalData.page.pageInfo.pageName = “Electronics>Computers>MacbookPro:ProductDetails”;

6.

digitalData.page={

       pageInfo:{

             pageName:”HomePage”,

       },

       category:{

             pageType:”Home”,

             primaryCategory:”Home”,

             subCategory1:”n/a”,

             subCategory2:”n/a”

       }

}

Please let me know if you have any question by your comment in the comment section.

Related Posts

Leave a comment

You must login to add a new comment.

[wpqa_login]