Skip to content

Commit

Permalink
updating helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacques Crocker committed Jun 12, 2011
1 parent aaa09d9 commit 77547e8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 26 deletions.
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ You can get a session in a few different ways:
# pass in the tracking code directly
AARRR(cookies["_utmarrr"])

You should then save the session to cookie: `AARRR(request.env).save(response)`
You should then save the session to cookie: `AARRR(request.env).set_cookie(response)`

### Tracking vs Completion events

For each category of events, you can track multiple events leading up to the actual "completion" step for a category, use the option `:in_progress => true`
### Completion events

For each category of events, each events you log leads up to a "completion" step for a category. Once you hit an event that provides a "completion" step, add :complete => true. You can also use the ! version of the method to designate that the funnel has been completed for this action.

AARRR(request.env).acquisition!(:signed_up) #=> passes along :complete => true


### Acquisition
Expand All @@ -75,7 +78,7 @@ If you'd rather define Acquisition events manually, just use:

To track the funnel leading up to the acquisition event, use:

AARRR(request.env).acquisition!(:opened_signup_popup, :in_progress => true)
AARRR(request.env).acquisition(:opened_signup_popup)


### Activation
Expand Down Expand Up @@ -113,13 +116,6 @@ Referrals are done in 2 parts. First you can track when someone decides to refer
When someone enters the site without an activated session and a referral code shows up, then we track the referral event as soon as the user signs up.


### Track

Track allows you to trigger multiple events at a time. (defaults to :activation event)

AARRR(request.env).track!(:built_page, :event_type => :activate, :in_progress => true)


### Revenue

Whenever you capture a dollar from user, then you should track that intake event.
Expand All @@ -134,6 +130,22 @@ Whenever you capture a dollar from user, then you should track that intake event
AARRR(request.env).revenue!(55.00, :unique => "x8175m1o58113")


### Track

Track allows you to trigger multiple events at a time. (defaults to :activation event)

AARRR(request.env).track!(:built_page, :event_type => :activate)


### Shortened helper aliases

AARRR.acq #=> same as AARRR.acquisition
AARRR.act #=> same as AARRR.activation
AARRR.ret #=> same as AARRR.retention
AARRR.ref #=> same as AARRR.referral
AARRR.rev #=> same as AARRR.revenue


## Cohorts

Cohorts are ways to slice up reports so you can see the results for these 5 metrics for groups of specific users. Some useful examples are:
Expand Down
4 changes: 2 additions & 2 deletions lib/aarrr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
end

# helper method to initialize an AARRR session
def AARRR(env_or_model)
def AARRR(env_or_model, attributes = nil)
if env_or_model.is_a?(Hash) and env_or_model["aarrr.session"]
env_or_model["aarrr.session"]
else
session = AARRR::Session.new(env_or_model)
session = AARRR::Session.new(env_or_model, attributes)

# add to the rack env (if applicable)
env_or_model["aarrr.session"] = session if env_or_model.is_a?(Hash)
Expand Down
61 changes: 48 additions & 13 deletions lib/aarrr/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def set_cookie(response)
end

# track event name
def track!(event_name, options = {})
def track(event_name, options = {})
options = options.with_indifferent_access

# add event tracking
result = AARRR.events.insert({
"aarrr_user_id" => self.id,
"event_name" => event_name.to_s,
"event_type" => translate_event_type(options["event_type"]),
"in_progress" => options["in_progress"] || false,
"complete" => options["complete"] || false,
"data" => options["data"],
"revenue" => options["revenue"],
"referral_code" => options["referral_code"],
Expand All @@ -77,35 +77,70 @@ def track!(event_name, options = {})
result
end

# more helpers
def track!(event_name, options = {})
options[:complete] = true
track(event_name, options)
end

# helpers

def acquisition!(event_name, options = {})
def acquisition(event_name, options = {})
options[:event_type] = :acquisition
track!(event_name, options)
track(event_name, options)
end
alias :acq :acquisition

def acquisition!(event_name, options = {})
options[:complete] = true
acquisition(event_name, options)
end
alias :acq! :acquisition!

def activation!(event_name, options = {})
def activation(event_name, options = {})
options[:event_type] = :activation
track!(event_name, options)
track(event_name, options)
end
alias :act :activation

def activation!(event_name, options = {})
options[:complete] = true
activation(event_name, options)
end
alias :act! :activation!

def retention!(event_name, options = {})
def retention(event_name, options = {})
options[:event_type] = :retention
track!(event_name, options)
track(event_name, options)
end
alias :ret :retention

def retention!(event_name, options = {})
options[:complete] = true
retention(event_name, options)
end
alias :ret! :retention!

def referral!(event_name, options = {})
def referral(event_name, options = {})
options[:event_type] = :referral
track!(event_name, options)
track(event_name, options)
end
alias :ref :referral

def referral!(event_name, options = {})
options[:complete] = true
referral(event_name, options)
end
alias :ref! :referral!

def revenue!(event_name, options = {})
def revenue(event_name, options = {})
options[:event_type] = :revenue
track!(event_name, options)
track(event_name, options)
end
alias :rev :revenue

def revenue!(event_name, options = {})
options[:complete] = true
revenue(event_name, options)
end
alias :rev! :revenue!

Expand Down

0 comments on commit 77547e8

Please sign in to comment.