How to use Google Analytics with PHP-Nuke

Website statistics can be used to help determine how to best develop the website.  PHP-Nuke includes its own tracking module- you can find more information on this module in Using the PHP-Nuke Statistics. However, if you want a much better and complete solution, you should incorporate Google Analytics into the PHP-Nuke website.  This will require that you have an account with Google Analytics, and also do a little editing to the site code.  The following article reviews how to add Google Analytics to your PHP-Nuke website.
 
NOTE: Before making the following changes, be sure that you make a complete backup of your website. If you require information and you used Softaculous to load your site, see the following article: Backing Up and Restoring Your Website using Softaculous.  You can also make a backup using FTP – see How to Create a Backup Using FTP.
 
 

Adding Google Analytics into your PHP-Nuke Website

 

Create Google Analytics Account and Get Tracking Code

 
You will first need to create a Google Analytics account, if you intend to use Google Analytics in your website.  After your account has been created you will be able to obtain the tracking code.  The code will be needed and should be on all pages that you intend to track.  Since the HEADER.HTML for PHP-Nuke websites is typically on every page, you can place the Google Analytics code within that file.  
 
  1. Go to Google Analytics and setup your account.
  2. Google provides the code that you will need for tracking your website data. Save this code for later use (or leave the window with the code open so that you can access it later).

The Tracking Code will look like the following:

<script type=”text/javascript”>
 
  var _gaq = _gaq || [];
  _gaq.push([‘_setAccount’, ‘UA-12345678-1’]);
  _gaq.push([‘_trackPageview’]);
 
  (function() {
    var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
    ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘https://www’) + ‘.google-analytics.com/ga.js’;
    var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
  })();
 
</script>

 

Open the Web Site File(s) That require the Code

 
In order to access your files, we will be using the Cpanel File Manager.  You will need to know what theme you are using.  If you know what theme you are using then skip the first two steps.  
 
  1. Login to the PHP-Nuke Administration Back-end and click on PREFERENCES.
  2. Scroll to the bottom of the page and go to the Web Site Configuration section.   Click on the THEMES option menu.  It will then display the theme being used in the line labeled “Default Theme for your site.”
  3. Login to your Cpanel as an Administrator
  4. Go the File manager and navigate to the installation files for PHP-Nuke.
  5. Look for the THEMES folder.  Double-click on the theme folder (inside THEMES) that matches the theme that you identified earlier. 
  6. Click to highlight the HEADER.HTML file.  Click on CODE EDITOR (or EDIT) at the top of the File Manager in order to edit the file.  
  7. Highlighted code indicates Google Analytics code

    Obtain the code that you received from Google and paste it into the editor immediately before the comment that says “close header”.  This is demonstrated in the screenshot at right.

     
  8. Click on SAVE CHANGES in the top right hand corner to save your entries.
 
This completes the addition of the Google Analytics code to your PHP-Nuke website.  Check the Google Analytics website for further options to add the tracking code (there are several options) in case your website theme cannot use the above method.  If you require information on learning how to use Google Analytics, please to go Learn Google Analytics.

AC
Arnel Custodio Content Writer I

More Articles by Arnel

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+