Track IP Addresses In Google Analytics

UPDATE: Apparently this is against Analytic’s TOS. So if you are thinking about collecting this data it might be wise NOT to.

Now that Google Analytics allows multiple custom variables it is much easier to track your users ip addresses. Simply insert the following code in your analytics tag:

pagetracker._setCustomVar(1, "IP", "<?php echo $_SERVER['REMOTE_ADDR']; ?>", 2);

To break down each variable:

  • SLOT – 1 refers to the Index or “slot” – you can have up to five slots
  • NAME – IP Address names the variable “IP Address” in Analytics
  • VALUE – The php script echos the visitor’s ip address as the value for the above named variable
  • SCOPE – The final “1” defines the scope of the variable. Possible scopes include:
    • 1 – visit level
    • 2 – session level
    • 3 – page level (default value)

There is a lag of about 12-24 hours before the IP addresses will show in analytics. To access this data click on Visitors->Custom Variables. A variable titles “IP” should appear in the list. Click on it to get detailed statistics. It should look something like this:

 

Google Analytics with IP Tracking

 

Go here to read more about Custom Variables in Google Analytics.

UPDATE: Apparently this is against Analytic’s TOS. So if you are collecting this data it might be wise NOT to.

The applicable section is:

“7. PRIVACY . You will not (and will not allow any third party to) use the Service to track or collect personally identifiable information of Internet users, nor will You (or will You allow any third party to) associate any data gathered from Your website(s) (or such third parties’ website(s)) with any personally identifying information from any source as part of Your use (or such third parties’ use) of the Service. You will have and abide by an appropriate privacy policy and will comply with all applicable laws relating to the collection of information from visitors to Your websites. You must post a privacy policy and that policy must provide notice of your use of a cookie that collects anonymous traffic data.”

Lower Your Bounce Rate With One Line of Code

While reading through the Google Analytics Event Tracking Guide, I came across this nugget:

In general, a “bounce” is described as a single-page visit to your site. In Analytics, a bounce is calculated specifically as a session that triggers only a single GIF request, such as when a user comes to a single page on your website and then exits without causing any other request to the Analytics server for that session. However, if you implement Event Tracking for your site, you might notice a change in bounce rate metrics for those pages where Event Tracking is present. This is because Event Tracking, like page tracking is classified as an interaction request.

Of course having read through several SEO related posts identifying bounce rate as a ranking factor (or at a minimum a quality signal), I devised a way to game it.

<div id="header" onMouseOver="pageTracker._trackEvent('bounce', 'bouncecheck', 'Look Ma No Bounce');">

I figure a mouseover on my header will probably be triggered enough to dramatically drop my bounce rate without looking too artificially manipulated. Plus I wonder if a body onLoad statement would be overkill, or trigger faster than the gif request. Anyway after implementing this for one day you can see the huge difference below.




Now while my method is obviously solely aimed at gaming the system, there are some legitimate uses. A few examples that come to mind where firing off an event make sense are video plays, if the end of a javascripted animation, newsletter signups, rss subscribes and there are probably a thousand more.