1 | <?php |
||
10 | class AbTesting |
||
11 | { |
||
12 | protected $experiments; |
||
13 | |||
14 | const SESSION_KEY_EXPERIMENTS = 'ab_testing_experiment'; |
||
15 | const SESSION_KEY_GOALS = 'ab_testing_goals'; |
||
16 | |||
17 | 48 | public function __construct() |
|
21 | |||
22 | 48 | protected function start() |
|
55 | |||
56 | 48 | public function pageview() |
|
63 | |||
64 | 42 | protected function setNextExperiment() |
|
73 | |||
74 | 42 | protected function getNextExperiment() |
|
80 | |||
81 | 9 | public function isExperiment($name) |
|
87 | |||
88 | 15 | public function completeGoal($goal) |
|
89 | { |
||
90 | 15 | if (! $this->getExperiment()) { |
|
91 | 12 | $this->pageview(); |
|
92 | } |
||
93 | |||
94 | 15 | $goal = $this->getExperiment()->goals->where('name', $goal)->first(); |
|
95 | |||
96 | 15 | if (! $goal) { |
|
97 | 3 | return false; |
|
98 | } |
||
99 | |||
100 | 12 | if (session(self::SESSION_KEY_GOALS)->contains($goal->id)) { |
|
101 | 3 | return false; |
|
102 | } |
||
103 | |||
104 | 12 | session(self::SESSION_KEY_GOALS)->push($goal->id); |
|
105 | |||
106 | 12 | return tap($goal)->incrementHit(); |
|
107 | } |
||
108 | |||
109 | 27 | public function getExperiment() |
|
113 | |||
114 | 3 | public function getCompletedGoals() |
|
124 | } |
||
125 |