Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Reproducing Magento Google Analytics GA.php into header
 
darrells
Jr. Member
 
Total Posts:  7
Joined:  2008-09-22
 

Im trying to take the class and functions in the built in GoogleAnalytics and put it in the header and use pieces of it when and where I want. Because I am doing things with the new multiple custom variables and asynchronous GA.

app\code\local\Mage\GoogleAnalytics\Block\GA.php

Need Google Analytics in header.
Need to customize GA script output however I want.
Maintain whatever it is doing to detect a checkout and generate the GA javascript for that.

So far I managed to take my own GA javascript and do this line into my footer template instead of within the php class in GA.php:

pageTracker._trackPageview("<?php echo Mage::getSingleton('core/url')->escape($_SERVER['REQUEST_URI']) ?>");

Now Im trying to reproduce the functions just as functions alone and not within class.

Original:

class Mage_GoogleAnalytics_Block_Ga extends Mage_Core_Block_Text
{
    
/**
     * Retrieve Quote Data HTML
     *
     * @return string
     */
    
public function getQuoteOrdersHtml()
    
{
        $quote 
$this->getQuote();
        if (!
$quote{
            
return '';
        
}

        
if ($quote instanceof Mage_Sales_Model_Quote{
            $quoteId 
$quote->getId();
        
else {
            $quoteId 
$quote;
        
}

        
if (!$quoteId{
            
return '';
        
}

        $orders 
Mage::getResourceModel('sales/order_collection')
            ->
addAttributeToFilter('quote_id'$quoteId)
            ->
load();

        
$html '';
        foreach (
$orders as $order{
            $html 
.= $this->setOrder($order)->getOrderHtml();
        
}

        
return $html;
    
}

...........etc

My changes…

function getQuoteOrdersHtml()
    
{
        $quote 
Mage::getSingleton('checkout/session')->getQuote();
        if (!
$quote{
            
return '';
        
}

        
if ($quote instanceof Mage::Mage_Sales_Model_Quote{
            $quoteId 
$quote->getId();
        
else {
            $quoteId 
$quote;
        
}

        
if (!$quoteId{
            
return '';
        
}

        $orders 
Mage::getResourceModel('sales/order_collection')
            ->
addAttributeToFilter('quote_id'$quoteId)
            ->
load();

        
$html '';
        foreach (
$orders as $order{
            $html 
.= $this->setOrder($order)->getOrderHtml();
        
}

        
return $html;
    
}

Am I on the right track. Notice how I added Mage:: I’m not sure if that is right. What about the last line $html .= $this->setOrder($order)->getOrderHtml(); since I’m not extending the class anymore?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top