1

There are many ways suggested on the internet to install google analytics code on wordpress blog and I would like to clear my doubts.

When I copy the analytics code to the footer.php

  • Will this be available for all pages & post?
  • after theme update, will the custom analytics code still remain

What is the advantage of using google tag manager? Which is the best way and why?

1

Since your question is about installing the google analytics code in Wordpress, I will highly recommend you to install the UA-XXXXXX-X tracking code before the closing head tag "</head>". Just edit the theme header.php file.

You don't need to create a child theme unless you are using someone else's theme that could potentialy be updated or ask you for an update from which your tracking code will be deleted.

  • I know installing the tracking code on header.php. But what if there is theme update and when you download it, the tracking code goes off. We then will have to again copy the tracking code to header.php. What is the better way to achieve this? – Santosh Aug 19 '15 at 9:17
  • 1
    @Santosh The BEST way to achieve this is by creating a child theme. You only need to copy the files you are customizing (like the header.php for example), just create a copy of the header.php file and edit that copy, it will overwrite the original one and will keep you safe for any third party theme author update. What I said is that you might or might not need to create a child theme. If you are using you own theme you might not need to worry about any update. I would not recommend to use an external js file. – Raul Reyes Aug 20 '15 at 2:51
  • @Santosh if satisfactory, remember to mark the question as completed – Raul Reyes Aug 21 '15 at 3:30
1
  1. It will be available on all template files (single, page, index, ...) that call that specific footer (if there's only 1 footer.php every call to get_footer will include that file)
  2. If footer.php is modified by the original creator then yes this is overwritten. A solution is to create a child theme based on the original theme and modify that instead. Another option is to use a plugin for google analytics or write one yourself. This way you don't have to worry about loosing code when the theme files are overwritten.
  • Thank you for answering. point 2 is still not clear to me. As I understand creating a child theme will save the styles, formatting & css but can that store custom code(google analytics code) on page too? How? – Santosh Aug 8 '15 at 13:34
  • With child themes you can overwrite the regular theme functionality. In this case all you need to do is put you Google analytics code in an external js file and load it using a custom functions.Php file in a child theme. Please check this site, it's well explained codex.wordpress.org/Child themes. – alwynW Aug 9 '15 at 13:03
0

I think the easiest way to install Google Analytics and track all your pages on your website is to install one plugin and then just copy paste the code.

One Wordpress plugin that can help you achieve this is Google Analytics.

Once you add the code it will track it on every page.

You can find a nice tutorial about how to install Google Analytics here: http://www.netcrumb.com/install-google-analytics-wordpress-website/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.