Welcome!
Hi My name is Claire! I am a mom, and student, oh yeah and a photographer. I love photographing those life moments that slip by all two fast and turning them in to beautiful pieces of art. Check out my facebook page or online website to get to know me more!
Google's Analytics. After enabling this plugin visit
the settings page and enter your Google Analytics' UID and enable logging.
* Author: Spiral Web Consulting
* Author URI: http://spiralwebconsulting.com/
*/
define('GOOGLE_ANALYTICATOR_VERSION', '4.2.1');
# Include Google Analytics Stats widget
if ( function_exists('curl_init') ) {
# Check if we have a version of WordPress greater than 2.8
if ( function_exists('register_widget') ) {
require_once('google-analytics-stats-widget.php');
} else {
require_once('google-analytics-stats.php');
$google_analytics_stats = new GoogleStatsWidget();
}
}
// 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_level", "ga_admin_level", 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_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_footer", "ga_footer", true);
define("key_ga_specify_http", "ga_specify_http", 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_admin_level_default", 8, true);
define("ga_adsense_default", "", true);
define("ga_extra_default", "", true);
define("ga_extra_after_default", "", 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_footer_default", ga_disabled, true);
define("ga_specify_http_default", "auto", true);
// Create the default key and status
add_option(key_ga_status, ga_status_default, 'If Google Analytics logging in turned on or off.');
add_option(key_ga_uid, ga_uid_default, 'Your Google Analytics UID.');
add_option(key_ga_admin, ga_admin_default, 'If WordPress admins are counted in Google Analytics.');
add_option(key_ga_admin_disable, ga_admin_disable_default, '');
add_option(key_ga_admin_level, ga_admin_level_default, 'The level to consider a user a WordPress admin.');
add_option(key_ga_adsense, ga_adsense_default, '');
add_option(key_ga_extra, ga_extra_default, 'Addition Google Analytics tracking options');
add_option(key_ga_extra_after, ga_extra_after_default, 'Addition Google Analytics tracking options');
add_option(key_ga_outbound, ga_outbound_default, 'Add tracking of outbound links');
add_option(key_ga_outbound_prefix, ga_outbound_prefix_default, 'Add tracking of outbound links');
add_option(key_ga_downloads, ga_downloads_default, 'Download extensions to track with Google Analyticator');
add_option(key_ga_downloads_prefix, ga_downloads_prefix_default, 'Download extensions to track with Google Analyticator');
add_option(key_ga_footer, ga_footer_default, 'If Google Analyticator is outputting in the footer');
add_option(key_ga_specify_http, ga_specify_http_default, 'Automatically detect the http/https settings');
// 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() {
// Register out options so WordPress knows about them
if ( function_exists('register_setting') ) {
register_setting('google-analyticator', key_ga_status, '');
register_setting('google-analyticator', key_ga_uid, '');
register_setting('google-analyticator', key_ga_admin, '');
register_setting('google-analyticator', key_ga_admin_disable, '');
register_setting('google-analyticator', key_ga_admin_level, '');
register_setting('google-analyticator', key_ga_adsense, '');
register_setting('google-analyticator', key_ga_extra, '');
register_setting('google-analyticator', key_ga_extra_after, '');
register_setting('google-analyticator', key_ga_outbound, '');
register_setting('google-analyticator', key_ga_outbound_prefix, '');
register_setting('google-analyticator', key_ga_downloads, '');
register_setting('google-analyticator', key_ga_downloads_prefix, '');
register_setting('google-analyticator', key_ga_footer, '');
register_setting('google-analyticator', key_ga_specify_http, '');
}
}
// Initialize outbound link tracking
add_action('init', 'ga_outgoing_links');
// Hook in the options page function
function add_ga_option_page() {
global $wpdb;
add_options_page('Google Analyticator Settings', 'Google Analytics', 8, basename(__FILE__), 'ga_options_page');
}
function ga_options_page() {
// If we are a postback, store the options
if (isset($_POST['info_update'])) {
// if ( wp_verify_nonce($_POST['ga-nonce-key'], 'google-analyticator') ) {
// 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
$ga_admin_level = $_POST[key_ga_admin_level];
if ( $ga_admin_level == '' )
$ga_admin_level = ga_admin_level_default;
update_option(key_ga_admin_level, $ga_admin_level);
// 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 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 footer
$ga_footer = $_POST[key_ga_footer];
if (($ga_footer != ga_enabled) && ($ga_footer != ga_disabled))
$ga_footer = ga_footer_default;
update_option(key_ga_footer, $ga_footer);
// Update the HTTP status
$ga_specify_http = $_POST[key_ga_specify_http];
if ( $ga_specify_http == '' )
$ga_specify_http = 'auto';
update_option(key_ga_specify_http, $ga_specify_http);
# Update the stat options
update_option('google_stats_user', $_POST['google_stats_user']);
update_option('google_stats_password', $_POST['google_stats_password']);
// Give an updated message
echo "
Google Analyticator settings saved.
";
// }
}
// Output the options page
?>
\n";
echo ' \n\n";
}
}
}
}
// The guts of the Google Analytics script
function add_google_analytics() {
global $ga_in_footer;
$uid = stripslashes(get_option(key_ga_uid));
$extra = stripslashes(get_option(key_ga_extra));
$extra_after = stripslashes(get_option(key_ga_extra_after));
$extensions = str_replace (",", "|", get_option(key_ga_downloads));
// If GA is enabled and has a valid key
if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
// Display page tracking if user is not an admin
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' ) {
echo "\n";
# Google Adsense data if enabled
if ( get_option(key_ga_adsense) != '' && !$ga_in_footer )
echo ' \n\n";
// Pick the HTTP connection
if ( get_option(key_ga_specify_http) == 'http' ) {
echo " \n\n";
} elseif ( get_option(key_ga_specify_http) == 'https' ) {
echo " \n\n";
} else {
echo " \n\n";
}
echo " \n";
// Include the file types to track
$extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
$ext = "";
foreach ( $extensions AS $extension )
$ext .= "'$extension',";
$ext = substr($ext, 0, -1);
// Include the link tracking prefixes
$outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
$downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
?>
by Claire
no comments
link to this post email a friend