Forum Moderators: open
Here is the JavaScriptcode, in the <head> of the HTML document:
###############################################################################
<head>
[...]
<link rel="stylesheet" href="http://foobar.com/stylesheet.css"
type="text/css">
<script type="text/javascript">
var addr = '<!--#echo var="REMOTE_ADDR"-->';
var agent = '<!--#echo var="HTTP_USER_AGENT"-->'
var docuri = '<!--#echo var="DOCUMENT_URI"-->';
var params = "addr=" + addr + "&agent=" + agent + "&docuri=" + docuri;
function sendURL(url) {
window.location = url;
}
function alog(adpos, asin, prod) {
var cgiURL = "http://foobar.com/cgi-bin/alog.cgi?";
sendURL(cgiURL + params + "&adpos=" + adpos + "&asin=" + asin + "&prod="
+ prod);
return false;
}
</script>
</head>
###############################################################################
Here is the invoked alog.cgi script:
###############################################################################
#!/usr/bin/perl
$logfile = "/var/www/cgi-bin/log/alog";
$query_string = $ENV{QUERY_STRING};
if ($query_string =~
/^addr=([^&]+)&agent=([^&]+)&docuri=([^&]+)&adpos=([^&]+)&asin=([^&]+)&prod=(.+)
$/) {
open(LOG, ">> $logfile");
$addr = $1;
$agent = $2;
$docuri = $3;
$adpos = $4;
$asin = $5;
$prod = $6;
$time = localtime();
print LOG "$time $addr $agent $docuri $adpos $asin $prod\n";
close(LOG);
}
print "Status: 204 No Content\n\n";
exit 0;
###############################################################################
And here is a typical Amazon.com link invoking alog():
###############################################################################
<a href="http://www.amazon.com/exec/obidos/ASIN/BXXXYYYZZZ/ref=nosim/foobar-
20" rel="nofollow" onclick="alog('adfour', 'BXXXYYYZZZ', 'My Life as a Foo')">
###############################################################################
Before (when clicking on an Amazon link opened up a new browser window), this scheme tracked clicks pretty reliably, say 90% of time. Now, it tracks maybe less than 20% of the time.
Is this a timing issue? Is it dependent on browser, OS, CPU speed, ...? I can't discern any pattern. It seems to be entirely hit or miss.
I have added debugging code to determine that it's not an environment variables issue (hence failure of the pattern match, therefore no open and write to the log file). The problem seems to be that, most of the time (now), the alog() function is not being called in the first place.
What am I doing wrong here? Help!