Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1172538
    dwyerddd
    Participant

    I am so confused over where to add following code

    <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’,’https://www.google-analytics.com/analytics.js&#8217;,’ga’);

    ga(‘create’, ‘UA-75297221-3’, ‘auto’);
    ga(‘send’, ‘pageview’);

    </script>

    Some say in functions.php which kills my site and others say in custom javascript of the theme. Can someone please help?

    #1172558
    dwyerddd
    Participant

    I should ad that I put it into Child theme global javascript without <script> but cannot get it verified. Should I be able to see it on the home page in the source?

    #1172679
    Paul R
    Moderator

    Hi,

    You can add this in your child theme’s functions.php file.

    
    
    // Add scripts to wp_footer()
    function child_theme_footer_script() {
    ?>
    <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','https://www.google-analytics.com/analytics.js','ga');
    
    ga('create', 'UA-75297221-3', 'auto');
    ga('send', 'pageview');
    
    </script>
    
    <?php	
    }
    add_action( 'wp_footer', 'child_theme_footer_script' );
    

    Hope that helps

    #1173924
    dwyerddd
    Participant

    Hi Paul

    No go. Please refer to attached files.

    #1174350
    Christopher
    Moderator

    Hi there,

    You can install Analytics extension from X addons page and insert analytics code there.

    Or you can update previous code in child theme’s functions.php to :

    function third_party_tracking_code() { ?>
    
      <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','https://www.google-analytics.com/analytics.js','ga');
    
    ga('create', 'UA-75297221-3', 'auto');
    ga('send', 'pageview');
    
    </script>
    
    <?php }
    
    add_action( 'wp_head', 'third_party_tracking_code' );

    Hope it helps.

    #1175588
    dwyerddd
    Participant

    Thank you Christopher

    #1176006
    Friech
    Moderator

    We’re delighted to assist you with this.

    Cheers!

    #1290911
    Shutsen
    Participant

    Hi Themeco,

    How come in the snippet below, the first php tag is a closing one (?>) and the second one an opening (<?php).. Where did the first closing one open, and where does the second opening one close?

    Thanks for shining some light on this..

    function third_party_tracking_code() { ?>

    <script>
    // Third party tracking code.
    </script>

    <?php }

    add_action( ‘wp_footer’, ‘third_party_tracking_code’ );

    #1291003
    Christian
    Moderator

    It’s best practice not to close PHP. You need to close it when you insert an HTML though and then add an the opening <?php again to continue with the rest of the PHP code. For more details, please see http://php.net/manual/en/language.basic-syntax.phptags.php

    Thanks.

    #1292369
    Shutsen
    Participant

    Superinteresting. Thanks for clarifying that 🙂
    So then I have no clue why analytics doesn’t start tracking.. After double triple checking my php code, my analytics tracking code, correct ftp upload etc, I have no clue why it’s not doing anything..

    #1292415
    Lely
    Moderator

    Hi There,

    To help you better with this, please share your site URL and also the code you have added so we can double check for you. In case you do have caching plugin, please purge cache.

    #1297001
    Shutsen
    Participant
    This reply has been marked as private.
    #1297005
    Shutsen
    Participant
    This reply has been marked as private.
    #1297040
    Christopher
    Moderator

    Hi there,

    Google analytics was added successfully to your site, please see the attachment.

    Hope it helps.

    #1297958
    Shutsen
    Participant

    It started analyzing yes! Thank you!

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