Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #884736
    WebHorse413
    Participant

    I am unable to edit the header.php file for any of my sites using the x theme. I have created a child theme and copied the header.php files from the parent via FTP, but they do not include the <HEAD> </HEAD> and I have no way of including the tracking. please help.

    #885520
    Thai
    Moderator

    Hi There,

    To add the google analytics tracking code, please add the following code under functions.php file locates in your child theme:

    add_action( 'wp_head', 'x_google_code' );
    function x_google_code(){
    	?>
    	<!-- Your Google Analytics Code Go Here -->
    	<?php
    }

    Hope it helps 🙂

    #888838
    WebHorse413
    Participant

    Excellent I will do this right now. Just to be certain, I would be adding my code in between both “–” and replacing the “Your Google Analytics Code Go Here” with the tracking code, but leaving everything else as is?

    #888877
    WebHorse413
    Participant

    And this is the tracking code I usually use. Do I use this format or just the tracking ID when adding the code this way?

    <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.instBefore(a,m)
    })(window,document,’script’,’https://www.google-analytics.com/analytics.js&#8217;,’ga’);

    ga(‘create’, ‘UA-69475208-2’, ‘auto’);
    ga(‘send’, ‘pageview’);

    </script>

    #888922

    Hey there support,

    I just happened upon this post and it got me thinking. Is it okay for me to have the google analyics code in global custom JS section in the customizer? Or should I also place the code in functions.php file?

    Thanks!

    #889470
    Christopher
    Moderator

    Hi there,


    @webhorse413

    Please add your code just after following line :

    <!-- Your Google Analytics Code Go Here -->


    @marketingtransloc-com

    Analytics code should be added to functions.php file or it should be added via ‘Google Analytics’ plugin.

    Hope it helps.

    #890167

    Thanks. I have other tracking code also, what’s the best way to include those on our website?

    #890787
    Jade
    Moderator

    Hi there,

    just add this in your child theme functions.php file

    add_action( 'wp_head', 'x_google_code' );
    
    function x_google_code() {
        
        if ( is_page(8) ) { 
    
        ?>
     	<!--Add Your Javascript Below this line for page 8 -->
    
    	<!--Do not modify anything below this line-->
        <?php
        }
    
        if ( is_page(9) ) { 
    
        ?>
     	<!--Add Your Javascript Below this line for page 9 -->
    
    	<!--Do not modify anything below this line-->
    
        <?php
        }
    
    }
    

    Replace the #8 and #9 to the page ID of the page you only want to add the script to.

    Guide on how to get post/page ID -> http://theme.co/x/member/kb/how-to-locate-post-ids/

    Hope that helps.

    #893813
    WebHorse413
    Participant

    Hello, I did as you said but when I scanned my site it came back as having no Google Analytics. My code looks as follows at the very end of my funtions.php file:

    });

    add_action( ‘wp_head’, ‘x_google_code’ );
    function x_google_code(){
    ?>
    <!– Your Google Analytics Code Go Here –>
    <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-69475208-2’, ‘auto’);
    ga(‘send’, ‘pageview’);

    </script>
    <?php
    }

    Is this correct?

    #894776
    Rupok
    Member

    Hi @webhorse413

    Your code seems correct and should be added on the page. Kindly check the source code. You could also provide us the URL so that we could check too.

    Cheers!

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