Support » Plugin: NK Google Analytics » It works, but not as advertised

  • The plugin lists a feature “No tracking for admin users logged-in.” – however, the Analytics tracking code is still displayed even when logged in as an admin (not inside the Admin Panel, but on the normal blog sites).

    Looking into the code, I realized that the author tries to accomplish this switch using is_admin(). The WordPress Codex clearly states: ” It should not be used as a means to verify whether the current user has permission to view the Dashboard or the administration panel (try current_user_can() instead)” (see http://codex.wordpress.org/Function_Reference/is_admin)

    I solved this by manually adapting the check in the plugin code to

    if (!current_user_can( ‘edit_posts’ )) {
    add_action(‘wp_head’, ‘NKgoogleanalytics’);
    }

    P.S.: I also have a feature request: It should be possible to select wether you want the code inserted into the head or the end of the page (for speed optimization).

Viewing 3 replies - 1 through 3 (of 3 total)
  • P.S. current_user_can would cause the page to stay completely white with no markup being generated. Wrap it up like this in order to work:

    if (!current_user_can( ‘edit_posts’ )) {
    add_action(‘wp_head’, ‘NKgoogleanalytics’);
    }

    Adapted this in my previous post.

    Plugin Author marodok

    (@marodok)

    Hi Connum,

    This is an interesting comment because i can improve the plugin, thank you. I’ll change the way in that plugin detect logged admin users for next update.

    Also, I have been working in the option to set where the code will be inserted (between head or end of page), maybe it will be available for next update.

    Thankyou again,

    CaliforniaTeachersCollege

    (@californiateacherscollege)

    First off, loving the plugin so far…Very easy and works with UA!! So thank you so much for it!!

    Just curious, how do you analyze whether to put it into the head or the footer?

    In other words, why would I chose to insert it into the head instead of the footer or footer instead of the head?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘It works, but not as advertised’ is closed to new replies.