Post by MagicFire » Mon Sep 17, 2012 9:22 pm

Hi,
I have slightly problem here. I've searched this forum and have foung some topics about this problem. First of all I don't want use any of the commercial modules. It's not the way of learning new things for me.

I would like to add the e-commerce tracking on eshop. After some searching I found this solution:
In controler/checkout/success.php

Code: Select all

if (isset($this->session->data['order_id'])) {			
/*Data for Analytics: START*/
$this->load->model('checkout/order');
$this->data['DetailObjednavka'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);
foreach ($this->cart->getProducts() as $product) {
      $this->data['objednavkaProdukty'][] = $product;   
/*Data for Analytics: END*/
$this->session->data['tracking_order'] = $this->session->data['order_id'];
$this->cart->clear();
First thing... variables used later for GA isn't set. The only option is to put them outside the "if" condition, but this is not a good idea. And even if I put them ouside, only the $DetailObjednavka is set. Am I using the wrong function getProducts() ?
Second.... this is working only for the unregistered user. Where should I put this so it work for the registred user (I guess somewhere else or here should be also loaded different model, f.e. model_account_order)?

adn finally in the template/common/success.tpl ( I changed the names like UA code and name of shop, not a mistake)

Code: Select all

<?php if(isset($DetailObjednavka)&& isset($objednavkaProdukty)) { echo "Funguje";?>
<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-XXXXXXXX-X");
  pageTracker._trackPageview();
  pageTracker._addTrans(
      '<?php echo $DetailObjednavka['order_id']; ?>',
      'Name Of the shop',
      '<?php echo $DetailObjednavka['total']; ?>',
      '0',
      '0',
      '<?php echo $DetailObjednavka['shipping_city']; ?>',
      '<?php echo $DetailObjednavka['shipping_zone']; ?>',
      '<?php echo $DetailObjednavka['shipping_country']; ?>'
    );
  <?php foreach($objednavkaProdukty as $product) { ?>
       pageTracker._addItem(
          '<?php echo $DetailObjednavka['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 } ?>
Where is the catch?

Thanks

Newbie

Posts

Joined
Thu Sep 13, 2012 7:38 am

Post by i2Paq » Mon Sep 17, 2012 11:18 pm

eshop is a fork to work with Wordpress.

We only support OpenCart.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by MagicFire » Tue Sep 18, 2012 1:01 am

What does it have to do with WP? It's a question of OpenCart system. Or maybe I misslead you. It's the OpenCart system. Not www page with eshop.

Newbie

Posts

Joined
Thu Sep 13, 2012 7:38 am

Post by justinv » Tue Sep 18, 2012 5:50 am

That code seems to look ok. The if statement will only execute if you go to that page after purchasing a product, if you go directly to the checkout/success page it will not work. The other thing is that if your users purchase something with an external payment gateway and it doesn't redirect them back to that page, then they will not be tracked.

But what you have done there is fairly similar to the way HostJars ecommerce tracking module works. You are on the right track.

Documentation: OpenCart User Guide
Mods: Total Import PRO | CSV Import PRO | Ecom Tracking | Any Feed | Autosuggest | OpenCart CDN
Image


Active Member

Posts

Joined
Tue Oct 12, 2010 1:24 pm

Post by MagicFire » Tue Sep 18, 2012 6:15 am

Thanks man, I appreciate your help. So there is only one thing. Why the varible $objednavkaProdukty , which should contains all ordered products isn't set. Because all I got is the javascript for _addTrans, but not a single _addItem (if I remove the $objednavkyProdukty from the if statement). I look for some code in the system and it's similiar to the code, how the cart takes care of showing up choosen item. Isn't there som hiddn step, that will clear the cart? Or unset something? But I guess that the order and success are two steps that go consecutively.

Newbie

Posts

Joined
Thu Sep 13, 2012 7:38 am
Who is online

Users browsing this forum: No registered users and 33 guests