Adding Google Analytics to Customizr 51

Note : This snippet applies to Customizr version 3.1.x and below. It may not work with version 3.2+. Use with caution on 3.2+ and check the availability and type of the hooks in the Customizr hooks API.

Here’s a quick snippet to add Google Analytics tracking’s code to your website.

Where to copy/paste this code? => in your functions.php file of a child theme. I strongly recommend you create a child theme. Download a start-up child theme here.

Everything you need to know about child theme with Customizr here.

 

 


About Nicolas

My name is Nicolas Guillaume (nikeo). I am the developer of the WordPress Customizr Theme. This website is a discussion platform, your comments are welcome!


51 thoughts on “Adding Google Analytics to Customizr

  • Reply
    ben boldt

    Can the alternative method of adding the google code in the header section be used? If it can what need to be done?

    Thank you

  • Reply
    ben boldt

    Hello again, My site using the customizr theme is a subdomain of another site. The subdomain site does not have the “function.php” file showing. Can the google meta tag still be added somewhere so that the site can be verified?

  • Reply
    Paula

    Hi,

    I had done what you put on this post and when I save the functions.php with the new code the page can not be uploaded, and I can´t access to the wp-admin. I don´t know what happenned. Please I need some quick help, I am a little bit worried.

    Thank you so much.
    Paula.

    • Reply
      Nicolas Post author

      Hi Paula, there must have been some error in the code : upload a new clean version of your functions.php to your server.
      Hope this will help.
      PS : if you still have issues :
      1) always make a backup of your files before starting to develop.
      2) please continue this discussion on the WordPress forum

  • Reply
    John

    My website is letoutsidein.com. I followed the code snippet by nikeo, and cannot seem to get tracking installed. Here is the code, placed in a functions.php child theme:

  • Reply
    Stamatis Kanatas

    Hello!Since i upload my site from localhost to internet host i cant edit the functions.php file because i dont have the permissions…What goes wrong?

  • Reply
    Sandra

    Could someone add a more detailed example of where to add the code in the functions.php file? I’m not very knowledgeable in .php. Thanks!

  • Reply
    ElectricFeet

    Hi Nicolas, could you update to say “Use the following code in the functions.php file of your child theme:”
    Someone on the forum tried adding it to the theme’s function.php.

  • Reply
    ebwally

    I”m so confused! I’m just a layman with a dream. Hi Nicolas – thanks for your beautiful theme. I love it – though I’m not using it to its full potential I’m sure. I”m writing because my site http://www.brooklynartsforkids.com does not come up when you google Brooklyn Arts for Kids – I have tried to verify and do what Webmaster Tools suggested but nothing is working. Help! I don’t know where to add tags to a page or how to easily alert Google of our whereabouts. Thanks for any and all help. With best wishes, ebwally

  • Reply
    Richard

    Thanks Nicolas I’ve spent half a day scouring the net trying work out how to get verified. I should’ve came here for advice first. ;)

    Can I use the same snippet for Bing and Alexa?

  • Reply
    Rick Cantu

    Hello. Newbie at HTML here. I added the following to header.php as Google wanted me to add (and maintain) the code below in the header section of my website for domain verification purposes. When I added the code as shown below, the text boxes in the sliders were thrown out of position (they were no longer appearing centered). Once I removed the code, everything looked normal again. What am I doing wrong? I played with some plugins that were supposed to lead to Google reading meta tags on my site but they didn’t work. Thanks for your help!

    ***CODE ADDED***

    ***THIS IS WHERE I ADDED IT***

    <?php
    /**
    * The Header for Customizr.
    *
    * Displays all of the section and everything up till
    *
    * @package Customizr
    * @since Customizr 1.0
    */
    ?>

  • Reply
    Sean Smith

    Does the same go for using the Google Webmaster Tools code for verifying ownership of a website? Should I use the same code and just replace the analytics … with the ?

    Google Webmaster Tools tells me to place the within the of my homepage. But of course the head is added to the header.php via a hook in Customizr theme so I’m not exactly sure where to put this code.

    Thanks in advance for any advice.

    Sean

    • Reply
      Nicolas Post author

      Hi Sean, I confirm that you can use the same snippet to handle the Webmaster Tools verification.

      You can just add the conditional code to display this code only on home page, with the Customizr built-in helper : tc__f(‘__is_home’).

      Best

  • Reply
    Belqadi

    I hope this email finds you well. Many thanks for your help. Great Work. I love it!! I have a question please. Many folks waiting this. Could you please demonstrate where and how I insert the Google Tag Manager Snippet into your Child Theme?

    Please note, I don t want to use a Google Tag Manager plugin for that as I believe it has some limitations. It is important as Google Tag Manager will cover everything: Analytics, Marketing, Remarking and more. Please note I installed Customizer Child with only style.css created.How Can I create Functions.php with Filemanager plugin? Could please show me how in simple steps ? Sure it will be a great help for me and many other. THE FOLLOWING is Google Tag Manager Snippet.

    (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({‘gtm.start':
    new Date().getTime(),event:’gtm.js’});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!=’dataLayer’?’&l=’+l:”;j.async=true;j.src=
    ‘//www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,’script’,’dataLayer’,’GTM-T8RVRN’);

    I am impatient to hear your help.
    Best of regards and many many thanks for everything in advance.

    • Reply
      Pat Camillo

      I am also really struggling with trying to set up google analytics. I installed the child theme plug in as recommended with no problems. However, it appears that if I activate that, then the parent theme is inactivated – so I’m confused about that. I have my code for google analytics to insert and apparently I need to insert it into function.php but for the life of me I can’t find that anywhere! ANy help would be greatly appreciated!!!
      Pat

  • Reply
    Joe

    Nicolas,

    When I use the Editor it allows me to choose between themes. If I choose Cutomizr it shows me all the editable php files including functions.php for the Customizr theme. However, as we know we should not enter the Google Analytics code there, because it will disappear when a theme update is made.

    However the problem is that when I choose my child theme from the list of themes to edit, the Editor only shows me one editable file, style.css. This is fine for making style changes but it doesn’t help in cases where files like functions.php need to be edited in the child theme. Is there any change I can make so that the entire list of editable files will show up in the Editor for the child theme too. If this is something users cannot do, then perhaps you should consider making a change so that at least the functions.php is editable in the Editor for a child theme.

    Thank you for a great theme.

    Joe

  • Reply
    Joe Gallop

    Okay, I got it to work. The solution is the same for inserting Google Tag Manager Code or Google Analytics Code. Here is what you do:

    1. Create a text file called functions.txt on you desktop and paste the following code into it:

    2. Go to Google Tag Manager or Analytics and copy the code you want to insert.
    3. Select the line in your new file that says:

    then paste the Google Code.
    4. Save and close the functions.txt file.
    5. From your desktop rename the file: functions.php
    6. Open an FTP client or whatever file manager your host provides for your server.
    7. Navigate the files in your website’s directory until you find your child theme’s directory. It may be along a path like this:
    /YourWebsite.com/wp-content/themes/YourChildThemeName
    8. Copy the functions.php file to your child theme’s directory.
    9. Now in a browser open your website, and use the browser’s view source code function to view a page on your website.
    10. Use the find function to search on the page for the

    tag
    11. Somewhere (about 10 lines or so) below the head tag you should see your inserted Google Analytics or Tag Manager Code.

    Hope this helps.

  • Reply
    Joe Gallop

    Step 10 above should say: Use the find function in your browser to search on the page for the word “head”. This should take you to the head tag.

  • Reply
    Joe Gallop

    Sorry not sure why the code wrapping didn’t display all of the code in step 1 above. Here it is again:

  • Reply
    Joe Gallop

    For some reason the code wrapper is only showing part of the code. I’ll try again with a shortened version of the code for step #1 above:

  • Reply
    Blake O'Ruairi

    Hi all.
    Hopefully this wont be out of place to ask as it does directly relate to adding Google analytics/Universal Analytics.
    When I was verfiying this site I’m working on and before I’ve added the customizr child theme to work with (Thank You, awesome piece),
    I used the “Add CNAME” method to verify ownership (i was already in Cpanel, hadnt done that method before, so..) of the site for Google analytics.
    Will i still need to add a code snippet to the child theme, per examples above, to get full Analytics, or will the CNAME method above work fine?
    Sorry if its off thread track, thought just hit me~
    Thanks All!
    Blake~

  • Reply
    Patricia Camillo

    I’ve been struggling for almost a month now trying to add Google analytics to my site. I don’t know any code at all! So even when I read about inserting the code into the php function – I have no idea what you are talking about…….I was able to insert the analytics code very easily when I constructed a different website years ago using network solutions – so I am finding this extremely frustrating and time consuming. I finally found someone who told me to do the following – but I still don’t see it active……although it might take 24 hours. This is what I was told and I would appreciate your thoughts about this approach:
    Go to the “appearance” and click on “widgets”. Choose the text widget and move it to the “Footer Widget Area One”. Insert the code in that box under “Title” and hit “Save”.
    Is this a viable way to get analytics on board with this site? I was told that widgets are not changed with updates and that it shouldn’t be a problem.
    I greatly appreciate your response!
    Pat

  • Reply
    jacob

    Help, I received this error after updating functions.php, my website is down!

    Parse error: syntax error, unexpected ‘<' in /home/content/p3nexnas06_data02/18/2152918/html/wp-content/themes/customizr/functions.php on line 55

    Before made any changes or altercations to functions.php, I copied all the code from functions.php to notepad. I then restored all of the original data from notepad to functions.php. I am still getting this same error. Any ideas what I did or how I can fix this?

  • Reply
    Anne James

    Posted this code snippet and my tracking code into the functions.php file of the child theme, and I’m getting a white page with this error: Parse error: syntax error, unexpected ‘}’ in /home/zymboleditor1/public_html/wp-content/themes/customizr-child/functions.php on line 18
    Any thoughts?

  • Reply
    Hillary Johns

    I tried uploading the Child Theme and everything look great… until I got this nasty message after putting in my Google Analytics.

    Fatal error: Cannot redeclare my_analytics() (previously declared in /home/alpineva/public_html/wp-content/themes/customizr-child/functions.php:22) in /home/alpineva/public_html/wp-content/themes/customizr/functions.php on line 71

    How do I fix this?! A little freaked out right now.

    • Reply
      Nicolas Post author

      Hi,
      You seem to have declared a php function twice. In this kind of situation, you’ll need to re-upload a clean functions.php file to your FTP server.
      Hope this helps,
      Nicolas.

  • Reply
    Travis

    I followed the directions to install GA and it completely broke my site. I can’t even access my child theme to fix what happened. This is the error I get:

    Parse error: syntax error, unexpected ‘<' in /home/uoalogin/public_html/wp-content/themes/customizr-child/functions.php on line 24

    Please Help!

Leave a Comment

Your email address will not be published. Required fields are marked *

Do you need to share some code? To display it in a nice looking syntax highlighter, wrap your code between the following tags (css code in this example) : <pre class="lang:css">YOUR CODE</pre> ( possible code language acronyms : css, php, xhtml, javascript, sql)

You may also use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">