Author Topic: Google Analytics  (Read 35235 times)

Offline Shenhav

  • Newbie
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Google Analytics
« 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

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4358
  • Karma: +298/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: Google Analytics
« Reply #1 on: September 06, 2012, 08:14:15 AM »
If you need add generic code (show on all pages) into storefront head you can do this 2 ways.

1. Add code to TPL file /storefront/view/default/template/common/head.tpl
This whole file is pulled into <head></head>

2. You can include child block or just code into controller /storefront/controller/common/head.php
This can be done by adding (concatenating) to variable $head

If you need to add some script or CSS to head in some specific page only, you can use addScript or addStyle in that page controller.
These methods will append your script or CSS to the head on on that page.
Example:
Code: [Select]
$this->document->addScript(RDIR_TEMPLATE . 'javascript/jqgrid/js/jquery.jqGrid.min.js');
Code: [Select]
           $this->document->addStyle(array(
                'href' => $this->view->templateResource('/javascript/jquery/star-rating/jquery.rating.css'),
                'rel' => 'stylesheet',
                'media' => 'screen',
            ));

Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #2 on: September 10, 2012, 10:48:11 AM »
I'm a bit more concerned with how to add ecommerce transaction tracking code.   Any pointers there?  Ideal outcome would be template agnostic, as it is obviously desirable to have tracking work in all themes...

David

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4358
  • Karma: +298/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: Google Analytics
« Reply #3 on: September 10, 2012, 09:37:24 PM »
Solution #2 was for controller, so it is multi-template solution and will work on any template.
Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #4 on: September 11, 2012, 12:31:14 PM »
Both of those seem to presume you're just importing a file which contains the Javascript.  Doesn't seem to address the need to compose portions of the script on the fly....

David

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #5 on: September 11, 2012, 03:15:27 PM »
Hmm.  Seems I've discussed this before - need to split that script and get part of it into global foot...

David

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #6 on: September 12, 2012, 10:24:59 AM »
Indeed, I have.  See this post on asynchronous scripts

David
« Last Edit: September 15, 2012, 11:52:11 AM by Nimitz1061 »

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #7 on: September 12, 2012, 12:22:24 PM »
More specifically to Google Analytics implementation, GA requires the insertion of 2 OR MORE basic script elements.  All pages should have a  top script element, which includes some basic setup information such as the GA Web Property ID, and some configuration values for account usage (Cross Domain tracking, that sort of thing), and a bottom script element, which pulls the analytics javascript file from Google and executes the actual data insertion.

In between may be one or more "pushes".  This must include at least one on the checkout success page in order to achieve full ecommerce transaction tracking.   So, at least 3 script insertions must be done in order to get adequate tracking in place. 

One possible barrier to getting this done will be the checkout success page - which seems to immediately clear any existing order data......

David

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #8 on: October 04, 2012, 08:42:14 AM »
As the checkout success page is not changed in the 1.1.0 release, it would appear that the data needed to accurately emit transactional data remains missing from that page.

This does need to be addressed, quickly, and in the core code.

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 #9 on: October 05, 2012, 07:19:42 AM »
You need hook storefront/controller/pages/checkout/confirm.php
Something like this:
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);
$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 ;
}

Also look inside your confirm.tpl and check where do you plan place your hook-var. If you makes your own template you can create your own hookvar with any name and then assign value in hook.
As you see i used hookvar "payment_pre" of our default template in example above.
“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 #10 on: October 05, 2012, 10:00:47 AM »
Abolabo,

This looks more promising.  I'm concerned about the activity taking place on the confirm action, and using a payment_pre hook.

The whole idea of the tracking is to catch successful orders for which payment has been received.  This looks to me to be happening in the confirmation page, and before the transaction is complete.

Is this the case?

Oh, and from where can I hook this?

I've been trying to encode this from extensions/strikehawk_ganalytics/core  but that does not seem to work.

Thanks,

David

« Last Edit: October 05, 2012, 10:09:51 AM by Nimitz1061 »

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4358
  • Karma: +298/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: Google Analytics
« Reply #11 on: October 05, 2012, 02:25:11 PM »
If you need to hook after the order is created and the transaction is complete you need to hook similar way to ControllerPagesCheckoutSuccess  controller.  This one is call after order is all complete.

You put it into your extension core file class  extensions/strikehawk_ganalytics/core/strikehawk_ganalytics.php

class ExtensionStrikehawk_ganalytics extends Extension {
   
....

Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #12 on: October 21, 2012, 09:14:44 AM »
I'm under the impression that ControllerPagesCheckoutSuccess only knows that checkout is complete because it has been called. (routed to, whatever).

Are you telling me that the :

Code: [Select]
if (isset($this->session->data['order_id'])) {

conditional is a check for order completion ??

David

Offline Nimitz1061

  • Full Member
  • ***
  • Posts: 190
  • Karma: +22/-0
  • No matter where you go, there you are...
    • View Profile
Re: Google Analytics
« Reply #13 on: October 21, 2012, 11:28:47 AM »
Ok, I put :

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);
$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 ;
}

in extensions/strikehawk_ganalytics/core/strikehawk_ganalytics.php file as:

Code: [Select]
class StrikehawkGanalyticsStrikehawkGanalytics extends Extension {
public function __construct(){
  $this->registry = Registry::getInstance();
}

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);
$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 ;
}



Placed:
Code: [Select]
<?php echo $this->getHookVar('payment_pre'); ?>in:

storefront/view/default/template/pages/checkout/confirm.php

Nothing appearing.  Adding text above the getHookVar call does result in that text showing up on the page, so I think I have the right template for this purpose.  (Still would rather this comes out on checkout success, but at this point am just trying to get something to display in a catalog page...)

Now, should note I have no controllers or models setup for this extension. 

« Last Edit: October 21, 2012, 11:30:53 AM by Nimitz1061 »

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 #14 on: October 22, 2012, 05:43:11 AM »
Ok, I put :

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);
$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 ;
}

in extensions/strikehawk_ganalytics/core/strikehawk_ganalytics.php file as:

Code: [Select]
class StrikehawkGanalyticsStrikehawkGanalytics extends Extension {
public function __construct(){
  $this->registry = Registry::getInstance();
}

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);
$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 ;
}



Placed:
Code: [Select]
<?php echo $this->getHookVar('payment_pre'); ?>in:

storefront/view/default/template/pages/checkout/confirm.php

Nothing appearing.  Adding text above the getHookVar call does result in that text showing up on the page, so I think I have the right template for this purpose.  (Still would rather this comes out on checkout success, but at this point am just trying to get something to display in a catalog page...)

Now, should note I have no controllers or models setup for this extension.
Hello.
1. code works 100%. i tested.
2. check is your core/strikehawk_ganalytics.php file included in main.php. Open main.php of your extension, there are have to be something like this
Code: [Select]
if(!class_exists('StrikehawkGanalyticsStrikehawkGanalytics')){
include('core/strikehawk_ganalytics.php');
}
3. check is file run via var_dump('bla-bla-bla'); If not - check status of extension.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

 

Powered by SMFPacks Social Login Mod