Analytics
2.7K members online now
Understand information in your reports and troubleshoot reporting issues such as self-referrals, (not set) data, and inaccurate information
 
Guide Me
star_border
Reply

tracking downloads using htaccess

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi all,

 
(disclaimer: I'm not super HTML/web literate, so apologies if I'm using the wrong terms/language for things)
 
Our site has a lot of files, and my webmaster set it up so that we could track downloads in Analytics. He told me that when I link to a file I want to track, I have to use <a href=/download instead of <a href=/files. Via Analytics, I simply go to content drilldown and I can see all the times people have accessed any page beginning with /download, effectively tracking how many people have downloaded a file off the site.
 
This morning I was creating a htaccess file, not realizing that there already WAS a htaccess file, since it was hidden and being an extreme beginner, I didn't realize that the download tracking thing was done via htaccess. Well, I overwrote the htaccess and bam -- all my file links returned 404 errors. After much googling and trial+error, I managed to use add the following to my htaccess, and everything seems to be working again.
 
RewriteEngine On
RewriteRule ^download/(.*)$ /files/$1 [R,NC,L]
 
Links are written as <a href=mysite.com/download/document.pdf> and once clicked, the browser opens mysite.com/files/document.pdf.
 
However, it seems Analytics is no longer treating clicks on file links as "pageviews." We want to see how many people "viewed" mysite.com/download/document.pdf. I think that before I messed it up, we could even see how long users stayed on that page, reading the pdf. What do I need to put into the htaccess file to restore this? Being not very fluent in HTML, it would be helpful to have the exact code I need to paste, and to know where to paste it.
 
I know there may be better ways to track downloads, and we will be revitalizing the website with this in mind later on, but our developer is still on vacationing and until then I need to put the htaccess to rights. (ie: I don't want to mess with the actual links for now; I only want to edit the htaccess)
 
 
Thanks for the help!
1 Expert replyverified_user

tracking downloads using htaccess

Top Contributor
# 2
Top Contributor

Have you asked your site host if they do regular backups of the site? If so, they might be able to restore the htaccess file for you

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here