30, 'analytics_js'=>'N', 'inpage_tracking'=>'N', 'demographics'=>'N', 'excluded_ips'=>'', 'roles_off'=>'administrator', 'in_footer'=>'N', 'ua_userid'=>'N', 'ua_ecommerce'=>'N', 'display_features'=>'N', 'addon_javascript'=>'')); } } $opts = get_option(self::PLUGIN_OPTIONS); if(isset($opts)) { if(isset($opts['analytics_id'])) $this->analytics_id=$opts['analytics_id']; if(isset($opts['analytics_js'])) $this->analytics_js=($opts['analytics_js']=='Y'); if(isset($opts['inpage_tracking'])) $this->inpage_tracking=($opts['inpage_tracking']=='Y'); if(isset($opts['demographics'])) $this->demographics=($opts['demographics']=='Y'); if(isset($opts['bounce_timeout'])) $this->bounce_timeout=$opts['bounce_timeout']; if(isset($opts['in_footer'])) $this->in_footer=$opts['in_footer']; if(isset($opts['ua_userid'])) $this->ua_userid=($opts['ua_userid']=='Y'); if(isset($opts['ua_ecommerce'])) $this->ua_ecommerce=($opts['ua_ecommerce']=='Y'); if(isset($opts['display_features'])) $this->ua_ecommerce=($opts['display_features']=='Y'); if(isset($opts['addon_javascript'])) $this->addon_javascript=$opts['addon_javascript']; if(isset($opts['excluded_ips'])) { $out=array(); foreach(explode(',',str_replace(' ','',trim($opts['excluded_ips']))) as $ip) { $ip=trim($ip); if(!empty($ip)) $out[]='#^'.str_replace('.','\.',$ip).'#'; } $this->excluded_ips=$out; } if(isset($opts['roles_off'])) { $this->roles_off=explode('|',$opts['roles_off']); } else { $this->roles_off=array("administrator"); } } add_action('add_meta_boxes', array($this,'meta_box_dont_track') ); add_action( 'save_post', array($this,'save_postdata') ); add_action( $this->in_footer ? 'wp_footer' : 'wp_head', array($this,'tracking_code')); add_action('admin_menu', array($this,'admin_menu')); add_action('admin_init',array($this,'register_Settings')); add_shortcode('ga_event',array($this,'shortcode_ga_event')); } function shortcode_ga_event($atts, $content='') { $cat=''; if(isset($atts['cat'])) $cat=trim($atts['cat']); if(isset($atts['category'])) $cat=trim($atts['category']); $act=''; if(isset($atts['act'])) $act=trim($atts['act']); if(isset($atts['action'])) $act=trim($atts['action']); $lab=''; if(isset($atts['lab'])) $lab=trim($atts['lab']); if(isset($atts['label'])) $lab=trim($atts['label']); $val=''; if(isset($atts['val'])) $val=trim($atts['val']); if(isset($atts['value'])) $val=trim($atts['value']); if(empty($cat) || empty($act)) return $content; $args=array("'".$cat."'","'".$act."'"); if(!empty($lab)) { $args[]="'".$lab."'"; if(!empty($val)) $args[]=$val; } $this->event_func=''; if($this->analytics_js) { $this->event_func="ga(".implode(',',$args).");"; } else { $this->event_func="_gaq.push(['_trackEvent',".implode(',',$args)."]);"; } // need to search the enclosed markup for )#si',$content,array($this,'callback_event1')); $content = preg_replace_callback('#(#si',$content,array($this,'callback_event2')); return $content; } private function callback_event1($matches) { if(!preg_match('#(ga|_gaq\.push)\(#si',$matches[2])) { // don't put in the event call if one already there return $matches[1].$this->event_func.$matches[2].$matches[3]; } return $matches[0]; } private function callback_event2($matches) { return $matches[1].' onclick="'.$this->event_func.'return true;">'; } function meta_box_dont_track() { add_meta_box( 'acp-dont-track-box-id', // ID attribute of metabox "Analytics Control Plus", // Title of metabox visible to user array($this,'meta_box_callback'), // Function that prints box in wp-admin 'page', // Show box for posts, pages, custom, etc. 'side', // Where on the page to show the box 'default' ); // Priority of box in display order } function meta_box_callback($post) { wp_nonce_field( 'acp_inner_custom_box', 'acp_inner_custom_box_nonce' ); /* * Use get_post_meta() to retrieve an existing value * from the database and use the value for the form. */ $value = get_post_meta( $post->ID, self::META_KEY, true ); echo '  '; echo ''; } function save_postdata( $post_id ) { if ( ! isset( $_POST['acp_inner_custom_box_nonce'] ) ) return $post_id; $nonce = $_POST['acp_inner_custom_box_nonce']; // Verify that the nonce is valid. if ( ! wp_verify_nonce( $nonce, 'acp_inner_custom_box' ) ) return $post_id; // If this is an autosave, our form has not been submitted, so we don't want to do anything. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; // Check the user's permissions. if ( 'page' == $_POST['post_type'] ) { if ( ! current_user_can( 'edit_page', $post_id ) ) return $post_id; } else { if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id; } /* OK, its safe for us to save the data now. */ // Sanitize user input. $mydata = ($_POST['acp_dont_track']=='Y') ? 'Y' : 'N'; // Update the meta field in the database. update_post_meta( $post_id, self::META_KEY, $mydata ); } private function get_ip() { foreach(array('HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED','HTTP_FORWARDED_FOR','HTTP_VIA', 'HTTP_CLIENT_IP','REMOTE_ADDR') as $f) { if(isset($_SERVER[$f])) return $_SERVER[$f]; } return 'NA'; } private function blocked_ip($ip) { foreach($this->excluded_ips as $bl) { if(preg_match($bl,$ip)) return true; } return false; } private function siteDomain() { $site=get_site_url(); if(preg_match('#^https?://(.*)$#si',$site,$matches)) { $site=$matches[1]; } if(preg_match('#^www\.(.*)$#si',$site,$matches)) { $site=$matches[1]; } return $site; } function tracking_code() { $code_id=$this->analytics_id; if(empty($code_id)) return; if(isset($_GET[self::GET_NOACP])) return; if($this->blocked_ip($this->get_ip())) return; if(is_page()) { $page_id = get_queried_object_id(); $value=get_post_meta($page_id,self::META_KEY, true); if($value=='Y') { echo ""; return; // no GA here!! } } $bounce_timeout=$this->bounce_timeout*1000; $userEnc=''; if($this->ua_userid) { $current_user = wp_get_current_user(); if(isset($current_user)) { $default=false; $userEnc=substr(md5($current_user->user_email.site_url()),0,16); } } $tracking_script=''; if($this->analytics_js) { $site=$this->siteDomain(); $tracking_script = <<<_TRACKING_CODE_ \n"; } else { $tracking_script = <<<_TRACKING_CODE_ _TRACKING_CODE_; } $doit=true; $role=''; $current_user = wp_get_current_user(); if(isset($current_user)) { $roles = $current_user->roles; $role = array_shift($roles); if(in_array($role,$this->roles_off)) $doit=false; } if(!empty($this->addon_javascript)) { $tracking_script.=''; } if($doit) { echo $tracking_script; } else { echo ""; } } function admin_menu() { add_options_page( 'Analytics Control+', 'Analytics Control+', 'manage_options', 'acp', array($this,'options')); } function options() { echo "

Analytics Control Plus Configuration

"; ?>

Please contribute $5 to the ongoing development of this and other plugins


Every little bit helps & encourages more development, please contribute.
Have an idea or suggestion?
Please
Contact Us.
user_email)) $wcUrl.='&email='.urlencode($current_user->user_email); if(!empty($current_user->user_firstname) && !empty($current_user->user_lastname)) $wcUrl.='&uname='.urlencode($current_user->user_firstname.' '.$current_user->user_lastname); } ?>
NEW
Website Checking Tool
Check SEO, Performance, SEM, Branding and Security.
Find out what is wrong with your website and how to fix it.
Test your site now

