0
Welcome Guest! Login
0 items Join Now

Gantry: Google analytics code outdated

  • Gantry: Google analytics code outdated

    Posted 14 years 9 months ago
    • It should use the new asynchronous tracking code that is inserted before the </head> tag.

      Key benefits of doing this would be:

      Faster tracking code load times for your web pages due to improved browser execution

      Enhanced data collection & accuracy

      Elimination of tracking errors from dependencies when the JavaScript hasn't fully loaded
    • Last Edit: 14 years 9 months ago by Joomla_Dave.
  • Re: Gantry: Google analytics code outdated

    Posted 14 years 9 months ago
  • Re: Gantry: Google analytics code outdated

    Posted 14 years 9 months ago
    • Actually the BigShot plugin is outdated as well ;-) There is already a better/new plugin in the JED (which I have installed already ...).

      My point actually is that Rockettheme should use the latest tracking code, if they offer this kind of functionality in Gantry ...
  • Re: Gantry: Google analytics code outdated

    Posted 14 years 8 months ago
    • Joomla_Dave --

      Which plug-in are you using? I have read that JoomlaGATor! is supposed to be nice, but is there a better one? And what is the best way to use this and not conflict with whatever Gantry has available?
  • Re: Gantry: Google analytics code outdated

    Posted 14 years 8 months ago
    • Just search for "asynchronous google" in the JED.

      But my hope is that Rockettheme would update their code. It would take only minutes for them and we could get rid of one more plugin :-)
    • Last Edit: 14 years 8 months ago by Joomla_Dave.
    • Rich Bean's Avatar
    • Rich Bean
    • Elite Rocketeer
    • Posts: 1194
    • Thanks: 1

    Re: Gantry: Google analytics code outdated

    Posted 14 years 8 months ago
    • Rich Bean's Avatar
    • Rich Bean
    • Elite Rocketeer
    • Posts: 1194
    • Thanks: 1

    Re: Gantry: Google analytics code outdated

    Posted 14 years 8 months ago
    • Maybe someone a bit better with php than I can firgure this out:

      Here's the code from Gantry that has the analytics feature:
      /**
       * @package     gantry
       * @subpackage  features
       */
      class GantryFeatureAnalytics extends GantryFeature {
       
          var $_feature_name = 'analytics';
          
          function render($position="") {
       
              ob_start();
              // start of Google Analytics javascript
              ?>
      <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("<?php echo $this->get('code'); ?>");
      pageTracker._trackPageview();
      } catch(err) {}</script>
              <?php
              // end of Google Analytics javascript
              return ob_get_clean();
          }
      }
      As you can see this is the old tracking code. Here's the newer one:
      <script type="text/javascript">
       
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'UA-XXXXX-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>

      So the question is...how to update?
    • My Sites:
      Perth Website Design
      Scuba Marketing
      I'm a Henning Stalker!
    • Andy Miller's Avatar
    • Andy Miller
    • Preeminent Rocketeer
    • Posts: 9919
    • Thanks: 96
    • Web Kahuna

    Re: Gantry: Google analytics code outdated

    Posted 14 years 8 months ago
    • There will be an update in the next version of Gantry, in the meantime, you can just create a file in your template/features/ folder called analytics.php, and copy this code into that file:
      <?php
      /**
       * @package      gantry
       * @subpackage  features
       * @version      ${project.version} ${build_date}
       * @author       RocketTheme http://www.rockettheme.com
       * @copyright   Copyright (C) 2007 - ${copyright_year} RocketTheme, LLC
       * @license      http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
       *
       * Gantry uses the Joomla Framework (http://www.joomla.org), a GNU/GPLv2 content management system
       *
       */
       
      defined('JPATH_BASE') or die();
       
      gantry_import('core.gantryfeature');
       
      /**
       * @package      gantry
       * @subpackage  features
       */
      class GantryFeatureAnalytics extends GantryFeature {
       
           var $_feature_name = 'analytics';
           
           function init() {
                global $gantry;
       
                ob_start();
                // start of Google Analytics javascript
                ?>
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', '<?php echo $this->get('code'); ?>']);
        _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);
        })();
                <?php
                // end of Google Analytics javascript
                $gantry->addInlineScript(ob_get_clean());
           }
      }

      With the power of Gantry, it will use your new updated Analytics feature rather than the bundled gantry one. BTW, this is the code that's going into the next rev of Gantry so if you find any problems with it, let me know. Cheers.
    • Rich Bean's Avatar
    • Rich Bean
    • Elite Rocketeer
    • Posts: 1194
    • Thanks: 1

    Re: Gantry: Google analytics code outdated

    Posted 14 years 8 months ago

Time to create page: 0.068 seconds