A few people have emailed me for more information about how to log clicks on the external 856 links in HIP, so here’s how to do it!
- a web server on which you can run a script (e.g. Perl or PHP)
- HIP 2 or 3
The 856 links in HIP are built from the MARC map in Horizon, so the first step is tweak it so that it prepends the URL of a logging script in front of the actual 856 URL. Here’s what our 856 MARC $u map looks like (split across several lines for readability):
To view the MARC map without line breaks (i.e. as you’d enter it into Horizon), click here.
Please remember to make a note of the original 856 MARC map value – you might need it!
The https://library.hud.ac.uk/cgi-bin/cataloguelink.pl bit will need to be changed to the location and name of your logging script.
My first version of the logging script simply logged the URL and the time, as I couldn’t figure out a way of capturing more useful info (such as the bib number or book title).
So, I brewed myself an extra strong coffee and sneaked up on the problem from a different angle!
Here’s a souped-up caffeine-enhanced Perl logging script, which attempts to get the bib number and book title:
You’ll need to pop it on your web server and make a few edits to the script:
- change the value of $hip to match the name (or IP address if you don’t use a name) of your HIP server
- change the value of $log if you’d prefer to have the log file stored somewhere else
The script checks to see if the web browser passed a HTTP_REFERER value (which should be the URL of the HIP page with the 856 link). If it did, then the script tries to fetch the XML version of the HIP page. If that works, then it grabs the bib number and the title from the XML.
The log file is tab delimited and contains:
- time stamp
- bib number
- 856 URL
The bib number and title are reliant on the HTTP_REFERER and being able to fetch the XML version of the HIP page.
You can see a sample log file here. The last line in the file shows you what happens if the HTTP_REFERER wasn’t passed by the web browser.
If you’d prefer to get a CSV (comma separated) file, then change the relevant lines in the script to something like:
open( OUT, ">>$log" ); $ttl =~ s/"//g; $url =~ s/"/%22/g; print OUT '"'.localtime(time).qq(",$bib,"$ttl","$url"n); close( OUT );
Some of you may have already spotted the weak link in all of the above — if the web server running the logging script fails, then none of your 856 links will work!
So, make sure your logging script is running on a high-availability server. If the server isn’t available, then the quickest way to fix things is to revert the 856 MARC map back to the original value.
If my recollection is right, then HIP automatically picks up any changes to the 856 MARC map so there’s no need to reboot/restart HIP.