Permalink
Browse files

update specs

  • Loading branch information...
1 parent 1853cbd commit 1e36c47fbba652135d37bf2ac162d1e98675cef0 @jacquescrocker committed Jun 2, 2011
Showing with 54 additions and 16 deletions.
  1. +15 −9 README.md
  2. +27 −5 lib/aarrr/session.rb
  3. +12 −2 spec/functional/aarrr/session_spec.rb
View
@@ -61,8 +61,7 @@ You can get a session in a few different ways:
### Tracking vs Completion events
-For each category of events, you can track multiple events leading up to the actual "completion" step for the step.
-
+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`
### Acquisition
@@ -73,6 +72,11 @@ If you'd rather define Acquisition events manually, just use:
AARRR(request.env).acquisition!(:viewed_homepage)
+To track the funnel leading up to the acquisition event, use:
+
+ AARRR(request.env).acquisition!(:opened_signup_popup, :in_progress => true)
+
+
### Activation
Activation events should be tracked as soon as your user interacts "sucessfully" with your app. You'll need to define this for your own app, however if your app is built to do something specific then you should add an activation event whenever that thing happens.
@@ -97,19 +101,22 @@ Referral should be triggered whenever someone gets someone else to sign up to yo
Referrals are done in 2 parts. First you can track when someone decides to refer someone. This would be an "invite" link or something similar.
# generate a referral
- referral_code = AARRR(request.env).referral!({email: "someone@somewhere.com"})
+ referral_code = AARRR(request.env).sent_referral!(:sent => {email: "someone@somewhere.com"})
# email out the url with this referral code in the query param
# "?_a=x71n5"
+ # after accepting the code
+ AARRR(request.env).accept_referral!(code)
+
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, :for => [:activation, :retention], :complete => [:activation])
+ AARRR(request.env).track!(:built_page, :event_type => :activate, :in_progress => true)
### Revenue
@@ -237,7 +244,7 @@ This section describes how AARRR stores your data within the MongoDB collections
AARRR tracks the raw metric data in a 2 main tables:
-`aarrr_users` tracks the unique identities of each user
+`aarrr_users`: tracks the unique identities of each user
* `_id`: generated aarrr user id
* `user_id`: optional tie in to your database's user_id (for drill down)
@@ -247,16 +254,15 @@ AARRR tracks the raw metric data in a 2 main tables:
* `ignore_reason`: a string that represents the reason this user is ignored in reports
* `referrer`: referrer url that user came from
* `ip_address`: ip address for the user
-* `first_event_at`: date that the user first interacted with the site
* `last_event_at`: date that the user last interacted with the site
-`aarrr_events` tracks each event that the user is engaged in.
+`aarrr_events`: tracks each event that the user is engaged in
* `_id`: generated aarrr event id
* `aarrr_user_id`: id that maps event back to the aarrr users table
-* `event_type`: array of types of the event that was tracked
-* `completed`: array of types of the event that were completed
* `event_name`: name for the event that was tracked
+* `event_type`: category of event type you are tracking
+* `in_progress`: true/false whether or not this event_type is in progress (not yet completed)
* `data`: data that should be tracked along with the event
* `revenue`: revenue the was generated on this event
* `referral_code`: referral code that was generated for this event
View
@@ -7,11 +7,11 @@ class Session
attr_accessor :id
# find or creates a session in the db based on the env or object
- def initialize(env_or_object = nil, data = nil)
+ def initialize(env_or_object = nil, attributes = nil)
self.id = parse_id(env_or_object) || BSON::ObjectId.new.to_s
# perform upsert
- update({"$set" => user_attributes(env_or_object).merge(data || {})}, :upsert => true)
+ update({"$set" => build_attributes(env_or_object).merge(attributes || {})}, :upsert => true)
end
# returns a reference the othe AARRR user
@@ -24,11 +24,33 @@ def set_data(data)
update({"data" => {"$set" => data}})
end
+ # track event name
+ def track!(event_name, options = {})
+
+ # add event tracking
+ AARRR.events.insert({
+ "aarrr_user_id" => self.id,
+ "event_name" => event_name,
+ "event_type" => options[:event_type],
+ "in_progress" => options[:in_progress] || false,
+ "data" => options[:data],
+ "revenue" => options[:revenue],
+ "referral_code" => options[:referral_code]
+ })
+
+ # update user with last updated time
+ update({
+ "$set" => {
+ "last_event_at" => Time.now.getutc
+ }
+ })
+ end
+
protected
# mark update
- def update(data, options = {})
- AARRR.users.update({"_id" => id}, data, options)
+ def update(attributes, options = {})
+ AARRR.users.update({"_id" => id}, attributes, options)
end
# returns id
@@ -51,7 +73,7 @@ def parse_id(env_or_object)
end
# returns updates
- def user_attributes(env_or_object)
+ def build_attributes(env_or_object)
if env_or_object.is_a?(Hash)
user_attributes = {}
@@ -11,8 +11,6 @@ module AARRR
it "should create a session with a request env" do
session = Session.new
- AARRR.users.count.should eq(1)
-
Session.new({
"rack.request.cookie_hash" => {
"_utmarr" => session.id
@@ -28,6 +26,18 @@ module AARRR
AARRR.users.count.should eq(2)
end
+
+ describe "tracking" do
+ before(:each) do
+ @session = Session.new
+ end
+
+ it "should track a custom event" do
+ @session.track!(:something)
+
+ AARRR.events.count.should eq(1)
+ end
+ end
end
end

0 comments on commit 1e36c47

Please sign in to comment.