1 | <?php |
||
12 | class AbTesting |
||
13 | { |
||
14 | protected $experiments; |
||
15 | |||
16 | const SESSION_KEY_EXPERIMENT = 'ab_testing_experiment'; |
||
17 | const SESSION_KEY_GOALS = 'ab_testing_goals'; |
||
18 | |||
19 | 51 | public function __construct() |
|
23 | |||
24 | /** |
||
25 | * Validates the config items and puts them into models. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | 51 | protected function start() |
|
66 | |||
67 | /** |
||
68 | * Triggers a new visitor. Picks a new experiment and saves it to the session. |
||
69 | * |
||
70 | * @return \Ben182\AbTesting\Models\Experiment|void |
||
71 | */ |
||
72 | 51 | public function pageView() |
|
83 | |||
84 | /** |
||
85 | * Calculates a new experiment and sets it to the session. |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | 42 | protected function setNextExperiment() |
|
98 | |||
99 | /** |
||
100 | * Calculates a new experiment. |
||
101 | * |
||
102 | * @return \Ben182\AbTesting\Models\Experiment|null |
||
103 | */ |
||
104 | 42 | protected function getNextExperiment() |
|
110 | |||
111 | /** |
||
112 | * Checks if the currently active experiment is the given one. |
||
113 | * |
||
114 | * @param string $name The experiments name |
||
115 | * |
||
116 | * @return bool |
||
117 | */ |
||
118 | 9 | public function isExperiment(string $name) |
|
124 | |||
125 | /** |
||
126 | * Completes a goal by incrementing the hit property of the model and setting its ID in the session. |
||
127 | * |
||
128 | * @param string $goal The goals name |
||
129 | * |
||
130 | * @return \Ben182\AbTesting\Models\Goal|false |
||
131 | */ |
||
132 | 15 | public function completeGoal(string $goal) |
|
155 | |||
156 | /** |
||
157 | * Returns the currently active experiment. |
||
158 | * |
||
159 | * @return \Ben182\AbTesting\Models\Experiment|null |
||
160 | */ |
||
161 | 42 | public function getExperiment() |
|
165 | |||
166 | /** |
||
167 | * Returns all the completed goals. |
||
168 | * |
||
169 | * @return \Illuminate\Support\Collection|false |
||
170 | */ |
||
171 | 3 | public function getCompletedGoals() |
|
181 | } |
||
182 |