Adding Google Analytics to Customizr

Note : the following code snippet requires advanced WordPress developer skills. There's no guarantee that this snippet works as is with the latest version of our themes, and with the latest version of WordPress. That's why you need to always test any code snippets in a staging environment before implementing it in a production site.

For Customizr-Pro and Hueman-Pro users: You can paste your Google Analytics tracking code in a specific field designed for that. Please read the following documenation:


If you’re not a developer, you can refer to this complete documentation on setting up your Google Analytics tracking code with a plugin.


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.



Related Snippets you may also like

75 thoughts on “Adding Google Analytics to Customizr

  • Joti Kang

    Nicolas – I’ve implemented the GA code per your snippet instructions in the functions.php file at the very end. It seems to be firing just fine. My question is that it is firing within the tag, but Google recommends we have the tag fire in the very top of the tag. How can we get the google tag we put in functions.php file to fire at the top of the tag, instead of firing in ?

    • Menaka S

      In that case, you can replace the hook.
      Change this line

      to this

      • Joti Kang

        @menakasmenakas:disqus Thanks for the help!

        add_action(‘__before_header’,’my_analytics’, 20);
        I believe this would fire the code before the . I would like to fire the code after and in very beginning of .

        Is there a hook for firing code at very beginning of ?

        • Menaka S

          Hi Joti Kang,
          Did you try it?
          The header is not the same as the head.
          The header is the top portion of the body of the page. So, __before_header is actually beginning of the body.
          Do try it and let me know.

          • Joti Kang

            @menakasmenakas:disqus – I had not tried your suggestion earlier (as you can now tell, I’m a novice. My apologies). I just tried it now and it is firing in the beginning of body just as we needed it to fire!

            Thanks you amazing help!

  • Marius

    Hi Nicolas, and thank you for the snippet.

    I have to ad the meta tag for the google website verification in the tag of the index.php

    Can I use this snippet for this too, as it is?

    Thank You!

  • Suresh Jaladanki

    With Customizr theme, Is there a recommended approach for setting up Google Analytics re-marketing Tag?
    I have currently configured my website for analytics, referring the code as published on this article. It works great, but looking for approach to embed remarketing tags.

    Thank you,
    Suresh Jaladanki

  • Caro

    Hello, I’m triyng to pass GA code by functions.php, i’m not php coder at all, so i have no idea what’s wrong, no matter what I do, the “Warning: Cannot modify header information – headers already sent by …” appears.

    I really need some help here, please 🙂

    The actual location of the site is:

    And this is my code:

    I’ll be doing changes, so may be site will not appear or you’ll find a plugin solution (wich i don’t want) mean while.

    Thanks in advance for read me and for any help you can give to me 🙂

  • Pratik Sinha

    Is it really necessary to install child theme? Dont you have some other way to make it more simpler for adding Google Analytics code?

    Please help me out with installing analytics code for different search engine for this theme, I am stuck and don’t know how to add the code as it is crucial for my website. I am skeptical of adding something extra as website speed is of utmost importance


    Don’t work
    I have customizer pro 1.0.10 on WP 3.5.1
    adding the code on function.php, the page is white and the site don’t work.

    i tried :
    function my_analytics() { ?>
    alert(“a”) )

    don't work. what solution I can try?

  • ANa

    hello, how can I modify this code to add it to my theme functions.php file child?.thanks in advance

    function disqus_config() {
    this.callbacks.onNewComment = [function() _ga.push([‘trackevent’,’formulario’,’enviado’,’]);

  • Ana Castro

    Hello community, I need your help. What code I need to add to my functions file. php my son cutomizr theme google analytics to measure the comments of my blog ?, thanks in advance

  • Antonis Kioupliotis

    Hi there, I run a multisite under customizr, so far everything’s fine, but since Google Analytics by Yoast does not work properly anymore, I’m looking for a non-plugin-solution in order to have separate readings for both sites. The problem is that I only have one function.php file in child-theme and two ‘UA-xxxxxxxx-yy’. Any idea how to fix it?

  • Roman K.

    Hi Nicolas!

    Since WP 4.0 this snippet doesn’t work anymore.
    When I add this code to function.php of my child theme the site doesn’t work at all.

    How and where should I add the google now?

    Thank you!

  • 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!

  • 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.

    • Nicolas Post author

      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,

  • 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?

  • 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?

  • 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!

  • 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!

  • Joe Gallop

    Nicolas sorry just wipe out all these attempts. I can’t get the code wrapper to display my code.

  • 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:

  • Joe Gallop

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

  • 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.

  • 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:
    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

    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.

  • Joe


    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.


  • 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.

    new Date().getTime(),event:’gtm.js’});var f=d.getElementsByTagName(s)[0],

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

    • 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!!!

  • 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.


    • 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’).


  • 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***


    * The Header for Customizr.
    * Displays all of the section and everything up till
    * @package Customizr
    * @since Customizr 1.0

  • 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?

  • 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 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

  • 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.

  • 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!

  • 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?

  • John

    My website is 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:

  • Paula


    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.

    • 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

  • 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?

  • 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

Comments are closed.