Google's Analytics. After enabling this plugin visit the settings page and enter your Google Analytics' UID and enable logging. * Author: Ronald Heft * Author URI: http://ronaldheft.com/ * Text Domain: google-analyticator */ define('GOOGLE_ANALYTICATOR_VERSION', '6.2'); // Constants for enabled/disabled state define("ga_enabled", "enabled", true); define("ga_disabled", "disabled", true); // Defaults, etc. define("key_ga_uid", "ga_uid", true); define("key_ga_status", "ga_status", true); define("key_ga_admin", "ga_admin_status", true); define("key_ga_admin_disable", "ga_admin_disable", true); define("key_ga_admin_role", "ga_admin_role", true); define("key_ga_dashboard_role", "ga_dashboard_role", true); define("key_ga_adsense", "ga_adsense", true); define("key_ga_extra", "ga_extra", true); define("key_ga_extra_after", "ga_extra_after", true); define("key_ga_event", "ga_event", true); define("key_ga_outbound", "ga_outbound", true); define("key_ga_outbound_prefix", "ga_outbound_prefix", true); define("key_ga_downloads", "ga_downloads", true); define("key_ga_downloads_prefix", "ga_downloads_prefix", true); define("key_ga_widgets", "ga_widgets", true); define("key_ga_sitespeed", "ga_sitespeed", true); define("ga_uid_default", "XX-XXXXX-X", true); define("ga_status_default", ga_disabled, true); define("ga_admin_default", ga_enabled, true); define("ga_admin_disable_default", 'remove', true); define("ga_adsense_default", "", true); define("ga_extra_default", "", true); define("ga_extra_after_default", "", true); define("ga_event_default", ga_enabled, true); define("ga_outbound_default", ga_enabled, true); define("ga_outbound_prefix_default", 'outgoing', true); define("ga_downloads_default", "", true); define("ga_downloads_prefix_default", "download", true); define("ga_widgets_default", ga_enabled, true); define("ga_sitespeed_default", ga_enabled, true); // Create the default key and status add_option(key_ga_status, ga_status_default, ''); add_option(key_ga_uid, ga_uid_default, ''); add_option(key_ga_admin, ga_admin_default, ''); add_option(key_ga_admin_disable, ga_admin_disable_default, ''); add_option(key_ga_admin_role, array('administrator'), ''); add_option(key_ga_dashboard_role, array('administrator'), ''); add_option(key_ga_adsense, ga_adsense_default, ''); add_option(key_ga_extra, ga_extra_default, ''); add_option(key_ga_extra_after, ga_extra_after_default, ''); add_option(key_ga_event, ga_event_default, ''); add_option(key_ga_outbound, ga_outbound_default, ''); add_option(key_ga_outbound_prefix, ga_outbound_prefix_default, ''); add_option(key_ga_downloads, ga_downloads_default, ''); add_option(key_ga_downloads_prefix, ga_downloads_prefix_default, ''); add_option('ga_profileid', '', ''); add_option(key_ga_widgets, ga_widgets_default, ''); add_option('ga_google_token', '', ''); add_option('ga_compatibility', 'off', ''); add_option(key_ga_sitespeed, ga_sitespeed_default, ''); # Check if we have a version of WordPress greater than 2.8 if ( function_exists('register_widget') ) { # Check if widgets are enabled if ( get_option(key_ga_widgets) == 'enabled' ) { # Include Google Analytics Stats widget require_once('google-analytics-stats-widget.php'); # Include the Google Analytics Summary widget require_once('google-analytics-summary-widget.php'); $google_analytics_summary = new GoogleAnalyticsSummary(); } } // Create a option page for settings add_action('admin_init', 'ga_admin_init'); add_action('admin_menu', 'add_ga_option_page'); // Initialize the options function ga_admin_init() { # Load the localization information $plugin_dir = basename(dirname(__FILE__)); load_plugin_textdomain('google-analyticator', 'wp-content/plugins/' . $plugin_dir . '/localizations', $plugin_dir . '/localizations'); } # Add the core Google Analytics script, with a high priority to ensure last script for async tracking add_action('wp_head', 'add_google_analytics', 999999); add_action('login_head', 'add_google_analytics', 999999); # Initialize outbound link tracking add_action('init', 'ga_outgoing_links'); // Hook in the options page function function add_ga_option_page() { $plugin_page = add_options_page(__('Google Analyticator Settings', 'google-analyticator'), 'Google Analytics', 'manage_options', basename(__FILE__), 'ga_options_page'); # Include javascript on the GA settings page add_action('admin_head-' . $plugin_page, 'ga_admin_ajax'); } add_action('plugin_action_links_' . plugin_basename(__FILE__), 'ga_filter_plugin_actions'); // Add settings option function ga_filter_plugin_actions($links) { $new_links = array(); $new_links[] = '' . __('Settings', 'google-analyticator') . ''; return array_merge($new_links, $links); } add_filter('plugin_row_meta', 'ga_filter_plugin_links', 10, 2); // Add FAQ and support information function ga_filter_plugin_links($links, $file) { if ( $file == plugin_basename(__FILE__) ) { $links[] = '' . __('FAQ', 'google-analyticator') . ''; $links[] = '' . __('Support', 'google-analyticator') . ''; $links[] = '' . __('Donate', 'google-analyticator') . ''; } return $links; } function ga_options_page() { // If we are a postback, store the options if (isset($_POST['info_update'])) { # Verify nonce check_admin_referer('google-analyticator-update_settings'); // Update the status $ga_status = $_POST[key_ga_status]; if (($ga_status != ga_enabled) && ($ga_status != ga_disabled)) $ga_status = ga_status_default; update_option(key_ga_status, $ga_status); // Update the UID $ga_uid = $_POST[key_ga_uid]; if ($ga_uid == '') $ga_uid = ga_uid_default; update_option(key_ga_uid, $ga_uid); // Update the admin logging $ga_admin = $_POST[key_ga_admin]; if (($ga_admin != ga_enabled) && ($ga_admin != ga_disabled)) $ga_admin = ga_admin_default; update_option(key_ga_admin, $ga_admin); // Update the admin disable setting $ga_admin_disable = $_POST[key_ga_admin_disable]; if ( $ga_admin_disable == '' ) $ga_admin_disable = ga_admin_disable_default; update_option(key_ga_admin_disable, $ga_admin_disable); // Update the admin level if ( array_key_exists(key_ga_admin_role, $_POST) ) { $ga_admin_role = $_POST[key_ga_admin_role]; } else { $ga_admin_role = ""; } update_option(key_ga_admin_role, $ga_admin_role); // Update the dashboard level if ( array_key_exists(key_ga_dashboard_role, $_POST) ) { $ga_dashboard_role = $_POST[key_ga_dashboard_role]; } else { $ga_dashboard_role = ""; } update_option(key_ga_dashboard_role, $ga_dashboard_role); // Update the extra tracking code $ga_extra = $_POST[key_ga_extra]; update_option(key_ga_extra, $ga_extra); // Update the extra after tracking code $ga_extra_after = $_POST[key_ga_extra_after]; update_option(key_ga_extra_after, $ga_extra_after); // Update the adsense key $ga_adsense = $_POST[key_ga_adsense]; update_option(key_ga_adsense, $ga_adsense); // Update the event tracking $ga_event = $_POST[key_ga_event]; if (($ga_event != ga_enabled) && ($ga_event != ga_disabled)) $ga_event = ga_event_default; update_option(key_ga_event, $ga_event); // Update the outbound tracking $ga_outbound = $_POST[key_ga_outbound]; if (($ga_outbound != ga_enabled) && ($ga_outbound != ga_disabled)) $ga_outbound = ga_outbound_default; update_option(key_ga_outbound, $ga_outbound); // Update the outbound prefix $ga_outbound_prefix = $_POST[key_ga_outbound_prefix]; if ($ga_outbound_prefix == '') $ga_outbound_prefix = ga_outbound_prefix_default; update_option(key_ga_outbound_prefix, $ga_outbound_prefix); // Update the download tracking code $ga_downloads = $_POST[key_ga_downloads]; update_option(key_ga_downloads, $ga_downloads); // Update the download prefix $ga_downloads_prefix = $_POST[key_ga_downloads_prefix]; if ($ga_downloads_prefix == '') $ga_downloads_prefix = ga_downloads_prefix_default; update_option(key_ga_downloads_prefix, $ga_downloads_prefix); // Update the profile id update_option('ga_profileid', $_POST['ga_profileid']); // Update the widgets option $ga_widgets = $_POST[key_ga_widgets]; if (($ga_widgets != ga_enabled) && ($ga_widgets != ga_disabled)) $ga_widgets = ga_widgets_default; update_option(key_ga_widgets, $ga_widgets); // Update the compatibility options $ga_compatibility = $_POST['ga_compatibility']; if ( $ga_compatibility == '' ) $ga_compatibility = 'off'; update_option('ga_compatibility', $ga_compatibility); // Update the sitespeed option $ga_sitespeed = $_POST[key_ga_sitespeed]; if (($ga_sitespeed != ga_enabled) && ($ga_sitespeed != ga_disabled)) $ga_sitespeed = ga_widgets_default; update_option(key_ga_sitespeed, $ga_sitespeed); // Give an updated message echo "
" . __('Google Analyticator settings saved.', 'google-analyticator') . "
Like Google Analyticator? Help support it by donating to the developer. This helps cover the cost of maintaining the plugin and development time toward new features. Every donation, no matter how small, is appreciated.