0
votes

I'm implementing Enhanced eCommerce for the first time. I want to use it to track content consumption. I'm trying to make this implementation step-by-step.

I've some scroll event fired on my website (scroll 25%,scroll 50%,etc...). I want to use them to trigger and feed each funnel step.

I wrote the following custom HTML tag :

ga('create', 'UA-XXXXXXX-1');
//we have already 10 custom dimensions
ga('set', 'dimension11', 'eehit');

ga('require','ec');

ga('ec:addProduct', {
  'id':{{Post_id}},
  'typeArticle':{{m_EC_typeArticle}},
  'timeSpent':{{m_EC_timeSpent}}

});


ga('ec:setAction','checkout', {
   'step':{{m_EC_is_scroll_event}}
});

//add option - checkout_option 

ga('send', 'event', 'Checkout', 'Option', {
   hitCallback: function() {
      // advance to next page
   }
});

When looking at GA debugger I have two mistake :

  • Waiting on require of "ec" to be fulfilled.
  • Ignoring create request for duplicate tracking name.

so I have two questions :

  • How should I send data to a specific UA with a custom HTML tag ?
  • How should I initiate the EC plugins ?

I guess I also have other mistake in my code. I'm learning so I hope that all this will make sense.

1

1 Answers

1
votes

Rather than use the ga calls in a Custom HTML Tag, use the in-built Tag options for universal analytics (Page View and Events). Configure them for Enhanced Ecommerce and use the dataLayer to pass your product (content) information via a Custom HTML.

You can use the checkout step dataLayer structure, passing your variables as needed and use this checkout event to trigger the Universal Analytics Tag.

<script>(function(){
if(typeof window.dataLayer != 'undefined') {
    dataLayer.push({
        'event': 'checkout',
        'ecommerce': {
            'checkout': {
                'actionField': {'step': {{m_EC_is_scroll_event}}, 'option': undefined},
                'products': [{
                    //'name': '',
                    'id': {{Post_id}},
                    'dimension12' : {{m_EC_typeArticle}}, // Product Scope Custom Dimension
                    'dimension13' : {{m_EC_timeSpent}} // Product Scope Custom Dimension
                    //'price': '00.00',
                    //'brand': '',
                    //'category': '',
                    //'variant': '',
                    //'quantity': 1

                }]
            }
        },
        'eventCallback': function() {
            // advance to next page
        }
    });
}
})();</script>

If you are adding additional data to the product i.e typeArticle, these need to be added as Product scoped Custom Dimensions. The format for Enhanced Ecomemrce requires them to be written in the dimensionXX form.

Simo Ahava put together a post on using Enhanced Ecommerce to track content with Google Tag Manager: https://www.simoahava.com/analytics/track-content-enhanced-ecommerce/, worth a read.