• Hello everybody. I am trying to create my own webpage based on WP and I’ve reached the point where I want to add the GA tracking code to the theme. I found the instructions provided by Nicolas to add the code to the functions.php file of the theme, but it doesn’t work.

    While I’m not very knowledgeable in .php, it amazes me that more detailed instructions are not provided. The code is there, but I don’t think I know where exactly it should be added, and it’s creating parsing errors. I tried creating a custom functions.php file for a child theme and it doesn’t work either.

    I want to keep the child theme scheme, I only need help on how to add the code to the custom functions.php file.

    Thanks in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • I found the instructions provided by Nicolas to add the code to the functions.php file of the theme.

    Yes, it’s not clear. This should be in your child theme’s functions.php. See here; similar problem.

    You need to:

    1. Restore the original functions.php for your Customizr version
    2. Set up a functions.php file in your child theme and
    3. Add your extras to the child theme’s functions.php.

    Let us know what help you need with any of those steps.

    Thread Starter xondra

    (@xondra)

    I figured that I had to create a child theme after much reading. Thankfully I can speak English for all of this, or else I’d be lost 😛

    This time around I added a tiny <?php at the beginning of my functions.php file for the child theme, and it worked. The developer is not very clear on this as probably he feels that his users already know that they have to put a beginning and an ending tag to all .php (well, this is mind numbing obvious now, but it wasn’t when I felt that it was a copy-paste thing). Yes, I did begin by modifying the original functions.php file, as you pointed out in his page.

    GA says it’s installed and working. Thanks for all your help!
    Cheers!

    Xomdra

    It is a free theme that is industrial-strength, though…

    Thread Starter xondra

    (@xondra)

    Sorry, I don’t understand our answer. I know it’s a very good theme.

    Hi all,

    I’m doing this in my child functions.php, but after putting the code in, website no longer works.

    <?php
    add_filter('tc_credits_display', 'my_custom_credits');
    function my_custom_credits(){
    $credits = ' ';
    $newline_credits = ' ';
    return '
    <div class="span4 credits">
              <p> · © '.esc_attr( date( 'Y' ) ).' <a href="'.esc_url( home_url() ).'" title="'.esc_attr(get_bloginfo()).'" rel="bookmark">'.esc_attr(get_bloginfo()).'</a> ·</p> </div>';
    }
    
    add_action('wp_head','my_analytics',1,20);
    
    function my_analytics() {
    <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', '(MY TRACKING CODE HERE)', 'auto');
      ga('send', 'pageview');
    
    </script>
    }

    (Obviously have some additional code at the start to customize the footer)

    What am I doing wrong?

    THANKS IN ADVANCE

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding Google Analytics Tracking Code to Customizr Child Theme’ is closed to new replies.