GitXplorerGitXplorer
b

rack-campaign

public
4 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
60d227b0755836a45a29ea3685ed999f14ad57f4

up the version for the new gem

bbillymeltdown committed 15 years ago
Unverified
c92180aaeef518b46820010092b0d65b3ed3a0a7

namespace adjustments, use Rack::Zetetic::Campaign

bbillymeltdown committed 15 years ago
Unverified
7b2d7e5e0d4657570bb80ad9d2d0e5a9471e7607

fussy tweaks to readme, include examples in gem distro

bbillymeltdown committed 15 years ago
Unverified
8d877f2a96d143cfccfed3db416dc8ac12df4d0c

updating example files and README

bbillymeltdown committed 15 years ago
Unverified
4af0582f7ce11a9f78ddaf75fbe83e57f7a7bda6

bump version number for bug fix

bbillymeltdown committed 15 years ago
Unverified
275aa76f613a03df64eca5e36c431a72ee7bff23

whoop, need to require yaml

bbillymeltdown committed 15 years ago

README

The README file for this repository.

h2. rack-campaign

This is a "Rack":http://rack.rubyforge.org/ application (a gem is available by the same name) allowing you to maintain a "YAML":http://www.yaml.org/ file of short URLs that redirect to target URLs with a set of specified Google Analytics variables. It could be used to attach any number of parameters by any name to the query string.

h2. What it does:

example promo url:

@http://zetetic.net/c/blog-rack-campaign@

When the user visits this link, our web server sees the /c/ location and forwards it to rack-campaign, which looks up 'blog-rack-campaign' in the YAML file, and redirects the user to the full URL, with campaign variables attached.

resulting full url:

@http://www.zetetic.net/blog/2010/06/11/introducing-rack-campaign?utm_campaign=rack-campaign&utm_source=blog&utm_medium=internets&utm_content=example%20link@

The former is much better than the latter, especially for newsletters and other promotional links. And with a Rack application and a YAML file you can host it yourself, you don't need to rely on bit.ly or other URL shorteners, and you can "fix" any mistakes after publishing a URL simply by updating the YAML file and reloading Unicorn (taking advantage of zero down-time!) [ You could use another Rack-server, we like Unicorn. ]

h2. Installation

@gem install rack-campaign@

The rest depends on how you intend to use it.

h2. Example Files

In the @/examples@ directory of the source distribution are some sample configuration files. @config.ru@ is a @rackup@ file, initializing the rack-campaign middleware. You don't have to use rack-campaign as a stand-alone Rack application, you could instead use it in a middleware stack (although you might want to modify it's behavior). You probably want to use the map directive in that case to assign rack-campaign to a particular url path (we use /c).

h2. Example Configuration

This is how we use rack-campaign as a stand-alone Rack application. Nginx is our web-server, and we use Unicorn to serve up rack-campaign for the /c path:

/www/campaigns/campaigns.yml:


blog-rack-campaign:
  url: http://dev.zetetic.net/blog/2010/06/11/introducing-rack-campaign
  tokens:
    campaign: rack-campaign
    source: blog
    medium: internets
    content: example link

blog-getstrip:
  url: http://getstrip.com
  tokens:
    campaign: rack-campaign
    source: blog
    medium: internets
    term: strip rocks!
    content: example link

/www/campaigns/config.ru:


# Rack-up application config

require 'rubygems'
require 'rack/zetetic/campaign'

run Rack::Zetetic::Campaign.new('/www/campaigns/campaigns.yml')

nginx.conf:


# define upstream for campaign routing
upstream campaigns {
  server unix:/www/campaigns/tmp/sockets/unicorn.sock;
}

location /c {
  proxy_redirect     off;
  proxy_set_header   Host             $host;
  proxy_set_header   X-Real-IP        $remote_addr;
  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  proxy_max_temp_file_size 0;

  # forward everything else to the mongrel cluster
  if (!-f $request_filename) {
   proxy_pass http://campaigns;
   break;
  }
}

/etc/init.d/unicorn_rack:


#!/bin/bash
#
# unicorn_rack       Startup script for Unicorn master processes
#
# chkconfig: - 85 15
# description: unicorn is a magical process offering up workers to nginx
#              

USER=mongrel
RETVAL=0
APPS=( '/www/campaigns' )

for APP in "${APPS[@]}"
do
  case "$1" in
      start)
        echo "Starting up $APP"
        cd $APP
        sudo -u $USER unicorn -c $APP/unicorn.rb -E production -D 
        RETVAL=$?
    ;;
      stop)
        echo "Stopping $APP"
        PID=`ps auxw | grep 'unicorn master' | grep $APP | grep -v grep | awk '{ print $2 }'`
        sudo -u $USER kill -INT $PID
        RETVAL=$?
    ;;
      restart)
      $0 stop
      sleep 2
      $0 start
    ;;
      reload)
        echo "Re-loading $APPS"
        PID=`ps auxw | grep 'unicorn master' | grep $APP | grep -v grep | awk '{ print $2 }'`
        sudo -u $USER kill -HUP $PID
        RETVAL=$?
    ;;
      *)
        echo "Usage: unicorn_rack {start|stop|restart|reload}"
        exit 1
    ;;
  esac      
done

exit $RETVAL