At work we wanted to set up some quick clickthru tracking. I whipped up a quick solution that seemed to work on my local machine. The solution was to use jQuery to look for anchor tags who's href started with "http://" as a signifier of external links, and add a click event to them to direct them back to our server first. Then catch that with a view that logged it and redirected it back out.
I liked this solution because: 1) The user still sees where the link is going in the status bar on hover. 2) If Javascript is off, there is no jQuery to affect the links and they get sent along as normal. Somewhere along the way the URLs are losing a "/" and the original URL of "http://www.google.com" gets munged into "http:/www.google.com", which is resulting in a 404 on our site. Relevant code: Javascript: $(document).ready(function(){ $("a[href^='http://']").click(function() { window.location = "/clickthru/" + escape(this.href); return false; }); }); URLs: (r'^clickthru/(?P<url>.*)/$', 'web.misc_views.clickthru'), View: def clickthru(request, url): """Log the URL then redirect""" import urllib url = urllib.unquote(url) Log.objects.create_log('clickthru', request, url) return HttpResponseRedirect(url) If I test escape in the Firebug console, I get what appears correct: >>> escape("http://www.google.com/") "http%3A//www.google.com/" And unquoting in Python reverses it: >>> import urllib >>> urllib.unquote("http%3A//www.google.com/") 'http://www.google.com/' Throwing an assert in my view shows that the url already has lost one slash. Any ideas would be helpful. Thanks, Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---