Implementing a referrer log

Ben Poole wrote an article on ”Site Revealed: Simple Referrers”, and I implemented it on this site. The main difference is that I use a Java agent, instead of a LotusScript agent, as I am a Java fan.

Creating the agent

Create a new Java agent that is ”Manually From Actions Menu” and ”Run Once (@Commands may be used)”. Paste the code that is supplied as an attachment to this article (edit: not any more I’m afraid, lost the attachment ages ago). Change the values in the excludeUsers, excludeReferrerHosts and excludeHosts variables to reflect your preference. Name the agent ”ReferrerGetter” and save it. The agent could be refined further, by letting the variables be set dynamically from a settings document / profile document. You could even write a ReferrerLog class etc…

Catching the referrers

The agent should be placed in the WebQuerySave event on the forms that you want to trace the referrers of. If you used the agent name above, you use:

@Command([ToolsRunMacro]; "ReferrerGetter");

Remember to put the HTTP_Referer field in those forms.

Creating the view

To show the referrers on a web page, a simple view must be created. It should have the selection formula:

SELECT Form = "Referrer"

The first column should be hidden and contain the creation date, and be sorted descending. The second column should contain the HTTP_Referer field. Name the view ”ReferrerLog”

Showing the referrer log

On my site, I have the following code to present the referrer list:

r:=@Trim(@Unique(@DbColumn("" : "NoCache"; @DbName; "ReferrerLog"; 2))); @If(@Elements(r) = 0; @Return(""); ""); t:=@Right(@If(@Length(r)>25; @Left(r; 25) + "..."; r); "://"); pad:=" "; pad + "<ul>" + @NewLine + @Implode(pad + " <li><a href="" + r + "">" + t + "</a></li>" + @NewLine) + pad + "</ul>"

That should be everything you need to get a referrer log!