Google Analytics
Removed analytics code for logged in users (2 posts)

  1. dake84
    Posted 3 years ago #

    Thanks alot for that simple plugin. However I wanted to remove the analytics code when a user was logged into wordpress.

    I achieved this by replacing the lines 55-bottom from the current release (1.0.5) with this code:

    function add_analytics_code(){
      if (!is_user_logged_in()) {
       add_action('wp_head', 'googleanalytics');
    register_activation_hook(__FILE__, 'activate_googleanalytics');
    register_deactivation_hook(__FILE__, 'deactive_googleanalytics');
    if (is_admin()) {
      add_action('admin_init', 'admin_init_googleanalytics');
      add_action('admin_menu', 'admin_menu_googleanalytics');
    } else {
      add_action('init', 'add_analytics_code');

    Would be glad if this change could make it to the code base (maybe the more sophisticated developer might introduce a checkbox in the options dialog or so...).


  2. ClaytonL
    Posted 2 years ago #

    You could put the following in your functions.php if you wanted.

    remove_action( 'wp_head', 'googleanalytics');
    if (!is_admin() && !is_user_logged_in()) {
      add_action('wp_head', 'googleanalytics');

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Google Analytics
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.