I'm just in the process of adding my own Google Analytics to my carts. I am using the async code which needs to go in the head tag (thats no problem). What I am trying to do know is on the Order success page I want to be able to pull all the order details and products for that order from the database then pop them into the google tracking code.
Can't quite figure out the best way to go about this! Any suggestions?
Can't quite figure out the best way to go about this! Any suggestions?
In catalog/controller/checkout/success.php fetch the data before the sessions are being unset
Replace
with something like:
and then on the success.tpl located in the common folder add a check if $orderDetails and $orderProducts is set.
Note: It's not tested, just something I made awhile back, but it will eventually get you started.. Use on your own risk, and check with google for the correct syntaxes and stuff.. I can see it got updated, so you might want to create some new stuff for the .tpl file ;-)
http://code.google.com/intl/da/apis/ana ... merce.html
Replace
Code: Select all
if (isset($this->session->data['order_id'])) {
$this->cart->clear();
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['guest']);
unset($this->session->data['comment']);
unset($this->session->data['order_id']);
unset($this->session->data['coupon']);
}
Code: Select all
if (isset($this->session->data['order_id'])) {
$this->load->model('checkout/order');
$this->data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$this->data['orderProducts'] = $this->model_checkout_order->getOrderProducts($this->session->data['order_id']);
$this->cart->clear();
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
unset($this->session->data['payment_methods']);
unset($this->session->data['guest']);
unset($this->session->data['comment']);
unset($this->session->data['order_id']);
unset($this->session->data['coupon']);
}
Code: Select all
<?php if(isset($orderDetails) && isset($orderProducts)) { ?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol ) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxx-x");
pageTracker._trackPageview();
pageTracker._addTrans(
"<?php echo $orderDetails['order_id']; ?>",
"Shop Name",
"<?php echo $orderDetails['total']; ?>",
"",
"",
"<?php echo $orderDetails['name']; ?>",
"",
"country"
);
<?php foreach($orderProducts as $product) { ?>
pageTracker._addItem(
"<?php echo $product['order_id']; ?>",
"<?php echo $product['product_id']; ?>",
"<?php echo $product['name']; ?>",
"<?php echo $product['model']; ?>",
"<?php echo $product['price']+($product['price']*$product['tax']/100); ?>",
"<?php echo $product['quantity']; ?>"
);
<? } ?>
pageTracker._trackTrans();
} catch(err) {}
</script>
<?php } ?>
http://code.google.com/intl/da/apis/ana ... merce.html
Request Reviews v1.0 released.
That bit right there is exactly what I needed :-) I had got everything else in place was just that last little bit :-)Code: Select all
$this->load->model('checkout/order'); $this->data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']); $this->data['orderProducts'] = $this->model_checkout_order->getOrderProducts($this->session->data['order_id']);
Thankyou shall let you know if it works!
model_checkout_order doesn't seem to have a getOrderProducts method anymore, and the shipping total was missing as well, so i changed it to the following:rockfreak wrote:That bit right there is exactly what I needed :-) I had got everything else in place was just that last little bit :-)Code: Select all
$this->load->model('checkout/order'); $this->data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']); $this->data['orderProducts'] = $this->model_checkout_order->getOrderProducts($this->session->data['order_id']);
Thankyou shall let you know if it works!
Code: Select all
$this->load->model('account/order');
$this->data['orderDetails'] = $this->model_account_order->getOrder($this->session->data['order_id']);
$this->data['orderDetails']['shipping_total'] = $this->session->data['shipping_method']['cost'];
$this->data['orderProducts'] = $this->model_account_order->getOrderProducts($this->session->data['order_id']);
1.5+ version updated code with a bit of OP's code modifications:
1 step:
In the "controller/checkout/success.php" file add this code:Put it between the line:
and:
2 step:
In your theme's directory "template/common/success.tpl" file add this code:Put it after the line (might differ, pretty much u need "after the header" part):
Hope this stuff helps someone.
1 step:
In the "controller/checkout/success.php" file add this code:
Code: Select all
/*Data for Analytics: START*/
$this->load->model('checkout/order');
$this->data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);
foreach ($this->cart->getProducts() as $product) {
$this->data['orderProducts'][] = $product;
}
/*Data for Analytics: END*/
Code: Select all
if (isset($this->session->data['order_id'])) {
Code: Select all
$this->cart->clear();
In your theme's directory "template/common/success.tpl" file add this code:
Code: Select all
<?php if(isset($orderDetails) && isset($orderProducts)) { ?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol ) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-XXXXXXX-XX");
pageTracker._trackPageview();
pageTracker._addTrans(
"<?php echo $orderDetails['order_id']; ?>",
"ErotinesPrekes.lt",
"<?php echo $orderDetails['total']; ?>",
"0",
"0",
"<?php echo $orderDetails['shipping_city']; ?>",
"<?php echo $orderDetails['shipping_zone']; ?>",
"<?php echo $orderDetails['shipping_country']; ?>"
);
<?php foreach($orderProducts as $product) { ?>
pageTracker._addItem(
"<?php echo $orderDetails['order_id']; ?>",
"<?php echo $product['product_id']; ?>",
"<?php echo $product['name']; ?>",
"<?php echo $product['model']; ?>",
"<?php echo $product['price']+($product['price']*(isset($product['tax'])?$product['tax']:0)/100); ?>",
"<?php echo $product['quantity']; ?>"
);
<? } ?>
pageTracker._trackTrans();
} catch(err) {}
</script>
<?php } ?>
Code: Select all
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
there;s an updated vqmod version of this in the Free Extensions - vqmod section. Not sure how they differ, but you might want to check it out.
There is a great Analytics extension ($30) that adds all sorts of tracking / add to cart clicks / funnel visualization of checkout / products orders / coversion rates / etc . http://www.opencart.com/index.php?route ... on_id=4496
Increase Page Speed (#1 rated commercial extension on OpenCart Marketplace)
15in1 Essential Extensions Value Pack Premium Customer Testimonials Reward Points Extended Admin Security Lockdown Suite
irc.freenode.net #opencart
Seems the code isn't fit for OC v.1.5.4.1.
Does anyone have the solution for the last OC version?
Here is what I'm doing:
Step 1: on "catalog/controller/checkout/success.php", I tried all three listed approaches (by dbstr, ckanoab and exXXe) before the line:
Step 2: on "template/common/success.tpl", when trying to print the variables values just for testing, something like:
I get the following error:
Cheers!
Does anyone have the solution for the last OC version?
Here is what I'm doing:
Step 1: on "catalog/controller/checkout/success.php", I tried all three listed approaches (by dbstr, ckanoab and exXXe) before the line:
Code: Select all
$this->cart->clear();
Code: Select all
<?php echo $orderDetails['order_id']; ?>
Can anyone give us a hand?Undefined variable: orderDetails in <b>/home/.../template/common/success.tpl</b> on line <b>24</b>
Cheers!
WIP Design Publicidade e Marketing Digital
I had the same error !!Ed_Rolla wrote:I get the following error:Code: Select all
<?php echo $orderDetails['order_id']; ?>
Can anyone give us a hand?Undefined variable: orderDetails in <b>/home/.../template/common/success.tpl</b> on line <b>24</b>
Cheers!
Did you resolve it?
Hi,ertygi wrote:I had the same error !!Ed_Rolla wrote:I get the following error:Code: Select all
<?php echo $orderDetails['order_id']; ?>
Can anyone give us a hand?Undefined variable: orderDetails in <b>/home/.../template/common/success.tpl</b> on line <b>24</b>
Cheers!
Did you resolve it?
Was there any solution to the above error?
Thanks,
Mike
Who is online
Users browsing this forum: No registered users and 68 guests