Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1098426
    ealor
    Participant

    hi !
    Filtering IP with google analytics is not a good issue for me, and I want exclude connected users from data sent to GA.

    My GA ID is set with the GA plugin you provide, works in the header (best practice), nice it works 😉 BUT how exclude connected users ?

    I found a php that seem to be efficient :
    <?php if(!current_user_can(‘manage_options’)){ ?>
    <script type=”text/javascript”>
    [here put the script Google Analytics]
    </script>
    <?php } ?>

    BUT where put this (if it works) to keep GA working in all headers ?

    And it shoud be more suitable for anyone to add a check box in your plugin “exclude connected users” than add functions in child theme and so on…! no ?

    than you for your attention
    cordially

    #1098509
    Lely
    Moderator

    Hi There,

    Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    Then add the code on your child theme’s functions.php file like this:

    function third_party_tracking_code() { 
    if(!current_user_can('manage_options')){
    ?>
    <script type="text/javascript">
    [here put the script Google Analytics]
    </script>
    
    <?php }}
    
    add_action( 'wp_head', 'third_party_tracking_code' );
    

    This link might help:https://community.theme.co/kb/customization/actions-and-filters-in-x/

    We certainly appreciate the feedback! This is something we can add to our list of feature requests. This way it can be taken into consideration for future development. All of these items are discussed with our team internally and prioritized based on the amount of interest a particular feature might receive. Thanks!

    #1101553
    ealor
    Participant

    thanks, done ==> waiting now a day or two to check if it works clean / I’ll keep you in touch

    #1101606
    Christian
    Moderator

    You’re welcome.

    #1101608
    ealor
    Participant

    I have an error ==> site down for maintenance… So I go back previous function.php.
    May be syntax error ? is really <script type=”text/javascript”> necessary instead of <script> ?

    Down here is the function.php that shoud work (but not), notice that I added loading a google font previously :

    <?php

    // =============================================================================
    // FUNCTIONS.PHP
    // —————————————————————————–
    // Overwrite or add your own custom functions to X in this file.
    // =============================================================================

    // =============================================================================
    // TABLE OF CONTENTS
    // —————————————————————————–
    // 01. Enqueue Parent Stylesheet
    // 02. Additional Functions
    // =============================================================================

    // Enqueue Parent Stylesheet
    // =============================================================================

    add_filter( ‘x_enqueue_parent_stylesheet’, ‘__return_true’ );

    // Additional Functions
    // =============================================================================

    function my_custom_head_output() {
    ?>
    <link href=’https://fonts.googleapis.com/css?family=Homemade+Apple&#8217; rel=’stylesheet’ type=’text/css’>
    <?php
    }

    add_action( ‘wp_head’, ‘my_custom_head_output’, 99999 );

    function third_party_tracking_code() {
    if(!current_user_can(‘manage_options’)){
    ?>
    <script type=”text/javascript”>
    (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,’script’,’https://www.google-analytics.com/analytics.js&#8217;,’ga’);

    ga(‘create’, ‘UA-xxxxxxx’, ‘auto’);
    ga(‘send’, ‘pageview’);
    </script>

    <?php }}

    add_action( ‘wp_head’, ‘third_party_tracking_code’ );

    any idea ?
    thanks

    #1101713
    Paul R
    Moderator

    Hi,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #1101771
    ealor
    Participant
    This reply has been marked as private.
    #1101774
    ealor
    Participant
    This reply has been marked as private.
    #1102085
    Darshana
    Moderator

    Hi there,

    Thanks for the FTP information provided. I went ahead and updated your code in your child theme’s functions.php file.

    Please make sure to update your code with the your Google Analytics ID.

    Replace the following in the code with your actual Google Analytics ID
    UA-xxxxxxx

    Let us know how it goes.
    Thanks!

    #1104871
    ealor
    Participant

    Seem it works, thanks ! I look tomorrow to see if GA will works great also and exclude connected users as wanted… and tell you.

    can you say me what you corrected on the code provided ? Or what mistake I done ?

    thanks

    #1105080
    Joao
    Moderator

    Hi There,

    Your google ID was added to the code.

    “Replace the following in the code with your actual Google Analytics ID
    UA-xxxxxxx”

    Hope that helps

    Joao

    #1106763
    ealor
    Participant

    hi great supp 😉

    of course I set correct UA ID…

    website works great with function.php edited in child theme, but exclude connected users seems to be inefficient !

    I look to real time traffic in google analytics: not connected I can see my hits, connected I can also see my hits / seems filter doesn works… bad thing

    any idea ? (I use php 7)

    thank you

    #1106841
    Rue Nel
    Moderator

    Hello There,

    For more better control of your Google Analytics, please use a 3rd party plugin instead. Perhaps this one could help:

    MonsterInsights – Google Analytics Dashboard for WordPress (Website Stats Made Easy)

    Hope this helps. Please let us know how it goes.

    #1108571
    ealor
    Participant

    seems it works great now! thank you.

    have a nice week-end

    #1108617
    Lely
    Moderator

    You’re welcome!

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-1098426 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>