How to install Google Analytics on a PHP based site?

Discussion in 'PHP' started by cavemanlawyer15, Aug 6, 2007.

  1. #1
    My client uses a CMS for all his web content development. I tried dumping the Google Analytics code at the bottom of each section in the CMS, but clearly this is still way too far up the page for Google to make use of it. So next I tried getting in behind the CMS via FTP, but found that PHP files aren't exactly east to edit.

    Is there a good PHP editor out there for Mac OS X? Or a better way to get this @#$ code in there and get on with life?

    Thanks
    PB
     
    cavemanlawyer15, Aug 6, 2007 IP
  2. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    The solutions is actually easy. I am not, however, familiar with an easy to use editor. Simply put, php files can be divided into two types: those that generate HTML and those that do not. HTML, is of course what is eventually presented to your site visitors and what dictates the appearance of the site. All you need to do is go over the php files, open them with any text editor (notepad will do). Then look for the end of the HTML document - the closing tags </body> and </html>. Place the analytics code right after the </body> tag and that's it. It's actually very easy. The only problem might be if the php itself generates the </body> tag. If that is the case, you need to search for something like:
    echo "</body>" or print "</body>" and place your analytics code as follows:

    echo "<analytics code....>"

    I hope this helps
     
    NoamBarz, Aug 6, 2007 IP
  3. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Can you get into your website's file manager while online? For example, if using Cpanel hosting, there is a file manager you can go into in the cpanel and edit your files. Find the main file in the CMS that as the main </body> tag at the end and insert your analytics code as specified. If your CMS implements templates you would be looking probably for the footer file so that the analytics code is implemented site-wide.
     
    einsteinsboi, Aug 7, 2007 IP
  4. Providence

    Providence Peon

    Messages:
    568
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think you will still need to edit the pages you want to have analytics on. Create an include file and edit all pages.
     
    Providence, Aug 7, 2007 IP