From Whirlwind eCommerce Wiki
Jump to: navigation, search


eV::googleTrackTrans($orderData) returns javascript Google code for use with google eCommerce Analytics tracking. Place in the final page of checkout (fa=ORDER.checkoutComplete). The returned string MUST be displayed FOLLOWING displaying the googleTrack code!


$string = eC::googleTrackTrans($orderArray);


  • $orderArray ARRAY
Array of order data as returned by orderGetCompleteArray

Return Values

Returns a string of Javascript code, as defined by Google, for use with the eCommerce tracking component of Google Analytics. The returned code includes the bounding <script> and </script> tags. An example of the returned code is below:

<script type="text/javascript">
	"123456",   // Order ID
	"",         // Affiliation
	"526.24",   // Total
	"25.26",    // Tax
	"10.56",    // Shipping
	"Bethesda", // City
	"MD",       // State
	"USA"       // Country

	"123456",                  // Order ID
	"ProdSKU12",               // SKU
	"Widget Twelve",           // Product Name 
	"Widget can do things!",   // Category
	"10.00",                   // Price
	"5"                        // Quantity
	"123457",                  // Order ID
	"ProdSKU13",               // SKU
	"Widget Thirteen",         // Product Name 
	"Widget can do more things!",   // Category
	"25.00",                   // Price
	"15"                        // Quantity


echo "<html>";
echo "<head>";
echo "<title>$metaTitle</title>";
echo "</head>";
echo "<body>";
echo $copy;
// display googleTrack code
// this MUST be displayed BEFORE calling eV::googleTrackTrans()
echo eV::googleTrack('UA-1234567-1');
// only display googleTrackTrans if in the final page of checkout
if($attributes['fa'] == 'ORDER.checkoutComplete'){
  // $attributes['orderNumber'] will always be passed into fa ORDER.checkoutComplete
  // we must resolve the orderNumber to the orderId to get the order array:
  $orderId = eV::orderGetIdFromNumber($attributes['orderNumber']);
  // now get the order array
  $orderArray = eV::orderGetCompleteArray($orderId);
  // pass the orderArray to googleTrackTrans: 
  echo eV::googleTrackTrans($orderArray);
// end if fa=ORDER.checkoutComplete
echo "</body>";
echo "</html>";

See Also