Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1115306

    I’m using an Enflod Child Theme and have copied into Google Services -> Tracking Code. Everything works fine.

    I have followed this tutorial to exclude traffic via a filter in Google Analytics:

    However, when I add the php function that checks if a special cookie is set before ga('send', 'pageview'); then the tracking stops working for all users. How can I add such a function in Enfold?

    <script>
        (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','//www.google-analytics.com/analytics.js','ga');
    
        ga('create', 'UA-XXXXXXX-X', 'auto');
        <?php
        if( isset( $_COOKIE['user_is_admin'] ) ) {
            echo 'ga(\'set\', \'dimension1\', \'true\');';
        }
        ?>
        ga('send', 'pageview');
    </script>
    #1115409

    Hey Eneas,

    Unfortunately, it would require quite some time and customization of the theme to achieve this, so I am sorry to tell you that this is not covered by our support. However, if it’s really important for you to get this done, you can always hire a freelancer to do the job for you :)

    Best regards,
    Vinay

    #1115410

    Hi Vinay! Thank you for your reply. The question was just why the embedded php code in the script snippet above is not working as expected in Enfold?

    #1115625

    Hi,

    You could try to add the code in a function instead to see if that works better:

    function eneas_add_custom_code(){
    ?>
    //YOUR CODE GOES HERE
    <?php
    }
    add_action('wp_head', 'eneas_add_custom_code');

    Best regards,
    Rikard

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