How do you implement Google Analytics conversion tracking in Gambio to record purchases? Basically, it is quite simple:
Step 1) We assemble the data for Google Analytics and then write it to the output buffer using a class extension. We implement this class extension using an overload in the folder
\user_classes\overloads\CheckoutSuccessExtenderComponent\
for example, using the name econcessGoogleAnalytics.inc.php. In this file, we first retrieve the order data:
$orders_total_query = xtc_db_query("select * from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int) $this->v_data_array['orders_id'] . "'");$orders_products_query = xtc_db_query("select * from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int) $this->v_data_array['orders_id'] . "'");
The results are then incorporated using ga('ecommerce:addTransaction',... and ga('ecommerce:addItem',..., as described very well, among other places, at https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce. In short:
First, initialize Ecommerce tracking with
ga('require', 'ecommerce');
Then add the transaction with
ga('ecommerce:addTransaction', {'id': '1234', // Transaction ID. Required.'affiliation': 'Acme Clothing', // Affiliation or store name.'revenue': '11.99', // Grand Total.'shipping': '5', // Shipping.'tax': '1.29' // Tax.});
Then add the products with
ga('ecommerce:addItem', {'id': '1234', // Transaction ID. Required.'name': 'Fluffy Pink Bunnies', // Product name. Required.'sku': 'DD23444', // SKU/code.'category': 'Party Toys', // Category or variation.'price': '11.99', // Unit price.'quantity': '1' // Quantity.});
Then send it:
ga('ecommerce:send');
All that remains is to put the assembled JavaScript code into the output buffer, for example with
$this->v_output_buffer['google_analytics_conversion_tracking']
and then proceed to Step 2.
Step 2) In our template folder, we now access the intermediate buffer, preferably in the template file
\templates\TEMPLATENAME\module\checkout_success.html
using the Smarty logic:
{$google_analytics_conversion_tracking}
Done!
