News:

AbanteCart v1.4.2 is released.

Main Menu

Do you like AbanteCart? Please rate AbanteCart or share your experience with other eCommerce entrepreneurs. Go to Softaculous rating page to add your rating or write a review

Google Analytics

Started by Shenhav, September 05, 2012, 09:15:31 PM

Previous topic - Next topic

Nimitz1061

Those lines exist between lines 10 and 12 of the extension generator created code.

Inserting a die() in to the core/strikehawk_ganalytics.php file does cause the script to die.

So, the issue is somewhere else.

David

abolabo

try this
class ExtensionStrikehawkGanalytics extends Extension {

    public function onControllerPagesCheckoutConfirm_UpdateData() {
        $registry = Registry::getInstance();
        $order_id = $registry->get('session')->data['order_id'];
        $order_info = $registry->get('model_checkout_order')->getOrder($order_id);
        $webpropertyid = $this->baseObject->get('config')->get('strikehawk_ganalytics_webpropertyid');
        $script_html = "Place Some html Here, for ex: <script> alert('Order Total: " . $order_info['total'] . "')</script>";
        $this->baseObject->view->addHookVar('payment_pre', $script_html);
        return;
    }

    public function onControllerCommonHead_UpdateData() {
        $registry = Registry::getInstance();
        $registry->get('document')->addScript($this->baseObject->view->templateResource('/javascript/global_scripts/myscript.js'));

        $this->baseObject->view->addHookVar('another_var_name', 'Confirmation Massage');
    }
}
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

Nimitz1061

abolabo

That last example worked, after I changed the include call in the main.php file to match the class name - to the extent that the confirmation message now appears on the screen.

That left a PHP error on the config value call - which I managed to resolve using another example in the documentation.  More specifically, I changed from:

$webpropertyid = $this->baseObject->get('config')->get('strikehawk_ganalytics_webpropertyid');
to:

$webpropertyid = $this->registry->get('config')->get('strikehawk_ganalytics_webpropertyid');

Implementing a similar method for the footer controller with an additional hook var display in the footer.tpl file also worked.

At the moment, I am now able to generate the script markup for the head and foot, and am now working on the transaction script output.

This is a very nice piece of progress, which I could not have done without your help.

Thanks!

David


Nimitz1061

I'm now working on generating transactional data on the checkout SUCCESS page.

This location is important.  I've mentioned a number of times throughout this process that analytic software should only report success after the confirmation is received and the payment processed.

I'm currently using:

    public function onControllerPagesCheckoutSuccess_InitData() {
        $registry = Registry::getInstance();
        $script_html = 'SCRIPT TAG';
        if (isset($this->session->data['order_id'])) {
        $order_id = $registry->get('session')->data['order_id'];
        $order_info = $registry->get('model_checkout_order')->getOrder($order_id);
        $webpropertyid = $this->baseObject->get('config')->get('strikehawk_ganalytics_webpropertyid');
        $script_html = "Place Some html Here, for ex: <script> alert('Order Total: " . $order_info['total'] . "')</script>";
        }
        $this->baseObject->view->addHookVar('payment_analytics', $script_html);
        return;
    }


as opposed to the suggested:

    public function onControllerPagesCheckoutConfirm_UpdateData() {
        $registry = Registry::getInstance();
        $order_id = $registry->get('session')->data['order_id'];
        $order_info = $registry->get('model_checkout_order')->getOrder($order_id);
        $webpropertyid = $this->baseObject->get('config')->get('strikehawk_ganalytics_webpropertyid');
        $script_html = "Place Some html Here, for ex: <script> alert('Order Total: " . $order_info['total'] . "')</script>";
        $this->baseObject->view->addHookVar('payment_analytics', $script_html);
        return;
    }


In either case, I'm getting an error similar to this:

Fatal error: Call to a member function getOrder() on a non-object in extensions/strikehawk_ganalytics/core/strikehawk_ganalytics.php on line 27

which refers to the line:

$order_info = $registry->get('model_checkout_order')->getOrder($order_id);


My diagnostic code (echoing the $order_id variable) indicates that I do have a valid order ID in the session.  So, it appears that this is not the correct way to invoke the checkout order model...

David

abolabo

Quote from: Nimitz1061 on November 04, 2012, 10:13:55 AM
I'm now working on generating transactional data on the checkout SUCCESS page.

