google-analyticsenhanced-ecommerce

Send enhanced ecommerce data


When i land on the confirmation page i run the following code.

var purchaseObject = {
  'id': $OrderID,
  'revenue': $total,
  'shipping': $deliverycost
};
if (couponCode.length) {
  purchaseObject['coupon'] = couponCode;
}
ga('ec:setAction', 'purchase', purchaseObject);
ga('ec:send');

Both sends generates error messages.

Plugin "ec" does not have method "send".

and

Error calling a plugin method: {0: "ec:send"}

I have added

ga('require', 'ec');

in the head and the other events works so i don't get why the send does not work.


Solution

  • EEC does not have a send method, you set the action with the E-Commerce-Data and this is send along with the next pageview (or other interaction). See the example from the Google documentation:

    // Transaction level information is provided via an actionFieldObject.
    ga('ec:setAction', 'purchase', {
      'id': 'T12345',
      'affiliation': 'Google Store - Online',
      'revenue': '37.39',
      'tax': '2.85',
      'shipping': '5.34',
      'coupon': 'SUMMER2013'    // User added a coupon at checkout.
    });
    
    ga('send', 'pageview');     // Send transaction data with initial pageview.
    

    Notice the last comment - transaction is sent with the pageview. If you do not want another pageview, use an event.