id = 'google_analytics';
$this->method_title = __( 'Google Analytics', 'woocommerce' );
$this->method_description = __( 'Google Analytics is a free service offered by Google that generates detailed statistics about the visitors to a website.', 'woocommerce' );
// Load the form fields.
$this->init_form_fields();
// Load the settings.
$this->init_settings();
// Define user set variables
$this->ga_id = $this->settings['ga_id'];
$this->ga_standard_tracking_enabled = $this->settings['ga_standard_tracking_enabled'];
$this->ga_ecommerce_tracking_enabled = $this->settings['ga_ecommerce_tracking_enabled'];
// Actions
add_action( 'woocommerce_update_options_integration_google_analytics', array( &$this, 'process_admin_options') );
// Tracking code
add_action( 'wp_footer', array( &$this, 'google_tracking_code' ) );
add_action( 'woocommerce_thankyou', array( &$this, 'ecommerce_tracking_code' ) );
}
/**
* Initialise Settings Form Fields
*/
function init_form_fields() {
$this->form_fields = array(
'ga_id' => array(
'title' => __('Google Analytics ID', 'woocommerce'),
'description' => __('Log into your google analytics account to find your ID. e.g. UA-XXXXX-X
', 'woocommerce'),
'type' => 'text',
'default' => get_option('woocommerce_ga_id')
),
'ga_standard_tracking_enabled' => array(
'title' => __('Tracking code', 'woocommerce'),
'label' => __('Add tracking code to your site\'s footer. You don\'t need to enable this if using a 3rd party analytics plugin.', 'woocommerce'),
'type' => 'checkbox',
'checkboxgroup' => 'start',
'default' => get_option('woocommerce_ga_standard_tracking_enabled') ? get_option('woocommerce_ga_standard_tracking_enabled') : 'no'
),
'ga_ecommerce_tracking_enabled' => array(
'label' => __('Add eCommerce tracking code to the thankyou page', 'woocommerce'),
'type' => 'checkbox',
'checkboxgroup' => 'end',
'default' => get_option('woocommerce_ga_ecommerce_tracking_enabled') ? get_option('woocommerce_ga_ecommerce_tracking_enabled') : 'no'
)
);
/**
* Google Analytics standard tracking
**/
function google_tracking_code() {
global $woocommerce;
if ( is_admin() || current_user_can('manage_options') || get_option('woocommerce_ga_standard_tracking_enabled') == "no" ) return;
$tracking_id = get_option('woocommerce_ga_id');
if ( ! $tracking_id ) return;
$loggedin = ( is_user_logged_in() ) ? 'yes' : 'no';
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$current_user = get_user_by('id', $user_id);
$username = $current_user->user_login;
} else {
$user_id = '';
$username = __('Guest', 'woocommerce');
}
?>
user_login;
} else {
$user_id = '';
$username = __('Guest', 'woocommerce');
}
?>