Can You Track Landings On A .PDF Document?

ComitSteve

Milkshake Drinker
Aug 6, 2010
122
1
0
I feel like an idiot for having to ask this here, but maybe someone can assist.

Aside from tracking downloads of the .PDFs on a site with the _trackPageview() function, is there a way to track landings from Google on these .PDF files?

One option I was thinking about would be to create new pages for each .PDF, then just embed the .PDF in the page, but I have something like 60 of them and do not want to go that route if possible.


 


just write a perl script or something to parse the server log for hits on that file. it's like 5 lines of code.
 
That's not my area of expertise. But I have some co-workers who can probably handle that.

Thanks for the tip.
 
Parsing the server logs is probably the easiest.

Another solution would be to create a server side script to function as a PDF handler. It could accept either the file name or some other ID as parameter then load the appropriate PDF file and stream it down to the browser. So then you might link to like /getpdf.php?file=filename, or even better you could use mod rewrite to map all .PDF requests to that script so you wouldn't have to change URLs.

This script could then track the hits in a database or file, or maybe it would be possible to call out to GA server-side.

Not sure if all that would be worth it; just an idea.
 
stream it in php

1st, As the others have mentioned, parsing your server logs would be easiest.

2nd, I've used the apache-mysql modules that instead of writing to logs, writes to a mysql database. It was easier to write scripts that queried/rolled the logs that way.

3rd, stream it in php
DISCLAIMER: this script is pseudo code. Do not use this as is. It is purely as an example for you. This is just explaining an implementation of what coffeebean has suggested.

<?php

//clean up any variables you are using from user input
$_GET = cleanUp($_GET);

//if the file doesn't exist, send them somewhere else
if(!$_GET['fileUploadId'])
{
header('Location: '.$redirect);
exit();
}

//grab file out of db
$file = $db->get_row("select whatever from fileUpload where fileUploadId='{$_GET['fileUploadId']}'");

//update count on record
$db->query("UPDATE fileUpload SET count = count + 1 WHERE fileUploadId='{$_GET['fileUploadId']}'");

//set headers to how you need them
header('Cache-Control: maxage=3600');
header('Pragma: public');
header("Content-Type: ".$file->typeHeader);
header("Content-Length: ".$file->size);
header("Content-Disposition: inline;filename=".$file->name);

//stream the file
echo $file->data;

?>