Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save peteeveleigh/94523eac6cd0876b799cd88aba252f93 to your computer and use it in GitHub Desktop.

Select an option

Save peteeveleigh/94523eac6cd0876b799cd88aba252f93 to your computer and use it in GitHub Desktop.

Revisions

  1. peteeveleigh created this gist May 9, 2016.
    27 changes: 27 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    ga('require', 'ecommerce'); // Load the ecommerce plug-in.

    ga('ecommerce:addTransaction', {
    'id': '{order_id}', // Transaction ID. Required
    'affiliation': '{site_name}', // Affiliation or store name
    'revenue': '{exp:cartthrob:view_formatted_number number="{order_total}" prefix="" decimals="2" dec_point="." thousands_sep="" }', // Sub Total
    'shipping': '{exp:cartthrob:view_formatted_number number="{order_shipping}" prefix="" decimals="2" dec_point="." thousands_sep="" }', // Shipping
    'tax': '{exp:cartthrob:view_formatted_number number="{order_tax}" prefix="" decimals="2" dec_point="." thousands_sep="" }' // Tax
    });

    // add item might be called for every item in the shopping cart
    // where your ecommerce engine loops through each item in the cart and
    // prints out _addItem for each

    // this is a loop that goes through each item in the order
    {exp:cartthrob:order_items order_id="{order_id}"}
    ga('ecommerce:addItem', {
    'id': '{item:order_id}', // Transaction ID. Required
    'name': '{item:title}', // Product name. Required
    'sku': '{item:entry_id}', // SKU/code
    'category': '', // Category or variation
    'price': '{item:price_numeric}', // Unit price
    'quantity': '{item:quantity}' // Quantity
    });
    {/exp:cartthrob:order_items}

    ga('ecommerce:send'); // Send transaction and item data to Google Analytics.