Google Affiliate Integration

Google Affiliate Integration
January 11th, 2011
copy and paste to the bottom of
app/design/frontend/base/default/theme_name/template/checkout/success.phtml
<!–Start Google Affiliate Integration–>
<?php
$companyID = “H456842″; #provided by Google
$category = urlencode(“Your product category”);
$lastorderid = Mage::getSingleton(‘checkout/session’)->getLastOrderId();
$_order = Mage::getModel(‘sales/order’)->load($lastorderid);
$orderID = $this->getOrderId(); #get the order ID
$aProduct = array();
$totalAmt = 0;
$prdsku = “”;
$prdnm = “”;
$prdqn = “”;
$prdpr = “”;
$prcatid = “”;
###########store order data in array of objects###########
foreach ($_order->getAllItems() as $item) {
$oProduct = new stdClass();
$oProduct->sku = $item->getSku(); #sku
$oProduct->price = $item->getPrice(); #price
$totalAmt = $totalAmt + ($oProduct->price * $item->getQtyOrdered()); #total amt (excl.tax/shipping)
$oProduct->qty = $item->getQtyOrdered(); #quantity
$oProduct->name = $item->getName(); #product name
$oProduct->category = $item->getProductId(); #ProductCatID
array_push($aProduct, $oProduct);
$oProduct = NULL; #nuke it
}
###########build query string variables###########
for ($i=0; $i < count($aProduct); $i++) {
if ($i == count($aProduct)-1) {
$prdsku .= urlencode($aProduct[$i]->sku);
$prdnm .= urlencode($aProduct[$i]->name);
$prdqn .= urlencode($aProduct[$i]->qty);
$prdpr .= urlencode($aProduct[$i]->price);
$prcatid .= urlencode($aProduct[$i]->category);
} else {
$prdsku .= urlencode($aProduct[$i]->sku) . “^”;
$prdnm .= urlencode($aProduct[$i]->name) . “^”;
$prdqn .= urlencode($aProduct[$i]->qty) . “^”;
$prdpr .= urlencode($aProduct[$i]->price) . “^”;
$prcatid .= urlencode($aProduct[$i]->category) .”^”;
}
}
?>
<img src=”https://gan.doubleclick.net/gan_conversion?advid=H456842&event_type=transaction&oid=<?=$orderID?>&amt=<?=urlencode($totalAmt)?>&prdsku=<?=$prdsku?>&prdqn=<?=$prdqn?>&prdpr=<?=$prdpr?>&prdcatid=<?=$prcatid?>&clickid=47999f0b3143dac1f2f35ff096c6b” width=”1″ height=”1″ style=”border:0px solid #F00;”>
<!–End Google Affiliate Integration–>
<!–Start Google Affiliate Integration–><?php$companyID = “H456842″; #provided by Google$category = urlencode(“Your product category”);$lastorderid = Mage::getSingleton(‘checkout/session’)->getLastOrderId();$_order = Mage::getModel(‘sales/order’)->load($lastorderid);$orderID = $this->getOrderId(); #get the order ID$aProduct = array();$totalAmt = 0;$prdsku = “”;$prdnm = “”;$prdqn = “”;$prdpr = “”;$prcatid = “”;
###########store order data in array of objects###########foreach ($_order->getAllItems() as $item) { $oProduct = new stdClass(); $oProduct->sku = $item->getSku(); #sku $oProduct->price = $item->getPrice(); #price $totalAmt = $totalAmt + ($oProduct->price * $item->getQtyOrdered()); #total amt (excl.tax/shipping) $oProduct->qty = $item->getQtyOrdered(); #quantity $oProduct->name = $item->getName(); #product name $oProduct->category = $item->getProductId(); #ProductCatID array_push($aProduct, $oProduct); $oProduct = NULL; #nuke it}###########build query string variables###########for ($i=0; $i < count($aProduct); $i++) { if ($i == count($aProduct)-1) { $prdsku .= urlencode($aProduct[$i]->sku); $prdnm .= urlencode($aProduct[$i]->name); $prdqn .= urlencode($aProduct[$i]->qty); $prdpr .= urlencode($aProduct[$i]->price); $prcatid .= urlencode($aProduct[$i]->category); } else { $prdsku .= urlencode($aProduct[$i]->sku) . “^”; $prdnm .= urlencode($aProduct[$i]->name) . “^”; $prdqn .= urlencode($aProduct[$i]->qty) . “^”; $prdpr .= urlencode($aProduct[$i]->price) . “^”; $prcatid .= urlencode($aProduct[$i]->category) .”^”; }}?>
<img src=”https://gan.doubleclick.net/gan_conversion?advid=H456842&event_type=transaction&oid=<?=$orderID?>&amt=<?=urlencode($totalAmt)?>&prdsku=<?=$prdsku?>&prdqn=<?=$prdqn?>&prdpr=<?=$prdpr?>&prdcatid=<?=$prcatid?>&clickid=47999f0b3143dac1f2f35ff096c6b” width=”1″ height=”1″ style=”border:0px solid #F00;”>
<!–End Google Affiliate Integration–>