Get the files

Dowload

Get the latest version:
Download »

Extract

Extract the js file somewhere below webroot on your webserver.
I prefer a folder "js" or "javascript".


Basics: track a visit

What You need to do is:

  1. Load the javascript file in the header.
  2. At the end of the html code init an object with new localstats().
  3. Call the the track() method. This adds the current page and time to a local browser variable.
  <!doctype html>
  <html>
  <head>

    (...)
    <script src="/javascript/localstats.class.js"></script>
    (...)

  </head>
  <body>
    (...)
    page content ...
    (...)
    <script>
        var oStats=new localStats();

        // track the request
        oStats.track();
    </script>
  </body>
  </html>

Basics: show a counter

    <p>
        your page requests so far:
        <span id="spanCounter"></span>
    </p>

    <script>
        var oStats=new localStats();
        document.getElementById("spanCounter").innerHTML=oStats.getCountTotal();
    </script>

show statistics graph

<!DOCTYPE html>
<html>
    <head>
        <title>localstats-Demo</title>
        <script src="/axel/javascript/localstats/localstats.class.js"></script>
        <style>
            .localstatsbar{background:#ace;}
        </style>
    </head>
    <body>
        <div>Demo of statistics</div>
        <div id="stats">[please wait ...]</div>
    <script>
        function renderStats(){
            var sHtml='';
            sHtml+='<h2>LocalStats</h2>';
            var oStats=new localStats();
            var myDate=new Date(oStats.getCountSince());

            sHtml+='requests: <strong>'+oStats.getCountTotal() + '</strong> '
                +'of <strong>'+oStats.getPageCount() 
                +'</strong> different pages since <em>' + myDate + '</em> '
                + oStats.renderTopTable(20)
                ;
            document.getElementById("stats").innerHTML=sHtml;
        }

        window.setTimeout("renderStats()", 200);

    </script>
    </body>
</html>

statistic







Copyright © 2022 Axel Hahn
project page: Axels Webseite (de)
results will be here