Author Topic: Google Analytics  (Read 35250 times)

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #15 on: October 22, 2012, 10:02:09 AM »
Those lines exist between lines 10 and 12 of the extension generator created code.

Inserting a
Code: [Select]
die() in to the core/strikehawk_ganalytics.php file does cause the script to die.

So, the issue is somewhere else.

David

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Google Analytics
« Reply #16 on: October 25, 2012, 06:16:26 PM »
try this
Code: [Select]
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

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #17 on: November 03, 2012, 10:01:40 AM »
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:

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

Code: [Select]
$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


Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #18 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:

Code: [Select]
    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:

Code: [Select]
    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:

Code: [Select]
$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

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Google Analytics
« Reply #19 on: November 04, 2012, 05:26:08 PM »
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:

Code: [Select]
    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:

Code: [Select]
    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:

Code: [Select]
$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
Code: [Select]
$this->baseObject->loadModel('checkout/order'); or
Code: [Select]
$registry->get('load')->model('checkout/order');before getOrder call.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #20 on: November 04, 2012, 06:44:48 PM »
It appears that
Code: [Select]
$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

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #21 on: November 05, 2012, 07:00:22 AM »
One thing I am noticing is that I have products reappearing in the cart after I log in to complete the next checkout...


Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Google Analytics
« Reply #22 on: November 05, 2012, 09:48:26 AM »
You don't clear session data after checkout.
 
Look into file storefront/controller/pages/checkout/success.php

Code: [Select]
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

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #23 on: November 06, 2012, 08:41:05 AM »
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

Offline FG

  • Newbie
  • *
  • Posts: 27
  • Karma: +5/-0
    • View Profile
Re: Google Analytics
« Reply #24 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)?  :)

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #25 on: February 20, 2013, 03:16:41 AM »
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

Offline sowerswebtech

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Google Analytics
« Reply #26 on: November 04, 2015, 01:36:28 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

Offline Basara

  • Administrator
  • Hero Member
  • *****
  • Posts: 5774
  • Karma: +274/-2
    • View Profile
Re: Google Analytics
« Reply #27 on: November 05, 2015, 01:22:54 AM »
Thank you, sowerswebtech

 

Powered by SMFPacks Social Login Mod