Link to home
Start Free TrialLog in
Avatar of Ray Padilla
Ray PadillaFlag for United States of America

asked on

Hit Counter For Client Application

Hola Experts,

I have researched the site and found a few good examples for a hit counter on DOCUMENTS, I'd like to keep track of when the db is opened for viewing, The DB opens to a frameset with 2 frames one frame contains a page with the menu the other frame a view, is there anyway I can put a counter on the menu that will increment everytime a person opens the db. This is a read only DB, users CANNOT make any changes to documents it is fed via an agent from another DB. The requirement is to have a "web" type counter displaying the number of times the db has been read. Can this be done?
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

This requires more than you think... Do users log in into the server? If you have anonymous access things are more difficult: you'd have only IP-address to tell you the "user", and there can be more than one user with the same IP-address! Furthermore, there is no such thing as an "open" from a browser. The user just throws a URL to the server and the server responds. With clever means like Java you might be able to maintain some session, the Domino server might even have the info for you (if you enabled session-based login) but it's still not easy.

The best you can do is make a small page that is only displayed on the very first page that appears when the user opens the database. Just like the About this database page. In that page, the usual way is to have some image opened by a URL that is no image at all; e.g.
    <img height=0 width=0 border=0 src="http: // www.domain.com/db.nsf/countagent?openagent">
and you make sure the agent does a
    Print "[/icons/ecblank.gif]"
at the end.
Avatar of Ray Padilla

ASKER

Users do Log on to the server and the application is strictly client based. So ther eis no way to track when the db is opened? even if we don't display the count on the page? I just need to keep a running tally of how often the app is used, we are trying to get rid of some applications and this would be our method of deterining if the applications are being used. So eventually I would use this on all our apps.
This is Notes client only?? Then you might be able to do it from the database's PostOpen event. See the Designer, under Other, Database Resources.

On the other hand, you don't need this at all. Check your server and look for a database called catalog.nsf. The view Database/By Title contains a document per database. Open a document and look at the last paragraph, Database Activity. Would that do it for you??
That looks like the information we're looking for, is there any way to extract that and put it on my application?
You need it in your application? What do you need then?

The standard views in the Catalog do not contain all databases. If you want to do this without applying changes to the Catalog, you need the replica-id from the current database and use that as an index in the ($ReplicaID) view in the catalog. Otherwise, you have to add a (hidden) view with all database documents.

Check the fields in a database document, to find out which fields you need. Or open catalog.ntf in the Designer.
this might help http:Q_21701916.html
Cezar that increments daily I need to increment every time somebody opens the db and reads a doc.......
that was just to give you an idea how to implement a counter. if you need to increment it when a document is read, create a procedure in a script library (that increments the counter) and call it on PostOpen event of all your forms.

this approach is prone to "save conflict documents". i would suggest an enhencement to it

1. retain the document that stores the count (call it countDoc)
2. create a dummy document everytime you want to increment the counter
3. count all the dummy documents and add the total to the count stored in the countDoc

daily maintenance:
1. count all the dummy documents and add the total to the count stored in the countDoc
2. update the count stored in the countDoc
3. delete all the dummy documents.

of course it is still best if you can get the info from the catalog.nsf as suggested by sjef_bosman as long as it is updated everytime you need the info.

hope this helps.
Just make sure the Catalog process is mentioned in notes.ini to run every night. Info will then be no more than 24 hours old.
Hey Guys, I now have designer access to Catalog.nsf I see the form and field that the data is coming from, how would I incorporate that into my application?
Great! Now what do you need INSIDE your application? Wouldn't it be possible for your applicxation just to open Catalog.nsf and walk though all database documents? Or grab a particular database and deal with that? What do you want to record?
I'd like to grab the Number of uses in previous 24 hours line and put it in the menu like a hit counter just the number would be fine
If you want a hit counter for a database, maybe this is what you need:
    http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/c12a2fd2142758b68525688d00708397?OpenDocument

It is not exactly a hit counter, but who cares, and who will know?
can there not be a script put into the database script that would increment a counter once the database is opened? This is under other in the resoruces....
Yes you can, using a profile document, with code in the PostOpen like this:

    Dim ns As New NotesSession
    Dim doc As NotesDocument
    Dim db As NotesDatabase
    Dim opens As Long    

    Set db= ns.CurrentDatabase
    Set doc= db.GetProfileDocument("DbCounter")
    opens= 1
    If doc.HasItem("Opens") Then
        opens= doc.Opens(0) + 1
    End If
    Call doc.Save(True, False)
Can you help me ou twith the profile document, Iv'e never worked with one. This is what I've done so far:

I created a form unchecked Include in Menu

Added a field Opens

How do I access the data? and what makes it a profile doc?
I am assuming you mean the PostOpen of the Database script, correct? I have added this formula to the field on another form called Hit Counter which I will use to display the number of hits:

@GetProfileField("DBCounter";
"opens")

This is a computed for display field. I am not getting any values, what am I missing here?
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK here's where I'm at:

1. Added script to postopen on resources->other->Database Resources ->Database Script

2. Created a Form with a field computed for display using the formula: (This is not a profile document)
@GetProfileField("DBCounter";
@Text("Opens"))

Would this then display the incrementing of the number of times the DB is open?
Even after I changed the script it is still not displaying any number.
You have to completely close the database to trigger PostOpen on the next open, so both in Notes AND in the Designer!
That worked Perfectly! Thanks Sjef! I had to close notes and the designer but it looks great!!! any way I can add a few zeros to the beginging ofthe numbering?
Suppose so. In Formula language, look at @Text() in the Help db; in LotusScript you can use Format(value, "0000"). In Formula, I tend to use code like
    nt:= @Text(number);
    @If(@Length(nt)>=4; nt; @Right("000" + nt; 4)
cool thanks!