javascriptgoogle-analyticsgoogle-tag-manageruniversal-analyticsdata-layer

Product scoped dimensions in Google Analytics and Google Tag Manager


I need to pass my product scoped custom dimension throught Google Tag Manager into Google Analytics. I am able to read just first variable in my array of objects of products. And no custom dimension is showing at all (even this first value of all of them) in my Analytics.

I have set custom dimension in Analytics as product scoped: enter image description here

Then in GTM I seted up custom dimension in my tag. enter image description here

In dimension value I used variable which goes into structure and find variable productSize.

enter image description here

And here is my code:

<script>
    dataLayer.push({
      'event': 'productImpression',
      'ecommerce': {
        'impressions': [
         {
           'name': 'Android tričko',
           'id': '12345',
           'price': '299',
           'brand': 'Google',
           'category': 'Pánská trička',
           'variant': 'bílá',
           'list': 'Search Results',
           'productSize': 'L',          // product scoped custom dimension
           'position': 1            
         },
         {
           'name': 'Donut Friday Scented T-Shirt',
           'id': '67890',
           'price': '33.75',
           'brand': 'Google',
           'category': 'Apparel',
           'variant': 'Black',
           'list': 'Search Results',
           'productSize': 'XL',         // product scoped custom dimension
           'position': 2
         }]
      }
    });
</script>

As I said the problem is I can read only the first value (obviously) of my custom dimension ("L"). What should I write instead of zero symbol in variable dot notation to get all of the values ("L", "XL")?

I need to pass all values about every products into Analytics. Do I have to I push every product in separate dataLayer.push()? Where is the problem that I don't see anything at all in Analytics? Please help.


Solution

  • You cannot use the name you've given to the dimension via the interface. You'd have to use the "dimension" keyword plus the numeric index (order of creation), so the dimension that is referred to as "productSize" in the reports would in your example be addressed as "dimension1" in the code:

    ...
    'list': 'Search Results',
    'dimension1': 'L',          // product scoped custom dimension
    'position': 1       
    ...
    

    After that GA will pick your dimensions automatically from the datalayer.