Project:Statistics Advanced Settings
Version:6.x-1.4
Component:Code
Category:task
Priority:minor
Assigned:costas100
Status:closed (fixed)
Issue tags:anonymous, anonymous user, statistics, stats, view, views

Issue Summary

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.

Comments

#1

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

#2

Thank you! I spent hours looking for something like this for my site. It works perfectly!

#3

Hi,

this works for me. I can see user name if I make a "user" view and then use the Access log hostname fields along with the custom www.hostip.info lookup.

One question - how do you get it to print the country name instead of the flag?

Thanks!

#4

One question - how do you get it to print the country name instead of the flag?

It's possible, but probably not very straightforward. I think the View would have to execute an http GET and load a little snippet of text from the hostip server for each IP address, because that's how the hostip.info API works - that's the exact same thing you see happen when you click on one of the country flags.

If you can find a way to put a few lines of PHP in a Views output field, it should be possible. Using a PHP function like file_get_contents or http_get to grab the country details in the background, then more PHP to clean up the text, and display it inline, I guess... all the http_gets could make the page load slower, though

BTW, lejon, if your version that includes the user names is working OK, you could post it here in a comment. It would be more useful than the original version for many people, I think. My foolish mistake was to assume that something called 'Access_Log' must surely be the correct way to Access the Log :\ ... Obviously I am still not wise in the ways of Drupal

#5

Hello, and thanks for this great tip, this view page is very very useful! I post here cause I'd like to know the way to integrate exact user name instead of bare IP addresses.. but I have no idea how to... what does lejon mean in #3, suggesting to create a user filed in the view? If anyone achieved this, I hope the solution'll be posted here soon!!! thanks everybody

#6

when you create a new view, you get an option to choose the view type. Choose the User type and you'll get a different bunch of fields to the Node type.

Good luck!

#7

Thank you .. I tried this out but.. I just can' t understand how it works..

#8

Thanks for the nice View bsimon =)

I did the same thing as lejon described, and converted it to a User type, and added a User Name field, plus some other very minor changes to suit my own personal tastes. I've attached the code to import if it'll help anyone out.

AttachmentSize
Advanced Visitor Data View.TXT 11.7 KB

#9

Thanks a lot, just what I needed!

#10

Category:feature request» task
Priority:normal» minor
Assigned to:Anonymous» costas100
Status:needs review» fixed

Great work, I just installed it and works perfect. Only one small comment:
When I add in a separate browser tab, the link (in my case): http://my site/stats-view/main it shows page not found, but from http://my site/admin/build/views/edit/stats_access_log I can get to the "Edit view stats_access_log" and from there click on the top right corner link View "Page" which take me to the first link.
I guess it must be a question of login in the new tab.
I will add a link to http://my site/stats-view/main somewhere and I think this will solve this minor problem
Thank you for this great feature.

Costas
PS: I just added the link and works like a charm. Also checked it from on other browser (not logged in) and access was denied as expected. Great. Thank you again.

CL

#11

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here