TrafficMansion

Installation

Add this line to your application's Gemfile:

gem 'traffic_mansion'

And then execute:

$ bundle

Environment

The following environment variables can be set:

  TRAFFIC_MANSION_HTTP_HOST=mydomain.com # the domain where you track from
  TRAFFIC_MANSION_ENDPOINT=http://www.trafficmansion.com # the API endpoint
  TRAFFIC_MANSION_ROOT_CAMPAIGN_ID=666 # the default campaign id for the root traffic if there is one
  TRAFFIC_MANSION_LOG_REQUESTS=1 # set this to debug the tracking request and response
  TRAFFIC_MANSION_LOG_TO_FILE=1 # set this to debug it into a file instead of the main logger

Tasks

Run traffic_mansion:create_indexes after the instalation to set the Queue collection indexes.

Usage

Unique visits

Track them directly from the controller:

  def track_unique_visit
    if !TrafficMansion::tracked_client?(cookies)
      campaign_id = TrafficMansion::get_campaign_id params[:campaign_id]
      if campaign_id
        event = TrafficMansion::Queue::add_unique_visit campaign_id, request.remote_ip, request.referer
        cookies[TrafficMansion::COOKIE_NAME] = { :value => event.id, :expires => 30.days.from_now, :domain => :all }
      end
    end
  end

Signups

Track them directly from the controller:

  def  user
    if TrafficMansion::tracked_client?(cookies)
      TrafficMansion::Queue:: cookies[TrafficMansion::COOKIE_NAME], user.id, request.remote_ip, request.referer
    end
  end

Sales

Track them from the post response controller:

  def track_sale user, payment
    TrafficMansion::Queue::add_sale user.id, payment.id, payment.amount, payment.product.name, request.remote_ip, request.referer
  end