Support » Fixing WordPress » where in php to put Google Analytics

  • senoritagracia

    (@senoritagracia)


    I have the code from Google Analytics but I don’t know where to put it, can anyone help please?

    Here are the directions given by Google:
    This is the Universal Analytics tracking code for this property. To get all the benefits of Universal Analytics for this property, copy and paste this code into every webpage you want to track.
    This is your tracking code. Copy and paste it into the code of every page you want to track.

    <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', 'UA-49310797-1', 'graciamariastudio.com');
      ga('send', 'pageview');
    
    </script>

    PHP ImplementationOPTIONAL
    Create a PHP file (I tried ‘new stylesheet’ but it doesn’t show up in the Editor side bar) named “analyticstracking.php” with the code above and include it on each PHP template page. Then, add the following line to each template page immediately after the opening <body> tag:
    <?php include_once("analyticstracking.php") ?>

    Im very lost in php, I am slowly learning how to use it though, just be gentle with jargon.
    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • You should create that analyticstracking.php file outside of WordPress and then upload it to the server.

    However, if that is abracadabra to you and you just want to add it through the WordPress editor, you can add it the code right after the <body>-tag in header.php.

    Abhishek Ghosh

    (@abhishek_ghosh)

    Hello Original Poster named senoritagracia,

    I have the code from Google Analytics but I don’t know where to put it, can anyone help please?

    You are a new WordPress user. Just perform a search with your question on the Search WordPress.org Q above the blue download WordPress button link (right side of navigation bar). You will get lot of questions and answers.

    There are lot of Free WordPress Plugins like Google Universal Analytics which are very easy to use. You will need to put the number (UA-4******7-1 in your case) only on a field after activating the plugin.

    Alternatively, you can use Header and Footer plugin. You need to paste the whole script in this case :

    <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', 'UA-4******7-1', '******astudio.com');
      ga('send', 'pageview');
    </script>

    The same plugin can inject other scripts, meta tags etc.

    Do not create analyticstracking.php like common named .php file to avoid various possible complicated situation difficult to solve with your assumed knowledge. Almost everything has free Plugins => http://wordpress.org/plugins/ but do not install hundreds of plugins, btw…
    Creating PHP file method is for older websites or custom e-commerce websites, not for us. Do not touch any Template file on live working WordPress website with your current experience. Please read the documentation here http://codex.wordpress.org/Main_Page and install WordPress on your computer (localhost) to test things like plugins etc. Never touch that Editor button for Editing PHP codes within WordPress, we usually edit from FTP to avoid various issues. Plus you need to know about PHP, wordpress hooks etc.

    There is handbook for the users here : http://make.wordpress.org/support/user-manual/ (Please do not ask question there, the subdomain is for developers not the end users.)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘where in php to put Google Analytics’ is closed to new replies.