Ah, that was a very handy suggestion. :up:
When I changed the hook to attachment_display I started to see records inserted into my database table. However it was a small surprise to me to see that when thumbnails are display that hook is triggered. I had to make a small change to my code to skip over thumbnails since I'm not interested in tracking that data at the moment. The revised code below seems to now work.
As an aside I was able to remove the extra quoting of all the query parameters that I'd added as suggested above. Since my table schema defines userid and attachmentid as int(10) the quoting doesn't appear to be required. It did work perfectly fine with them in place but it seems extraneous.
Code:
global $vbulletin;
$isThumb = $vbulletin->GPC['thumb'];
if (!$isThumb)
{
$userId = $vbulletin->userinfo['userid'];
$attachId = $vbulletin->GPC['attachmentid'];
$sessionId = $vbulletin->session->vars['host'];
$vbulletin->db->query_write("
insert into " . TABLE_PREFIX ."attachmentDownloadHistory
(userid, host, attachmentid)
values
($userId, '$sessionId', $attachId)
");
$vbulletin->db->show_errors();
}