简体   繁体   中英

Google Analytics not tracking conversions in Magento 1.7

I'm using Magento's built in Googleanalytics module which is working fine for page views, but not for conversions. The account is set up fine on Google, but it's not adding the addTrans part in the checkout/onepage/success page.

I've done a lot of digging this morning, and found that the observer does observe the "checkout_onepage_controller_success_action" correctly, and does indeed run. It does the following:

$block = Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('google_analytics');
    if ($block) {
        $block->setOrderIds($orderIds);
    }

I've done some echoing, and it does retrieve the block, and it also sets the order ids correctly. However, in the block itself, if I echo out $this->getOrderIds(); its empty.

My next thought was that perhaps it could be using two GA blocks on the page, and maybe its passing the data to the first one but echoing the HTML of the 2nd one, but I've no clue how to start checking that! The Googleanalytics.xml file only has one block it in, and I don't use that block name anywhere else!

Anyone experienced similar? Or have any idea where I can go from here?

EDIT: The Ga.php block includes the transaction code if $this->getOrderIds() returns an array, which it is not doing. However, the observer is doing $block->setOrderIds($order_ids); which is passing through an array containing an order id. So the observer is passing the ids to the block, and the block is receiving them (setting up a method of setBlockIds and echoing out the argument, does show the array), but when the block tries to access its own data, it's suddenly not there ($block->getData() returns an array of properties but there is no order_ids property).

I also figured maybe it could be that its echoing the blocks HTML before setting the order id, so I added some variables in to check that and it's not that - its definitely setting the order_ids before trying to get them again, but its still not working!

I'm completely stumped! My only idea now is to modify the Ga.php block to use Magento's registry instead of it's own _data property, which is really not a nice way of doing it!

I think i've been an utter tool. Magento wasn't tracking conversions on the live site because I hadn't put the account code in the configuration part, but I had on my test site.

I had previously put my own analytics code in the template, so I had tracked page views.

When I saw no conversions (despite putting the account code in my test site), I started making orders on the test site and then viewing the source of the order success page. Firefox loads its source as a new request...which automatically goes to the empty basket page. So obviously, it wasn't showing the addTrans or anything, because it had already done that.

A quick check in firebug revealled it was working as it should.

So in the end, after a day of searching, I had to change "No" to "Yes" in the admin, and type in the account code. Great.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM