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.
add_action('wp_head','my_analytics', 20); function my_analytics() { ?> YOUR GOOGLE ANALYTICS TRACKING CODE HERE (looks like <script type="text/javascript">.....</script> ) <?php }
75 thoughts on “Adding Google Analytics to Customizr”
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 ?
Hi,
In that case, you can replace the hook.
Change this line
to this
@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 ?
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.
@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!
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!
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
Hi, what are the re-marketing tags? could you provide an example ?
Thanks 🙂
Thanks for your reply,
I was looking at setting up google re-marketing tag for retail on our website.
This what i was trying to accomplish https://support.google.com/adwords/answer/3103357?hl=en
However, I am not looking at it anymore as there are restrictions in setting up the same for healthcare.
Thank you for this great theme
Regards,
Suresh Jaladanki
Ok got it. Thanks 🙂
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: http://greenfongroup.com/greenknow/
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 🙂
I will strongly recommend you to install this plugin instead of creating another child theme.
Hi Caro,
you can open a new topic here.
Copy the whole content of your child-theme functions.php (the not working one) in pastebin.com and then put the link in your topic.
Most likely is some small error in the code.
Cheers
p.s.
to Pratik Sinha:
she already uses a child theme, why do you say “another child-theme” ? 😀
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 :
add_action(‘wp_head’,’my_analytics’,1,20);
function my_analytics() { ?>
alert(“a”) )
<?php}
don't work. what solution I can try?
thanks.
Hi Deborah,
Thanks for getting in touch !
As a pro user, would you mind opening a new topic in the pro support forum about this ?
Our support team will do its best to help !
Thanks!
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’,’]);
/>
}
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
take a look here…
http://presscustomizr.com/snippet/adding-google-analytics-customizr/
I have already inserted the tracking code in the file functions son and my theme works. I am now setting goals google analytics and one of my goals is to measure the comments of my blog, the question is what code I need to insert into my theme for google analytics measure the comments of my blog?
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?
Hi Nico,
I can’t found Child Themify botton after activate this plugin,
Thanks for answer
Hi Ulya,
Did you try to use the Customizr Child theme, it may be simpler to use.
I hope this will help,
Cheers
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!
I fixed it!
Hi, thanks Travis.
Could you please quickly explain how you did fix this ?
Thanks (useful for users facing the same issue !)
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!
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.
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.
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?
Hi, this is a common error in php.
You might want to read this quick guide about common php errors : http://codex.wordpress.org/User:Skippy/Common_PHP_Errors
Hope this will help
Please disregard the above post…I just had to log into the FTP and reupload the backup…
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?
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
Hi Patricia, you might want to search Google Analytics plugins in the Wordpress.org plugin repository. You’ll find what you need!
Hope this helps
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~
Hi Blake,
you’ll have to add the javascript code to get your Google Analytics working.
Thanks!
Nicolas sorry just wipe out all these attempts. I can’t get the code wrapper to display my code.
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:
Sorry not sure why the code wrapping didn’t display all of the code in step 1 above. Here it is again:
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.
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.
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
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.
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
Hi Pat,
The functions.php file is located in the child theme in the following path of your website : wp-content/themes/customizr-child.
If you are new to Customizr (and WordPress), you might want to read this short guide on how to customize Customizr.
I would also strongly recommend that you take a look to the following resources :
1) the Customizr theme documentation
2) the FAQ
3) how to make a research in the Customizr user’s forum
4) the Customizr code snippets
If you still have issues then post a new thread in the the Customizr user’s forum and we’ll do our best to help you.
Hope this will help !
Thanks so much Nicolas for responding! I’m a qualitative researcher so this kind of coding etc isn’t really a match for me but I need to do it!! I will read through all the resources and hopefully figure it out but grateful to know there is help here :).
Pat
Thanks for all your hard work. The Google analytics work great and your theme is very good.
Thanks for your feedback @Eloy. Thanks for the donation too. Much appreciated!
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
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’).
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
*/
?>
Hi Rick, you should add this code in your functions.php file.
More about customizing the theme here : http://www.presscustomizr.com/customizr/how-to-customize-customizr-wordpress-theme/
Best
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?
Hi Richard, yes this should also work.
Thanks
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
Hi, you might take a look to these SEO ressources for WordPress :
http://codex.wordpress.org/Search_Engine_Optimization_for_WordPress
Best and thanks for using the theme
hi
I installed a plugin to do that, but, visits from mobile version don’t work
How to resolve?
Hi David, you might post a thread on the plugin’s forum about that.
Thanks
Make that *2* people on the forum who added it to the theme’s function.php 🙁
Done! Thanks
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.
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!
Hi Sandra, the best place to copy this code is the the functions.php file of a child theme. More informations about child theme here :http://www.presscustomizr.com/snippet/creating-child-theme-customizr/
Download the Customizr’s child theme here : http://www.presscustomizr.com/extension/customizr-child-theme/
Hope this will help you
PS : I’ve received your Twitter notification!
I did a lot of reading and I figured a lot out. ElectricFeet also helped me. It’s now running smoothly. Thanks! 🙂
Great! I am glad to read that.
Enjoy the theme.
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?
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:
Here is the code:
GA Tracking Code Insert Here
Please refer to wordpress forum for code: http://wordpress.org/support/topic/google-universal-analytics-tracking-not-installed?replies=1
Thank you so much Nicolas!!
And Congrats for the amazing theme! 🙂
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.
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
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?
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