View advanced visitor data

bsimon - March 11, 2009 - 08:47
Project:Statistics Advanced Settings
Version:6.x-1.4
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Issue tags:anonymous, anonymous user, statistics, stats, view, views
Description

Here are some Views pages that are much more powerful than Drupal's built-in stats pages in many situations - particular for tracking anonymous visitors. These work very well together with Statistics Advanced Settings, although they don't actually rely on the module.

If you have Views, this add on is extremely easy to install. It doesn't change anything. It doesn't require any extra code or database tables. It just makes better use of what's already there.

Advantages over Drupal's standard statistics pages:

  • You can track individual anonymous users to see how they're using your site. You can instantly see where they came from and what pages they looked at. Just click on an IP address to immediately see all pages visited by a user at that address.
  • You can see a visitor's referring page and IP address on the same page and timescale, unlike the default stats
  • A country flag is displayed for each visitor (flag graphics are loaded from hostip.info)
  • You can also click on a page title to see all visits to that page (similar to Drupal's built-in Track function, except this also shows you each visitor's IP and country)
  • The main referrer links are not clickable. This prevents inexperienced admins from clicking on bogus referrers (referrer spam). Clicking these spam ref links is potentially very bad because it sends your own site back to the spammer, as a referrer, This may make them believe your stats are publicly viewable and encourage them to spam you even more. The small '+' sign provides a clickable link to the referrer if you need it. Also, mouse hover on this shows you the full link.
  • You can easily edit the View yourself to customize the display. For example: make referrer links clickable, rearrange columns, show more or less data, display session IDs, expose filter to user, etc.

Disadvantages:

  • Currently, it doesn't show user names (so Drupal's built-in tracking pages are better for monitoring logged in users, in most cases).
  • Appearance could be improved (especially the odd ________ after 'Time', which is a cheap hack to prevent the time and date breaking onto two lines). This View looks best with a theme that is reasonably wide or fluid/expandable.
  • In a few cases apostrophes and some complex foreign language characters (Chinese, etc) are replaced by their html entity code (hovering over the + sign should display correctly). Possibly a bug in Views module.

You need to have the Views module installed first, obviously. http://drupal.org/project/views

Future improvements:

If you want full domain names and not just numerical IP addresses, it should be very simple to integrate the View with the Whois lookup module (http://drupal.org/project/whois) and provide a link to look up domain name automatically (but its probably not so simple to display the domain name inline on the same page).

Views doesn't seem to make user names available in Access Log mode. Probably there's some way to use PHP to look up the user name from the Session ID, but I don't yet know how...

Hostip.info data is incomplete for a few IP ranges. Report this at http://www.hostip.info and they should add it.

Installation

The code and installation instructions are in the comment(s) below.

#1

bsimon - March 11, 2009 - 08:53

If you already have the Views module installed, then installation is very simple. It won't alter or remove anything else.

1 Go to admininistration -> views -> import
2 Copy and paste in the code from the attached file: Advanced_visitor_data_view.txt. A title isn't required, I think.
3 You'll see the edit page for the new View you've just created, stats_access_log
4 Optional: By default this View should only be visible to people with the default Administrator role (role id #3 normally). You can check this now by looking at Defaults -> Basic Settings -> Access (click on the asterisk/gear wheel button to edit). Giving access to non-admins or anon users is not recommended.
5 Click the Save button

You can now access the new stats view page at yoursitename.com/stats-view/main

The initial view displays a list of all hits on your site, sorted by time. Click on IP addresses, page titles or the country flags for more data.

I'd suggest adding a menu item so admins can access the page easily.

AttachmentSize
Advanced_visitor_data_view.txt 10.28 KB
 
 

Drupal is a registered trademark of Dries Buytaert.