This location is important.  I've mentioned a number of times throughout this process that analytic software should only report success after the confirmation is received and the payment processed.

I'm currently using:

    public function onControllerPagesCheckoutSuccess_InitData() {
        $registry = Registry::getInstance();
        $script_html = 'SCRIPT TAG';
        if (isset($this->session->data['order_id'])) {
        $order_id = $registry->get('session')->data['order_id'];
        $order_info = $registry->get('model_checkout_order')->getOrder($order_id);
        $webpropertyid = $this->baseObject->get('config')->get('strikehawk_ganalytics_webpropertyid');
        $script_html = "Place Some html Here, for ex: <script> alert('Order Total: " . $order_info['total'] . "')</script>";
        }
        $this->baseObject->view->addHookVar('payment_analytics', $script_html);
        return;
    }


as opposed to the suggested:

    public function onControllerPagesCheckoutConfirm_UpdateData() {
        $registry = Registry::getInstance();
        $order_id = $registry->get('session')->data['order_id'];
        $order_info = $registry->get('model_checkout_order')->getOrder($order_id);
        $webpropertyid = $this->baseObject->get('config')->get('strikehawk_ganalytics_webpropertyid');
        $script_html = "Place Some html Here, for ex: <script> alert('Order Total: " . $order_info['total'] . "')</script>";
        $this->baseObject->view->addHookVar('payment_analytics', $script_html);
        return;
    }


In either case, I'm getting an error similar to this:

Fatal error: Call to a member function getOrder() on a non-object in extensions/strikehawk_ganalytics/core/strikehawk_ganalytics.php on line 27

which refers to the line:

$order_info = $registry->get('model_checkout_order')->getOrder($order_id);


My diagnostic code (echoing the $order_id variable) indicates that I do have a valid order ID in the session.  So, it appears that this is not the correct way to invoke the checkout order model...

David
hi.
i think you doing right. (i mean hook on success page)
about error.
i guess cause is model_checkout_order var. Try to paste
$this->baseObject->loadModel('checkout/order');
or
$registry->get('load')->model('checkout/order');
before getOrder call.
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

Nimitz1061

It appears that $this->baseObject->loadModel('checkout/order'); works.  Not sure why, as the baseObject type calls have been failing earlier..

Now to look at how to obtain itemized product data....

Thanks!

David

Nimitz1061

One thing I am noticing is that I have products reappearing in the cart after I log in to complete the next checkout...


abolabo

You don't clear session data after checkout.

Look into file storefront/controller/pages/checkout/success.php

class ControllerPagesCheckoutSuccess extends AController {
public function main() {

        //init controller data
        $this->extensions->hk_InitData($this,__FUNCTION__);

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']);
}
   

"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

Nimitz1061

Thanks,  I'll check there.

Odd thing is, now that I have logged out once, it appears to have stopped happening...

Now working on accessing various elements of the order and cart....

David

FG

This seems to be a lot of work to get Google Analytics on your site.  In other shopping carts you just paste your Google Analytics code in to a box and press save - is this going to be a feature in future release (please)?  :)

Nimitz1061

Quote from: FG on February 17, 2013, 12:38:28 PM
This seems to be a lot of work to get Google Analytics on your site.  In other shopping carts you just paste your Google Analytics code in to a box and press save - is this going to be a feature in future release (please)?  :)


Actually, getting Google Analytics to "work" on your site is just that easy in ANY shopping cart, including this one.  If you are willing to accept a low enough value of "works".

I  (and most of my clients) expect a bit more than just counting clicks and generating some page statistics.  This is after all, an eCommerce application - so ecommerce tracking should be the minimum standard.  That takes more work on every cart I've seen.

Another factor is that not everyone chooses Google Analytics to track their site performance and behaviors.   Our clients also use Piwik, Channel Advisor and other tracking systems.  So, what the cart should have, as standard, is an analytics framework.  Which is what I've been working towards.   

David

sowerswebtech

Quote from: Shenhav on September 05, 2012, 09:15:31 PM
Hi All,

I want to add google analytics to my website, I need to paste google code before the closing </head> tag on every page.
Where can I find it.

Thanks

I found this great tutorial on how to get Google Analytics easily installed within your installation of AbanteCart. SUPER easy.
fastcomet.com/tutorials/abantecart/google-analytics

Basara


Forum Rules Code of conduct
AbanteCart.com 2010 -