Shortcodes:

[ga_event cat="CATEGORY" act="ACTION" lab="LABEL" val="VALUE"]
  <a href="click.php">click me</a>
[/ga_event]

Attaches an action event to all anchors within the shortcode. See Event Tracking for more information.


Plugin by Aykira Internet Solutions get_names(); $off_roles=array(); foreach($roles as $role) { if(isset($input["role_$role"])) { $rolel=strtolower($role); $off_roles[]=$rolel; unset($input["role_$role"]); } } $input['roles_off']=implode('|',$off_roles); return $input; } public function ga_section() { echo "

Note: If you turn on the Enhanced Link Attribution or Demographics & Interest Reports you need to configure Google Analytics to use the information; this is done under Admin > Property > Property Settings > Advanced Settings - just flick the toggles to ON and save the changes. Log on to Google Analytics here.

"; } public function settings_analytics_id() { $options = get_option(self::PLUGIN_OPTIONS); $id=''; if(isset($options['analytics_id'])) $id=$options['analytics_id']; echo ""; } public function settings_analytics_js() { $options = get_option(self::PLUGIN_OPTIONS); echo " Google Help details. (site domain = ".$this->siteDomain()."). Migrate to Universal Analytics first in GA before turning on!"; } public function settings_inPage_Tracking() { $options = get_option(self::PLUGIN_OPTIONS); echo " Google Help details. Turn on in GA as well!"; } public function settings_demographics() { $options = get_option(self::PLUGIN_OPTIONS); echo " Google Help details. Turn on in GA as well!"; } public function settings_bounce_timeout() { $options = get_option(self::PLUGIN_OPTIONS); echo " (seconds) Minimum 5 seconds."; } public function settings_in_footer() { $options = get_option(self::PLUGIN_OPTIONS); echo " Put in the footer if you have JavaScript clashes."; } public function settings_excluded_ips() { $options = get_option(self::PLUGIN_OPTIONS); echo "
Comma separated list of IP's excluded (or subnets)
 Current IP = ".$this->get_ip()."
"; } public function settings_roles_off() { $options = get_option(self::PLUGIN_OPTIONS); global $wp_roles; $roles=$wp_roles->get_names(); foreach($roles as $role) { echo "  roles_off)) echo " checked"; echo "> $role
"; } echo "Select those roles who you do not want tracked on site."; } public function settings_ua_userid() { $options = get_option(self::PLUGIN_OPTIONS); echo " Google details. Track userID sessions (UA only)"; } public function settings_ua_ecommerce() { $options = get_option(self::PLUGIN_OPTIONS); echo " Google details. Record Transaction data (UA only)"; } public function settings_remarketing() { $options = get_option(self::PLUGIN_OPTIONS); echo " Google details. Turns on Display Advertising Support"; } public function settings_addon_javascript() { $options = get_option(self::PLUGIN_OPTIONS); echo "
Enter here any other Tracking JavaScript you want under display control. No need for the outer <script> </script>tags."; } } $acp = acp_plugin::instance();