Latest Google Analytics Code

Details of modifications which users can incorporate within Enuuk Auction Platform free of charge
Post Reply
RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Latest Google Analytics Code

Post by RWAP » Fri Oct 19, 2012 7:07 pm

Google Analytics now prefer asynchronous code for their javascript.

You can implement this by changing class\Core\PresentationData,php

Find:

Code: Select all

    static public function getGoogleAnalyticsCode(Core_Context $context)
    {
        $gaCode = '<script type="text/javascript">
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
        </script>
        <script type="text/javascript">
        try {
        var pageTracker = _gat._getTracker("UA-xxxxxxx-x");
        pageTracker._trackPageview();
        } catch(err) {}</script>';
        if(String::checkGoogleAnalytics($context->siteOptions['googleAnalyticsID'])){
            return str_replace('UA-xxxxxxx-x', $context->siteOptions['googleAnalyticsID'], $gaCode);
        }else{
            return '';
        }
    }
Change this to:

Code: Select all

    static public function getGoogleAnalyticsCode(Core_Context $context)
    {
		$gaCode = '<script type="text/javascript">
		      var _gaq = _gaq || [];
		_gaq.push(["_setAccount", "UA-xxxxxxx-x"]);
		_gaq.push(["_trackPageview"]);

		(function() {
		  var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
		  ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
		  var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);
		})();</script>';
        if(String::checkGoogleAnalytics($context->siteOptions['googleAnalyticsID'])){
            return str_replace('UA-xxxxxxx-x', $context->siteOptions['googleAnalyticsID'], $gaCode);
        }else{
            return '';
        }
    }
You will also need to remove the following line from themes\default\footer.php

Code: Select all

<?=$data['googleAnalyticsCode']?>
and then in themes\default\header.php, find:

Code: Select all

    <script type="text/javascript" src="<?=$relativePath?>themes/<?=$theme?>/js/global.js"></script>
and change this to:

Code: Select all

    <script type="text/javascript" src="<?=$relativePath?>themes/<?=$theme?>/js/global.js"></script>
    <?=$data['googleAnalyticsCode']?>

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Latest Google Analytics Code

Post by RWAP » Sun Jul 28, 2013 7:17 pm

Enuuk have now incorporated the latest Google Analytics code in the main system

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest