Changeset 179567
- Timestamp:
- 12/04/2009 07:06:36 AM (16 years ago)
- Location:
- google-analyticator/trunk
- Files:
-
- 5 edited
-
external-tracking.js (modified) (2 diffs)
-
external-tracking.min.js (modified) (1 diff)
-
google-analyticator.php (modified) (7 diffs)
-
google-analytics-summary-widget.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
google-analyticator/trunk/external-tracking.js
r126750 r179567 24 24 a.click(function() { 25 25 if ( analyticsEventTracking == 'enabled' ) { 26 pageTracker._trackEvent("Downloads", extension.toUpperCase(), href);26 _gaq.push(['_trackEvent', 'Downloads', extension.toUpperCase(), href]); 27 27 } else 28 pageTracker._trackPageview(analyticsDownloadsPrefix + url);28 _gaq.push(['_trackPageview', analyticsDownloadsPrefix + url]); 29 29 }); 30 30 } … … 35 35 a.click(function() { 36 36 if ( analyticsEventTracking == 'enabled' ) { 37 pageTracker._trackEvent("Outbound Traffic", href.match(/:\/\/(.[^/]+)/)[1], href);37 _gaq.push(['_trackEvent', 'Outbound Traffic', href.match(/:\/\/(.[^/]+)/)[1], href]); 38 38 } else 39 pageTracker._trackPageview(analyticsOutboundPrefix + url);39 _gaq.push(['_trackPageview', analyticsOutboundPrefix + url]); 40 40 }); 41 41 } -
google-analyticator/trunk/external-tracking.min.js
r126750 r179567 1 1 jQuery(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);}else3 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);}else5 pageTracker._trackPageview(analyticsOutboundPrefix+url);});}});});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'){_gaq.push(['_trackEvent','Downloads',extension.toUpperCase(),href]);}else 3 _gaq.push(['_trackPageview',analyticsDownloadsPrefix+url]);});} 4 if((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 118 118 } 119 119 120 // Initialize outbound link tracking 120 # Add the core Google Analytics script, with a high priority to ensure last script for async tracking 121 add_action('wp_head', 'add_google_analytics', 999999); 122 123 # Initialize outbound link tracking 121 124 add_action('init', 'ga_outgoing_links'); 122 125 … … 819 822 } 820 823 821 // Add the script822 $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 831 824 /** 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 834 826 **/ 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 827 function add_google_analytics() 828 { 829 # Fetch variables used in the tracking code 853 830 $uid = stripslashes(get_option(key_ga_uid)); 854 831 $extra = stripslashes(get_option(key_ga_extra)); … … 856 833 $extensions = str_replace (",", "|", get_option(key_ga_downloads)); 857 834 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 886 856 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 894 863 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 code864 echo " _gaq.push(['_setVar', 'admin]);\n"; 865 866 # Add any tracking code after the trackPageview 898 867 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 904 882 $extensions = explode(',', stripslashes(get_option(key_ga_downloads))); 905 883 $ext = ""; … … 908 886 $ext = substr($ext, 0, -1); 909 887 910 //Include the link tracking prefixes888 # Include the link tracking prefixes 911 889 $outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix)); 912 890 $downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix)); … … 914 892 915 893 ?> 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); ?>]; 918 897 <?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; ?>/'; 921 900 <?php } ?> 922 var analyticsEventTracking = '<?php echo $event_tracking; ?>';923 </script>924 <?php 901 var analyticsEventTracking = '<?php echo $event_tracking; ?>'; 902 </script> 903 <?php 925 904 } 926 905 } … … 932 911 function ga_outgoing_links() 933 912 { 913 # Fetch the UID 934 914 $uid = stripslashes(get_option(key_ga_uid)); 935 915 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 { 944 928 add_action('wp_print_scripts', 'ga_external_tracking_js'); 945 929 } … … 954 938 function ga_external_tracking_js() 955 939 { 956 // wp_enqueue_script('jquery');957 940 wp_enqueue_script('ga-external-tracking', plugins_url('/google-analyticator/external-tracking.min.js'), array('jquery'), GOOGLE_ANALYTICATOR_VERSION); 958 941 } -
google-analyticator/trunk/google-analytics-summary-widget.php
r179550 r179567 369 369 370 370 # If the stats need to be updated 371 //if ( ! $updated ) {371 if ( ! $updated ) { 372 372 373 373 # Get the metrics needed to build the top pages … … 380 380 update_option('google_stats_topPages_' . $this->id, $newStats); 381 381 382 //}382 } 383 383 384 384 # Check the size of the stats array -
google-analyticator/trunk/readme.txt
r179550 r179567 52 52 53 53 = 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. 54 55 * 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. 55 56 * 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.