Google Analytics from LocalHost

If you want to integrate Google Analytics with a site, you want it all working before the site goes live. Even better: integrate it from the convenient, secure localhost server on your dev box.

Prerequisites:

  • a gmail account
  • a Google Analytics account
  • a web server hosting at least one html page on your local PC
Create An Account

Your Google Analytics log-in can be associated with multiple “Accounts” which you define. I organize mine according to what server it tracks and give them the same name as the server machine name. You may decide it is best to segment by customers in order to keep data separated and name it after your customer.

Within an account you define one or more “Properties” which define what you intend to track. If you have a customer with multiple sites or a site and a mobile app you can keep them under a single account using properties to enter distinct URLs etc. I add a property and name it for each site I develop on a given server.

Analytics Organization

To create a new account you have to create at least one profile which will be the default. Profiles are for filtering reports and data and are not really relevant for localhost tests except that you need to make one to see reports:

  1. Log into Google Analytics
  2. Click the Admin tab at upper Right.
  3. Click Profiles tab.
  4. Click + New Profile
  5. Enter profile name and set time zone and country
  6. Click Create Profile
Google Analytics Property

Google Analytics Property

localhost
To associate a site with a property:

  1. Click Property Settings tab
  2. Enter Property Name. I used my machine name + “” to test a page located at my localhost server’s web root.
  3. Enter Default URL: I use my site name and end with “.com” You used to be able to enter .localhost but that doesn’t work as I’m writing this.
  4. Default Profile: the profile you want the Property to be associated with. If you have more than one dev box or image, pick the one that hosts the site.
  5. I don’t think there is a way to complete a site verification, so I only bother with Webmaster Tools Settings when I move an instance of the site onto a live web server I have already verified.
  6. Click Apply
Create A Property

Create A Property

Change some settings of the property to work with localhost:

    1. Click Tracking Code tab
    2. Scroll down to Website Tracking section
    3. Click Standard tab
    4. Under “1. What are you tracking?” tick Multiple top-level domains radio button
      What Are You Tracking?

      What Are You Tracking?

    5. Under “2. Paste this code on your site” copy the code from the box indicated right below and paste in a text editor
      GA-Code

      GA-Code

    6. Find the line that reads similar to this: _gaq.push([‘_setDomainName’, ‘[yourSiteName’]);
    7. Replace with this: _gaq.push([‘_setDomainName’, ‘none’]);
    8. Paste the final edited code so that it is the last script before the closing head tag in your default site page, such as index.htm.
    9. I added a button to prompt sending a call to analytics without refreshing the page using the following html: 

 

  1. Load on your browser and click the button.
Wait for it
Expect to see this for awhile before your clicks are registered by Google Analytics and displayed on your Overview:

No Visitors

No Visitors : (

No Tracking

No Tracking?

Another bonus of working from your own server is that you are in control of the events that occur so the signal to noise ratio is effectively 0. My click is the one and only click today!

visited

visited : )

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *


seven × 4 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.