Class: AARRR::Session
- Inherits:
-
Object
- Object
- AARRR::Session
- Defined in:
- lib/aarrr/session.rb
Overview
an AARR session is used to identify a particular user in order to track events
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
-
#acquisition!(event_name, options = {}) ⇒ Object
more helpers.
- #activation!(event_name, options = {}) ⇒ Object
-
#initialize(env_or_object = nil, attributes = nil) ⇒ Session
constructor
find or creates a session in the db based on the env or object.
- #retention!(event_name, options = {}) ⇒ Object
-
#save(response) ⇒ Object
save a cookie to the response.
-
#set_data(data) ⇒ Object
sets some additional data.
-
#track!(event_name, options = {}) ⇒ Object
track event name.
-
#user ⇒ Object
returns a reference the othe AARRR user.
Constructor Details
#initialize(env_or_object = nil, attributes = nil) ⇒ Session
find or creates a session in the db based on the env or object
10 11 12 13 14 15 |
# File 'lib/aarrr/session.rb', line 10 def initialize(env_or_object = nil, attributes = nil) self.id = parse_id(env_or_object) || BSON::ObjectId.new.to_s # perform upsert update({"$set" => build_attributes(env_or_object).merge(attributes || {})}, :upsert => true) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/aarrr/session.rb', line 7 def id @id end |
Instance Method Details
#acquisition!(event_name, options = {}) ⇒ Object
more helpers
62 63 64 65 |
# File 'lib/aarrr/session.rb', line 62 def acquisition!(event_name, = {}) [:event_type] = :acquisition track!(event_name, ) end |
#activation!(event_name, options = {}) ⇒ Object
67 68 69 70 |
# File 'lib/aarrr/session.rb', line 67 def activation!(event_name, = {}) [:event_type] = :activation track!(event_name, ) end |
#retention!(event_name, options = {}) ⇒ Object
72 73 74 75 |
# File 'lib/aarrr/session.rb', line 72 def retention!(event_name, = {}) [:event_type] = :retention track!(event_name, ) end |
#save(response) ⇒ Object
save a cookie to the response
28 29 30 31 32 33 34 |
# File 'lib/aarrr/session.rb', line 28 def save(response) response.(AARRR::Config., { :value => self.id, :path => "/", :expires => Time.now+AARRR::Config. }) end |
#set_data(data) ⇒ Object
sets some additional data
23 24 25 |
# File 'lib/aarrr/session.rb', line 23 def set_data(data) update({"data" => {"$set" => data}}) end |
#track!(event_name, options = {}) ⇒ Object
track event name
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aarrr/session.rb', line 37 def track!(event_name, = {}) # add event tracking result = AARRR.events.insert({ "aarrr_user_id" => self.id, "event_name" => event_name, "event_type" => [:event_type], "in_progress" => [:in_progress] || false, "data" => [:data], "revenue" => [:revenue], "referral_code" => [:referral_code] }) # update user with last updated time update({ "$set" => { "last_event_at" => Time.now.getutc } }) result end |
#user ⇒ Object
returns a reference the othe AARRR user
18 19 20 |
# File 'lib/aarrr/session.rb', line 18 def user AARRR.users.find(id) end |