Mage_GoogleAnalytics_Block_Ga Class Reference

Inheritance diagram for Mage_GoogleAnalytics_Block_Ga:

Mage_Core_Block_Text Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 getQuoteOrdersHtml ()
 getOrderHtml ()
 getAccount ()
 getPageName ()

Protected Member Functions

 _toHtml ()


Detailed Description

Definition at line 35 of file Ga.php.


Member Function Documentation

_toHtml (  )  [protected]

Prepare and return block's html output

Returns:
string

Reimplemented from Mage_Core_Block_Text.

Definition at line 164 of file Ga.php.

00165     {
00166         if (!Mage::getStoreConfigFlag('google/analytics/active')) {
00167             return '';
00168         }
00169 
00170         $this->addText('
00171 <!-- BEGIN GOOGLE ANALYTICS CODE -->
00172 <script type="text/javascript">
00173 //<![CDATA[
00174 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
00175 document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
00176 //]]>
00177 </script>
00178 <script type="text/javascript">
00179 //<![CDATA[
00180 var pageTracker = _gat._getTracker("' . $this->getAccount() . '");
00181 pageTracker._trackPageview("'.$this->getPageName().'");
00182 //]]>
00183 </script>
00184 <!-- END GOOGLE ANALYTICS CODE -->
00185         ');
00186 
00187         $this->addText($this->getQuoteOrdersHtml());
00188 
00189         if ($this->getGoogleCheckout()) {
00190             $protocol = Mage::app()->getStore()->isCurrentlySecure() ? 'https' : 'http';
00191             $this->addText('<script src="'.$protocol.'://checkout.google.com/files/digital/ga_post.js" type="text/javascript"></script>');
00192         }
00193 
00194         return parent::_toHtml();
00195     }

getAccount (  ) 

Retrieve Google Account Identifier

Returns:
string

Definition at line 134 of file Ga.php.

00135     {
00136         if (!$this->hasData('account')) {
00137             $this->setAccount(Mage::getStoreConfig('google/analytics/account'));
00138         }
00139         return $this->getData('account');
00140     }

getOrderHtml (  ) 

Retrieve Order Data HTML

Returns:
string

Definition at line 76 of file Ga.php.

00077     {
00078 
00079         $order = $this->getOrder();
00080         if (!$order) {
00081             return '';
00082         }
00083 
00084         if (!$order instanceof Mage_Sales_Model_Order) {
00085             $order = Mage::getModel('sales/order')->load($order);
00086         }
00087 
00088         if (!$order) {
00089             return '';
00090         }
00091 
00092         $address = $order->getBillingAddress();
00093 
00094         $html  = '<script type="text/javascript">' . "\n";
00095         $html .= "//<![CDATA[\n";
00096         $html .= 'pageTracker._addTrans(';
00097         $html .= '"' . $order->getIncrementId() . '",';
00098         $html .= '"' . $order->getAffiliation() . '",';
00099         $html .= '"' . $order->getBaseGrandTotal() . '",';
00100         $html .= '"' . $order->getBaseTaxAmount() . '",';
00101         $html .= '"' . $order->getBaseShippingAmount() . '",';
00102         $html .= '"' . $this->jsQuoteEscape($address->getCity(), '"') . '",';
00103         $html .= '"' . $this->jsQuoteEscape($address->getRegion(), '"') . '",';
00104         $html .= '"' . $this->jsQuoteEscape($address->getCountry(), '"') . '"';
00105         $html .= ');' . "\n";
00106 
00107         foreach ($order->getAllItems() as $item) {
00108             if ($item->getParentItemId()) {
00109                 continue;
00110             }
00111 
00112             $html .= 'pageTracker._addItem(';
00113             $html .= '"' . $order->getIncrementId() . '",';
00114             $html .= '"' . $this->jsQuoteEscape($item->getSku(), '"') . '",';
00115             $html .= '"' . $this->jsQuoteEscape($item->getName(), '"') . '",';
00116             $html .= '"' . $item->getCategory() . '",';
00117             $html .= '"' . $item->getBasePrice() . '",';
00118             $html .= '"' . $item->getQtyOrdered() . '"';
00119             $html .= ');' . "\n";
00120         }
00121 
00122         $html .= 'pageTracker._trackTrans();' . "\n";
00123         $html .= '//]]>';
00124         $html .= '</script>';
00125 
00126         return $html;
00127     }

getPageName (  ) 

Retrieve current page URL

Returns:
string

Definition at line 147 of file Ga.php.

00148     {
00149         if (!$this->hasData('page_name')) {
00150             //$queryStr = '';
00151             //if ($this->getRequest() && $this->getRequest()->getQuery()) {
00152             //    $queryStr = '?' . http_build_query($this->getRequest()->getQuery());
00153             //}
00154             $this->setPageName(Mage::getSingleton('core/url')->escape($_SERVER['REQUEST_URI']));
00155         }
00156         return $this->getData('page_name');
00157     }

getQuoteOrdersHtml (  ) 

Retrieve Quote Data HTML

Returns:
string

Definition at line 42 of file Ga.php.

00043     {
00044         $quote = $this->getQuote();
00045         if (!$quote) {
00046             return '';
00047         }
00048 
00049         if ($quote instanceof Mage_Sales_Model_Quote) {
00050             $quoteId = $quote->getId();
00051         } else {
00052             $quoteId = $quote;
00053         }
00054 
00055         if (!$quoteId) {
00056             return '';
00057         }
00058 
00059         $orders = Mage::getResourceModel('sales/order_collection')
00060             ->addAttributeToFilter('quote_id', $quoteId)
00061             ->load();
00062 
00063         $html = '';
00064         foreach ($orders as $order) {
00065             $html .= $this->setOrder($order)->getOrderHtml();
00066         }
00067 
00068         return $html;
00069     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:13 2009 for Magento by  doxygen 1.5.8