Skip to content

erpe/acts_as_referred

Repository files navigation

<img src=“https://badge.fury.io/rb/acts_as_referred.png” alt=“Gem Version” /> <img src=“https://travis-ci.org/erpe/acts_as_referred.png” /> <img src=“https://codeclimate.com/repos/524d89e2f3ea00328a0fbb91/badges/b4046748a27bfa99b07b/gpa.png” />

ActsAsReferred

A gentle gem which offers the possibility to track referrer and campaigning. After an ActiveRecord-instance that includes acts_as_referred gets persistet to your database a relational Referee is persistet as well.

A before_action included to ApplicationController scans the incoming request for specific data supplied in the request-url.

This information is stored in a cookie and in the session as well. The created cookie is valid for 1 month.

The action then makes this data available to your model. When supplied with acts_as_referred your pimped model will make use of a after_create action to create a relational Referee after it was created.

gem version 0.2.0 - works with rails-4.2 / use gem version 0.1.7 for rails-4.1

Status

staging…

Install

Add to your Gemfile

# for rails-4.1
gem 'acts_as_referred', '>= 0.1'

# for rails-4.2
gem 'acts_as_referred', '>= 0.2'

afterwards run the rake task to create necessary database table

rake acts_as_referred:create_table

add acts_as_referred to your model e.g.

class Order < ActiveRecord::Base
  acts_as_referred
end

and the final step - adopt your ApplicationController with:

class ApplicationController < ActionController::Base
  include ActsAsReferred::Controller
end

acts_as_referred supports manual tagged campaigns

If you use google-adwords you have to define manual-url-tagging instead of googles default auto-tagging

Auto-tagging (gclid) is recognized as campaign but can not be resolved. (could be by parsing e.g. google-analytics cookies - but i think its kind of bad practice to relay on googles cookie-syntax)

Update

When updating from version prior 0.1.3 there is a rake task to manage the migration:

rake acts_as_referred:add_timestamps

Usage

A example Order-model which includes acts_as_referred has a relation to Referee on creation you can query referees after relational order was created:

order.referee.is_campaign

returns true if request supplied campaign-arguments

order.referee.campaign

returns campaign name if supplied by tagging

order.referee.keywords

returns supplied keywords in the request.

order.referee.host

returns referrer-hostname

order.referee.path

returns path part of request

Referee.campaigns

returns collection of referee-instances connected to a campaign

order.referee.from

returns either campaign-name if source is campaign or referrer-host if request has referrer or ‘direct’ if neither campaign nor referrer

Background

whenever a request travels through ApplicationController and initializes a session the delivered referrer is persisted in the session. As soon as an ActiveRecord which includes acts_as_referred gets created the stored referrer will be used to build a new Referee

A typical request coming in from adwords (non-auto-tagging!) looks like

example.com/terror-in-baskets?utm_campaign=NSA&utm_term=PRISM&utm_medium=intercepted&utm_source=fbook

If you prefer - what i’d apreciate - Piwik as privacy-aware tracking

example.com/terror-in-baskets?pk_campaign=NSA&pk_kwd=PRISM

ActsAsReferred stores the supplied campaign and keywords with in a Referee