Portland & Courant News: Short URLs


08.12.09 Posted in Courant News by Max

This past Sat­ur­day I joined Daniel Bach­hu­ber and David Estes in Port­land to talk journo dev projects. We talked about work­flow engines, news wikis, vir­tual assign­ment desks, and other mis­cel­la­neous top­ics, but even­tu­ally Daniel and I got to work on build­ing a sim­ple short URL app for Django/Courant News.

There is cer­tainly no short­age of short URL ser­vices in exis­tence, with bit.ly cur­rently being the most pop­u­lar. How­ever, as the recent exis­ten­tial cri­sis at tr.im has shown, trust­ing these ser­vices is some­times not the best idea. In addi­tion, there are numer­ous advan­tages (enu­mer­ated else­where) to host­ing your short URLs on your own domain name.

Refer­ral Tracking

As news orgs strive to find ways of attract­ing traf­fic to their web­sites, eval­u­at­ing the effec­tive­ness of dis­tri­b­u­tion through dif­fer­ent medi­ums is crit­i­cal. How much traf­fic comes from email newslet­ters? Twit­ter? Face­book? the print edition?

Some or all of such medi­ums will not pass HTTP refer­rer head­ings, which means it is dif­fi­cult or impos­si­ble to track using nor­mal method­ol­ogy. If you are using Google Ana­lyt­ics or sim­i­lar ser­vice, the best you can likely do is add an HTTP GET para­me­ter to the end of the link and con­vert that on the server side. How­ever, it is easy for users to strip this off and is far from foolproof.

Alter­na­tively, we can gen­er­ate a dif­fer­ent short URL for each of the tar­get medi­ums and then track hits before/during the redi­rec­tion step. That’s the route we chose for our app.

Short URL Types

There are a few strate­gies to gen­er­at­ing actual short URL strings. Most of the pop­u­lar ser­vices just use incre­men­tal keys that are encoded in base-32 or sim­i­lar (con­verts a num­ber to a string con­sist­ing of A-Z, a-z, 0–9 and per­haps some punc­tu­a­tion characters).

That works well with huge vol­ume, as a sin­gle indi­vid­ual is unlikely to gen­er­ate con­sec­u­tive URL tokens. How­ever, when you host your own URL short­ener, all URLs gen­er­ated on a given day will look very sim­i­lar using this approach, which may or may not be problematic.

I, per­son­ally, pre­fer more diverse URLs for tokens cre­ated in a sequence. Since the point of per-medium URLs is to reli­ably track refer­rers, we don’t want users to eas­ily guess what the URL for another medium is and thus spoof our ser­vice (or just acci­den­tally mistype them).

There­fore, our short URL app sup­ports both gen­er­a­tion types: con­sec­u­tive sequence (GHn8n, GHn8o, GHn8p) or a pseudo-random gen­er­a­tor (GHn8n, SfMgo, ednto).

If you want a cus­tom URL for a spe­cial case, you can man­u­ally cre­ate a new short URL through the admin inter­face and man­u­ally spec­ify what­ever URL value you desire.

Pri­mary vs. Sec­ondary Domain

The YDN has a very long domain name, so we want to use a shorter domain name (goydn.com) for our short URLs. How­ever, some orgs, such as David’s DailyUW.com may want to just use their nor­mal domain. Thus our app sup­ports both scenarios.

If you want to use your pri­mary domain, we rec­om­mend you put it under some pre­fix, such as /go/ or /g/, to avoid col­li­sions with other valid URLs (e.g., /news/). How­ever, if you want to play with fire, you can con­fig­ure your short URLs to work at the top level of your pri­mary domain with­out problems.

Do note that short URLs will only get checked if the page requested would have oth­er­wise returned a 404 error.

App Mod­els

The first model in our app is Short­urlMedium, which is sim­ply a named object rep­re­sent­ing a given medium like “Print”, “Twit­ter” or what­ever your org needs.

The core of our app is the Short­url model, which maps a Short­urlMedium to a con­tent object (using Django’s con­tent type app) and stores the actual short URL.

Finally, we have the Short­url­Hit model, which tracks hits for a given per-medium short URL. I have not yet gen­er­ated any report gen­er­a­tion tools, but that should be an easy work item in the future and will surely be a part of Nando.

Tem­plate Tags

To put short URL links on your pages, we have a sim­ple tem­plate tag to get (and gen­er­ate, if nec­es­sary) one for a given con­tent object (arti­cle, page, event, etc.).

{% load shorturls %}
{% shorturl obj Twitter %}

That’s it. The first para­me­ter is the con­tent object vari­able, and the sec­ond is the medium you want it to run in.

Con­clu­sion

Our short URL app is pretty sim­ple, but is con­fig­urable to meet the needs of most col­lege news deploy­ment sce­nar­ios. Because it ties into your con­tent behind the scenes, it won’t break when you change your nor­mal URL struc­tures and sup­ports any new mod­els you add to the sys­tem. In a few months, after we use the sys­tem in pro­duc­tion, I’ll post a fol­lowup ana­lyz­ing the ana­lyt­ics data we gather from it.

Code can be found in the Courant News code repo. Parts were based on django-ittybitty, but we strayed far enough away in pur­pose and imple­men­ta­tion that it didn’t make sense to just treat our code as a patch. Let me know if you have any questions.



3 Responses to “Portland & Courant News: Short URLs”

  1. […] In the past week, Twit­ter as all about Face­book, Friend­Feed, and tr.im. Jef­fery Zeld­man, a notable designer, has taken the approach of not using any third-party URL short­en­ers and instead runs all of his posts off his own domain with a Word­Press plu­gin called, you guessed it, “Short URL plu­gin.” If your domain is short enough that this makes sense, it would prob­a­bly be a worth­while approach that would help avoid link rot. On a related note, Max Cut­ler and David Estes came down to Port­land last week­end. One of the projects that actu­ally came to life was a URL short­ener app for Courant News. […]

  2. […] In my mind, that’s exactly what we want out of the inter­sec­tion of work­flows and noti­fi­ca­tions. The work­flow con­cept of Edit Flow is based around the idea that there are two or more peo­ple that have to work together in uni­son to get a piece of con­tent pub­lished. The sta­tuses serve as the steps along the way, which don’t nec­es­sar­ily have to hap­pen in order or chrono­log­i­cally, and noti­fi­ca­tions hap­pen at each point where an action is taken within the sys­tem. Max and I mapped it out a bit when he came down from Seattle: […]

  3. […] Courant News included new email and ana­lyt­ics track­ing sys­tems, which allowed us to push break­ing news updates to our email sub­scribers and track […]

Leave a Reply