Harish
Harish

Reputation: 23

How to test and implement data layer in Google Tag Manager for Google Analytics

We are using enhanced eCommerce tracking by using data layer, to setup and test it in local environment. We can see page views in analytics but the event and impressions are not triggered. I tried using this:

dataLayer.push({ 
    'ecommerce': { 'Impression': [ { 'name': '${product.name}' ,'id': '${product.code}' }]}

});

dataLayer.push({
     'ecommerce': 
     { 'detail': 
        {    'products': 
                    [{ 
                        'name':  '${product.name}',  
                        'id': '${product.code}',
                        'variant': '${product.style}' 
                    }]
        } 
    } 
});

But I don't know how to test in local. I have tested using Google tag manager Debug mode, but it shows datalayer has been pushed but I can't track that event in Google Analytics

Upvotes: 1

Views: 6312

Answers (3)

Harish
Harish

Reputation: 23

In localhost used to check tracking by Google Tag Assistant

https://chrome.google.com/webstore/detail/tag-assistant-by-google/kejbdjndbnbjgmefkgdddjlbokphdefk

I think it is best way to check datalayer

Upvotes: 0

legowife
legowife

Reputation: 41

I have recently implemented this for a client and found that omnibug (for firefox or chome) and google real-time reports were the best combination for testing once we'd set everything up.

I pretty much went by the book having my developer setup the datalayer (very important that this be above the GTM tag in your code!) and setting up the various macros, rules, and tags myself in GTM according to this documentation (different from your link): https://developers.google.com/tag-manager/enhanced-ecommerce It's easy to miss the collapsed tag manager configuration steps on that page. I know I did.

If you've implemented all of the GTM settings, then most of the enhanced ecommerce stuff should show up in omnibug when you initiate any of the actions that should trigger those events.

The piece we had the most difficult time with was product impressions as our product listing pages are ajax driven.

I also found Simo Hava's blog post on this very helpful! http://www.simoahava.com/analytics/ecommerce-tips-google-tag-manager/


Note: For the record with our setup we use a separate container for production and development environments which is what enables us to publish and test out with omnibug. I find Simo's GTM Tools very useful for this too so I can just copy over select tags, macros, and rules: http://www.simoahava.com/analytics/introducing-gtm-tools/

Good luck!

Upvotes: 0

nyuen
nyuen

Reputation: 8907

At least for the impressions, it looks like you are not using the correct parameter name (you have "Impression", but it should be "impressions"). Impressions should be measured as such, taken from this guide, https://developers.google.com/tag-manager/enhanced-ecommerce:

// Product impressions are sent by pushing an impressions object
// containing one or more impressionFieldObjects.
dataLayer.push({
  'ecommerce': {
    'currencyCode': 'EUR',                       // Local currency is optional.
    'impressions': [
     {
       'name': 'Triblend Android T-Shirt',       // Name or ID is required.
       'id': '12345',
       'price': '15.25',
       'brand': 'Google',
       'category': 'Apparel',
       'variant': 'Gray',
       'list': 'Search Results',
       'position': 1
     }]
  }
});

Upvotes: 0

Related Questions