Difference between revisions of "Functions:googleTrackTrans"

From Whirlwind eCommerce Wiki
Jump to: navigation, search
(New page: == Description == eV::googleTrackTrans($orderData) returns javascript Google code for use with google eCommerce Analytics tracking. Place in the final page of checkout (fa=ORDER.checkoutCo...)
 
(Examples)
 
Line 58: Line 58:
  
 
// display googleTrack code
 
// display googleTrack code
 +
// this MUST be displayed BEFORE calling eV::googleTrackTrans()
 
echo eV::googleTrack('UA-1234567-1');
 
echo eV::googleTrack('UA-1234567-1');
  
Line 63: Line 64:
 
if($attributes['fa'] == 'ORDER.checkoutComplete'){
 
if($attributes['fa'] == 'ORDER.checkoutComplete'){
  
// $attributes['orderNumber'] will always be passed into 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:
+
  // we must resolve the orderNumber to the orderId to get the order array:
$orderId = eV::orderGetIdFromNumber($attributes['orderNumber']);
+
  $orderId = eV::orderGetIdFromNumber($attributes['orderNumber']);
  
// now get the order array
+
  // now get the order array
$orderArray = eV::orderGetCompleteArray($orderId);
+
  $orderArray = eV::orderGetCompleteArray($orderId);
  
// pass the orderArray to googleTrackTrans:  
+
  // pass the orderArray to googleTrackTrans:  
echo eV::googleTrackTrans($orderArray);
+
  echo eV::googleTrackTrans($orderArray);
 +
// end if fa=ORDER.checkoutComplete
 
};
 
};
  
Line 78: Line 80:
  
 
</source>
 
</source>
 
  
 
== See Also ==
 
== See Also ==
 
:*[[Functions:googleTrack|googleTrack]]
 
:*[[Functions:googleTrack|googleTrack]]

Latest revision as of 14:41, 29 May 2009

Description

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!

Syntax

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

Paramaters

  • $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">
  pageTracker._addTrans(
	"123456",   // Order ID
	"",         // Affiliation
	"526.24",   // Total
	"25.26",    // Tax
	"10.56",    // Shipping
	"Bethesda", // City
	"MD",       // State
	"USA"       // Country
  );

  pageTracker._addItem(
	"123456",                  // Order ID
	"ProdSKU12",               // SKU
	"Widget Twelve",           // Product Name 
	"Widget can do things!",   // Category
	"10.00",                   // Price
	"5"                        // Quantity
  );
  pageTracker._addItem(
	"123457",                  // Order ID
	"ProdSKU13",               // SKU
	"Widget Thirteen",         // Product Name 
	"Widget can do more things!",   // Category
	"25.00",                   // Price
	"15"                        // Quantity
  );
  pageTracker._trackTrans();
</script>

Examples

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