Class: IWonder::AbTestGoal

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/i_wonder/ab_test_goal.rb

Instance Method Summary collapse

Instance Method Details

#add_goal_to_query(scoped_statement) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/i_wonder/ab_test_goal.rb', line 33

def add_goal_to_query(scoped_statement)
  if tracks_event?
    sc = scoped_statement.where("i_wonder_events.event_type = ?", event_type)
  else
    sc = scoped_statement.where("i_wonder_events.event_type = ? AND i_wonder_events.controller = ?", "hit", page_view_controller)
    
    if page_view_action.present?
      sc = sc.where("i_wonder_events.action = ?", page_view_action)
    end
  end
  
  sc.where("i_wonder_events.created_at > ?", self.ab_test.started_at) # event had to come after goal
end

#clean_up_controllerObject



18
19
20
21
22
23
# File 'app/models/i_wonder/ab_test_goal.rb', line 18

def clean_up_controller
  if tracks_page_view?
    page_view_controller.gsub!("Controller", "")
    page_view_controller.downcase!
  end
end

#to_sObject



47
48
49
50
51
52
53
54
55
# File 'app/models/i_wonder/ab_test_goal.rb', line 47

def to_s
  if tracks_event?
    "#{event_type} occurred"
  elsif page_view_action.present?
    "#{page_view_controller}##{page_view_action} hit"
  else
    "any #{page_view_controller} hit"
  end
end

#tracks_event?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/i_wonder/ab_test_goal.rb', line 25

def tracks_event?
  goal_type == "Event"
end

#tracks_page_view?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/i_wonder/ab_test_goal.rb', line 29

def tracks_page_view?
  goal_type == "Page View"
end