Plugin Directory

Changeset 179567


Ignore:
Timestamp:
12/04/2009 07:06:36 AM (16 years ago)
Author:
cavemonkey50
Message:

Switches current tracking script (ga.js) to the new awesome async tracking script.

Location:
google-analyticator/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • google-analyticator/trunk/external-tracking.js

    r126750 r179567  
    2424            a.click(function() {
    2525                if ( analyticsEventTracking == 'enabled' ) {
    26                     pageTracker._trackEvent("Downloads", extension.toUpperCase(), href);
     26                    _gaq.push(['_trackEvent', 'Downloads', extension.toUpperCase(), href]);
    2727                } else
    28                     pageTracker._trackPageview(analyticsDownloadsPrefix + url);
     28                    _gaq.push(['_trackPageview', analyticsDownloadsPrefix + url]);
    2929            });
    3030        }
     
    3535            a.click(function() {
    3636                if ( analyticsEventTracking == 'enabled' ) {
    37                     pageTracker._trackEvent("Outbound Traffic", href.match(/:\/\/(.[^/]+)/)[1], href);
     37                    _gaq.push(['_trackEvent', 'Outbound Traffic', href.match(/:\/\/(.[^/]+)/)[1], href]);
    3838                } else
    39                     pageTracker._trackPageview(analyticsOutboundPrefix + url);
     39                    _gaq.push(['_trackPageview', analyticsOutboundPrefix + url]);
    4040            });
    4141        }
  • google-analyticator/trunk/external-tracking.min.js

    r126750 r179567  
    11jQuery(document).ready(function(){jQuery('a').each(function(){var a=jQuery(this);var href=a.attr('href');if(href==undefined)
    2 return;var url=href.replace('http://','').replace('https://','');var hrefArray=href.split('.').reverse();var extension=hrefArray[0].toLowerCase();var hrefArray=href.split('/').reverse();var domain=hrefArray[2];var downloadTracked=false;if(jQuery.inArray(extension,analyticsFileTypes)!=-1){downloadTracked=true;a.click(function(){if(analyticsEventTracking=='enabled'){pageTracker._trackEvent("Downloads",extension.toUpperCase(),href);}else
    3 pageTracker._trackPageview(analyticsDownloadsPrefix+url);});}
    4 if((href.match(/^http/))&&(!href.match(document.domain))&&(downloadTracked==false)){a.click(function(){if(analyticsEventTracking=='enabled'){pageTracker._trackEvent("Outbound Traffic",href.match(/:\/\/(.[^/]+)/)[1],href);}else
    5 pageTracker._trackPageview(analyticsOutboundPrefix+url);});}});});
     2return;var url=href.replace('http://','').replace('https://','');var hrefArray=href.split('.').reverse();var extension=hrefArray[0].toLowerCase();var hrefArray=href.split('/').reverse();var domain=hrefArray[2];var downloadTracked=false;if(jQuery.inArray(extension,analyticsFileTypes)!=-1){downloadTracked=true;a.click(function(){if(analyticsEventTracking=='enabled'){_gaq.push(['_trackEvent','Downloads',extension.toUpperCase(),href]);}else
     3_gaq.push(['_trackPageview',analyticsDownloadsPrefix+url]);});}
     4if((href.match(/^http/))&&(!href.match(document.domain))&&(downloadTracked==false)){a.click(function(){if(analyticsEventTracking=='enabled'){_gaq.push(['_trackEvent','Outbound Traffic',href.match(/:\/\/(.[^/]+)/)[1],href]);}else
     5_gaq.push(['_trackPageview',analyticsOutboundPrefix+url]);});}});});
  • google-analyticator/trunk/google-analyticator.php

    r179537 r179567  
    118118}
    119119
    120 // Initialize outbound link tracking
     120# Add the core Google Analytics script, with a high priority to ensure last script for async tracking
     121add_action('wp_head', 'add_google_analytics', 999999);
     122
     123# Initialize outbound link tracking
    121124add_action('init', 'ga_outgoing_links');
    122125
     
    819822}
    820823
    821 // Add the script
    822 $ga_in_footer = false;
    823 if (get_option(key_ga_footer) == ga_enabled) {
    824     $ga_in_footer = true;
    825     add_action('wp_head', 'add_ga_adsense');
    826     add_action('wp_footer', 'add_google_analytics');
    827 } else {
    828     add_action('wp_head', 'add_google_analytics');
    829 }
    830 
    831824/**
    832  * Adds the Analytics Adsense tracking code to the header if the main Analytics tracking code is in the footer.
    833  * Idea and code for Adsense tracking with main code in footer props William Charles Nickerson on May 16, 2009.
     825 * Echos out the core Analytics tracking code
    834826 **/
    835 function add_ga_adsense() {
    836     $uid = stripslashes(get_option(key_ga_uid));
    837     // If GA is enabled and has a valid key
    838     if (  (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
    839         // Display page tracking if user is not an admin
    840         if ( ( get_option(key_ga_admin) == ga_enabled || !current_user_can('level_' . get_option(key_ga_admin_level)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' ) {
    841             if ( get_option(key_ga_adsense) != '' ) {
    842                 echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://plugins.spiralwebconsulting.com/analyticator.html -->\n";
    843                 echo '  <script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n\n";
    844             }
    845         }
    846     }
    847 }
    848 
    849 // The guts of the Google Analytics script
    850 function add_google_analytics() {
    851     global $ga_in_footer;
    852    
     827function add_google_analytics()
     828{
     829    # Fetch variables used in the tracking code
    853830    $uid = stripslashes(get_option(key_ga_uid));
    854831    $extra = stripslashes(get_option(key_ga_extra));
     
    856833    $extensions = str_replace (",", "|", get_option(key_ga_downloads));
    857834   
    858     // If GA is enabled and has a valid key
    859     if (  (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
    860        
    861         // Display page tracking if user is not an admin
    862         if ( ( get_option(key_ga_admin) == ga_enabled || !current_user_can('level_' . get_option(key_ga_admin_level)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' ) {
    863        
    864             echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://plugins.spiralwebconsulting.com/analyticator.html -->\n";
    865             # Google Adsense data if enabled
    866             if ( get_option(key_ga_adsense) != '' && !$ga_in_footer )
    867                 echo '  <script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n\n";
    868            
    869             // Pick the HTTP connection
    870             if ( get_option(key_ga_specify_http) == 'http' ) {
    871                 echo "  <script type=\"text/javascript\" src=\"http://www.google-analytics.com/ga.js\"></script>\n\n";
    872             } elseif ( get_option(key_ga_specify_http) == 'https' ) {
    873                 echo "  <script type=\"text/javascript\" src=\"https://ssl.google-analytics.com/ga.js\"></script>\n\n";
    874             } else {
    875                 echo "  <script type=\"text/javascript\">\n";
    876                 echo "      var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n";
    877                 echo "      document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n";
    878                 echo "  </script>\n\n";
    879             }
    880        
    881             echo "  <script type=\"text/javascript\">\n";
    882             echo "  try {\n";
    883             echo "      var pageTracker = _gat._getTracker(\"$uid\");\n";
    884        
    885             // Insert extra before tracker code
     835    # Determine if the GA is enabled and contains a valid UID
     836    if ( ( get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
     837    {
     838        # Determine if the user is an admin, and should see the tracking code
     839        if ( ( get_option(key_ga_admin) == ga_enabled || !current_user_can('level_' . get_option(key_ga_admin_level)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
     840        {
     841            # Add the notice that Google Analyticator tracking is enabled
     842            echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
     843           
     844            # Add the Adsense data if specified
     845            if ( get_option(key_ga_adsense) != '' )
     846                echo '<script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n";
     847           
     848            # Add the first part of the core tracking code
     849            ?>
     850<script type="text/javascript">
     851    var _gaq = _gaq || [];
     852    _gaq.push(['_setAccount', '<?php echo $uid; ?>']);
     853<?php
     854       
     855            # Add any tracking code before the trackPageview
    886856            if ( '' != $extra )
    887                 echo "      " . $extra . "\n";
    888        
    889             // Initialize the tracker
    890             echo "      pageTracker._initData();\n";
    891             echo "      pageTracker._trackPageview();\n";
    892        
    893             // Disable page tracking if admin is logged in
     857                echo "  $extra\n";
     858           
     859            # Add the track pageview function
     860            echo "  _gaq.push(['_trackPageview']);\n";
     861       
     862            # Disable page tracking if admin is logged in
    894863            if ( ( get_option(key_ga_admin) == ga_disabled ) && ( current_user_can('level_' . get_option(key_ga_admin_level)) ) )
    895                 echo "      pageTracker._setVar('admin');\n";
    896        
    897             // Insert extra after tracker code
     864                echo "  _gaq.push(['_setVar', 'admin]);\n";
     865       
     866            # Add any tracking code after the trackPageview
    898867            if ( '' != $extra_after )
    899                 echo "      " . $extra_after . "\n";
    900        
    901             echo "  } catch(err) {}</script>\n";
    902        
    903             // Include the file types to track
     868                echo "  $extra_after\n";
     869       
     870            # Add the final section of the tracking code
     871            ?>
     872
     873    (function() {
     874        var ga = document.createElement('script');
     875        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
     876        ga.setAttribute('async', 'true');
     877        document.documentElement.firstChild.appendChild(ga);
     878    })();
     879</script><?php
     880           
     881            # Include the file types to track
    904882            $extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
    905883            $ext = "";
     
    908886            $ext = substr($ext, 0, -1);
    909887       
    910             // Include the link tracking prefixes
     888            # Include the link tracking prefixes
    911889            $outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
    912890            $downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
     
    914892       
    915893            ?>
    916             <script type="text/javascript">
    917                 var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
     894
     895<script type="text/javascript">
     896    var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
    918897<?php if ( $event_tracking != 'enabled' ) { ?>
    919                 var analyticsOutboundPrefix = '/<?php echo $outbound_prefix; ?>/';
    920                 var analyticsDownloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
     898    var analyticsOutboundPrefix = '/<?php echo $outbound_prefix; ?>/';
     899    var analyticsDownloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
    921900<?php } ?>
    922                 var analyticsEventTracking = '<?php echo $event_tracking; ?>';
    923             </script>
    924             <?php
     901    var analyticsEventTracking = '<?php echo $event_tracking; ?>';
     902</script>
     903<?php           
    925904        }
    926905    }
     
    932911function ga_outgoing_links()
    933912{
     913    # Fetch the UID
    934914    $uid = stripslashes(get_option(key_ga_uid));
    935915   
    936     // If GA is enabled and has a valid key
    937     if (  (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
    938         // If outbound tracking is enabled
    939         if ( get_option(key_ga_outbound) == ga_enabled ) {
    940             // If this is not an admin page
    941             if ( !is_admin() ) {
    942                 // Display page tracking if user is not an admin
    943                 if ( ( get_option(key_ga_admin) == ga_enabled || !current_user_can('level_' . get_option(key_ga_admin_level)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' ) {
     916    # If GA is enabled and has a valid key
     917    if (  (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
     918    {
     919        # If outbound tracking is enabled
     920        if ( get_option(key_ga_outbound) == ga_enabled )
     921        {
     922            # If this is not an admin page
     923            if ( !is_admin() )
     924            {
     925                # Display page tracking if user is not an admin
     926                if ( ( get_option(key_ga_admin) == ga_enabled || !current_user_can('level_' . get_option(key_ga_admin_level)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
     927                {
    944928                    add_action('wp_print_scripts', 'ga_external_tracking_js');
    945929                }
     
    954938function ga_external_tracking_js()
    955939{
    956 //  wp_enqueue_script('jquery');
    957940    wp_enqueue_script('ga-external-tracking', plugins_url('/google-analyticator/external-tracking.min.js'), array('jquery'), GOOGLE_ANALYTICATOR_VERSION);
    958941}
  • google-analyticator/trunk/google-analytics-summary-widget.php

    r179550 r179567  
    369369       
    370370        # If the stats need to be updated
    371 //      if ( ! $updated ) {
     371        if ( ! $updated ) {
    372372       
    373373            # Get the metrics needed to build the top pages
     
    380380            update_option('google_stats_topPages_' . $this->id, $newStats);
    381381       
    382 //      }
     382        }
    383383       
    384384        # Check the size of the stats array
  • google-analyticator/trunk/readme.txt

    r179550 r179567  
    5252
    5353= 6.0 =
     54* Switches current tracking script (ga.js) to the new awesome async tracking script. In laymen's terms: updates to the latest tracking code, the tracking script will load faster, and tracking will be more reliable.
    5455* Fixes the (not set) pages in the Top Pages section of the dashboard widget. Pages containing the title (not set) will be combined with the correct page and corresponding title. Note that I am still trying to get this bug fixed in the API; this is just a hold over until the bug is fixed.
    5556* Adds a link to Google Analytics on the dashboard widget for quick access to view full stat reports.
Note: See TracChangeset for help on using the changeset viewer.