mxmCounter

mxmCounter - A Simple Zope Hit Counter

A simple filesystem based hit counter for Zope, for multiple pages.



Current Version

    "1.1.0"



Installation

    You should install this product as usual.  Unpack the archive with 
    all contained directory information into your Zope products 
    directory <ZOPE>/lib/python/Products or <INSTANCE_HOME>/Products. 
    Restart Zope.
    
    Create an instance in the root of your zope server through the 
    zmi. It will automatically get the id "mxm_counter".



Usage

    On any page where you want a hit counter you should insert a few 
    lines of code.
    
    The most simple ZPT version is::
    
        <span tal:replace="python:here.mxm_counter.count(here)"/>


    A more involved, but more graphically pleasing version could be::
    
    
        Hits:
        <span style="font-family: courier; 
                     border: 1px solid black; 
                     background-color: lightgray;
                     padding: 0px 4px;"
              tal:define="count python:here.mxm_counter.count(here)"
              tal:content="python:'%06i' % count">
        0000001
        </span>
    

    In dtml it can look like::
    
        <dtml-var "mxm_counter.count(this())">
    
    
    In rare situations you might want to show the count while not 
    increasing it. Then you can write::

        <span tal:replace="python:here.mxm_counter.get_count(here)"/>
    
    
    You should notice that you can insert the counter code in 
    something like a footer script, and the counter will work 
    automatically on all files that uses the footer.


Properties


    
    "Properties screenshot":img:files/mxmCounter_properties.gif


    **title**
    
        Well, what can I say ....


    **ips_to_ignore**
    
        List of ip adresses to ignore. Meaning that they don't 
        increase the counter when they visit a page.
        
        Examples of valid patterns::
        
            127.0.0.1
            192.168.0.42
            192.168.0
            192


    **count_once**
    
        When this is checked it only counts a browser once for each 
        browser session. It stores a cookie in the browser that 
        expires when the browser is restarted. There is not really any 
        *right* way to do this. This was just the way I choosed to do 
        it.


    *save_interval*
	
	    The counter saves the hits in memory when the number of 
	    uncomitted hits reaches the save_interval. Any hits that are 
	    not saved when zope is closed down, are lost. With the default 
	    setting of 100, it means that it saves the hits to disk once 
	    every 100 hits.
	    
	    It also means that you can loose up to 100 registered hits 
	    when zope is shut down.
	    
	    On the positive side it is a fast approach that doesn't grow 
	    the zodb.
	    
	    The counters are stored in the var directory in a file called: 
	    'counters.dict'
	    
	    If not loosing hits is very important to you, you can set the 
	    value to 1. But then you will write the 'counter.dict' for 
	    every page count.
	    
	    This should be fine for small sites with few hits.
	    
	    The interval is overall for the site. Not pr. page. You don't 
	    need 100 hits on one page before it saves the counters, but 
	    100 hits on any of the counted pages combined.


counter management/overview page


    "Counter management/overview":img:files/mxmCounter-setCounters.gif


    The view tab in the zmi will show a very simple page, with paths 
    and counts. Sorted by number of hits in reverse order. You can use 
    this if you don't want visible counters on the pages.
    
    You can avoid showing the count on a page by using this code::
    
        <span tal:define="count python:here.mxm_counter.count(here)"/>
        
    It will still increase the page count, but it will not be visible. 
    You can then see it in the view tab of 'mxm_counter'.
    
    
    You can also set the count of a page to any value. If you set the 
    count to 0, the page is deleted from the counter, until someone 
    visits it again.
    
    *Tips: When you press "Set" the counts are saved to disk. So if 
    you want to shut down your site, and don't want to risk loosing 
    any counts, you can select a page and give it that same count as 
    it allready has. *


Methods

    You can call the following methods on the tool::

            def count(self, obj, REQUEST=None):
                """
                Increases The count For The Object. It will loose count 
                if object is moved.
                Returns the new count for that page.
                """

            def get_count(self, obj, REQUEST=None):
                "returns the count without incrementing"

            def total_hits(self):
                "Returns the total number of hits on all counted pages"


Important notice


    **There can be only one!**
    
    Notice that only one instance if this product can be installed on 
    a zope server!!!! Trying to install more than one instance will 
    silently fail.
    
    If you install the instance in a subfolder, you cannot later 
    install it in the root folder. So install it there to begin with.
    
    If you accidently install it in a subfolder, and has counts you 
    don't want to loose, you can do it by first renaming the 
    'counters.dict' in the var directory. Deleting the mxm_counter 
    instance, rename the 'counters.dict' back to the original name, 
    and create a new mxmCounter instance in the root folder. It will 
    then use the old 'counters.dict'.
    
    Probably this product should be made placeless. Well that is for 
    another version.
    

    **There might be issues with (multiple) ZEO clients**
    
    I don't know. I have not tested it in this setup yet. Please try 
    it and give me feedback.



License: GPL

    Full license text "here":http://www.fsf.org/copyleft/gpl.html


download

    You can get it here: "mxmCounter.1.1.0.tar.gz":files/mxmCounter.1.1.0.tar.gz