Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track a completed file download in ASP.NET

I have this ASP.NET web site that allows users to download program installation packages (just normal files). I want to be able to track when a download is completed (i.e. the file has been fully downloaded to the user's computer) and then invoke a Google Analytics script that reports a completed download as a 'Goal' (obviously, one of my goals is to increase file downloads).

The problem is that I need to support direct file URLs, as opposed to the "redirect page" solution. This is because a lot of traffic comes from software download sites that explicitly demand a direct file URL when submitting a product. Perhaps, they do their own file analysis (i.e. virus checking). But with this set of limitations, a typical scenario is:

  1. The user visits my product listing on a software download site
  2. The user clicks the "Download" button on this site
  3. The "Download" page is typically a redirect that finally brings the user to my file via the direct URL I've initially submitted, i.e. http://www.ko-sw.com/somefile.exe

If under these conditions, an exact solution for monitoring is not possible, maybe there exists a workaround? What comes to my mind is temporarily storing the number of performed downloads on the server and then accessing an administrative page that somehow reports this number to Google Analytics and finally sets it back to zero. With this workaround, there is at least no need to try to attach a javascript handler to a non-HTML resource. But even then there are issues:

  1. How to track if a download has completed?
  2. How to track user geolocation and browser capabilities to make them further visible in the reports?

Thanks everybody in advance

like image 642
Kerido Avatar asked Oct 07 '10 07:10

Kerido


2 Answers

According to awstats aborted download has http status code 206 so if you analyze server log for such code you can get those downloads that were not completed.

like image 56
Giorgi Avatar answered Oct 15 '22 09:10

Giorgi


@Kerido ~ I'm curious what the business case is here. Are you trying to track installs or downloads? If installs, go with @SamMeiers solution.

However, if you're trying to track downloads, then the next question is what webserver base are you using? IIS? Apache? Something else?

In IIS, assuming you're using 7 (or later), you could (easily?) write a HttpHandler that checks for the last bytes of the file to be sent, and on that, record a log somewhere.

On Apache, just setup logging to tell you how many bytes were transferred (a trivial change in httpd.conf) and then parse the logs daily (awstats [amongst others] is pretty good for this, but you might have to write a sed/awk script) and find out how many full transfers were completed. Just depends on how thorough you're trying to be.

But I go back to, what's the business case for this? What does it matter if there were unfinished downloads?

like image 41
jcolebrand Avatar answered Oct 15 '22 11:10

jcolebrand