This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

More control over Google Analytics code

  • Creator
    Topic
  • #6755
    srumery
    Participant

    Can you point out the location where the Google Analytics field is rendered? I would like to build an option (checkbox) into my child themes that gives the option to disable writing GA code to the page is the user is logged in. I don’t always want to log page views when I am logged in tweaking a page or post. It can mess with my GA reports on low traffic sites. Also, I see that it captures page views while I am in the editor previewing a new page or post (/?page_id=425&preview=true).

    Controlling the GA code a bit more would be really helpful. Is there an action or filter that I can use to alter when the code is written?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #6763
    Jason Bobich
    Keymaster

    You can remove it like this:

    Jump Start v1.0.1+ —

    remove_action( 'wp_head', 'themeblvd_analytics' );

    Jump Start v1.0.0 —

    remove_action( 'wp_footer', 'themeblvd_analytics' );

    You can use the themeblvd_analytics function to display the analytics in your own function conditionally to whatever you need and hook that to whatever action you want.

    #6780
    srumery
    Participant

    Perfect. Thank you!

    #6788
    karlo
    Participant

    What if scrumerys idea became a little tick box in Jump Start Analytics box? Like he says:

    if ( !current_user_can( 'administrator' ) ) && !is_preview() ) {
    tracking code...
    }

    or similar. “You want to hide Preview can just be hidden.

    Value of box increases with no side effect? Would be good enough for simple Analytics setup. Or better simple Piwik setup 🙂

    Piwik has changed code for tracking, now also goes in wp_head with async.

    Services an exclude admin via cookie, ip but they are not as fool proof. Plugins can do this and much more. And we control function with remove_action. But even so…

    Or may be “who is admin” queston make it best to avoid? Multi site? or a site has 10 admins but only the 1 who can edit plugins should really be excluded? Might be too muddy but it seems like a good idea to add tick box for simple sites.

    #6798
    Jason Bobich
    Keymaster

    Sounds like a cool idea for a plugin — To essentially disable analytics for the logged-in admin.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.