1 | <?php |
||
13 | class AbTesting |
||
14 | { |
||
15 | protected $experiments; |
||
16 | |||
17 | const SESSION_KEY_EXPERIMENT = 'ab_testing_experiment'; |
||
18 | const SESSION_KEY_GOALS = 'ab_testing_goals'; |
||
19 | 51 | ||
20 | public function __construct() |
||
24 | |||
25 | /** |
||
26 | * Validates the config items and puts them into models. |
||
27 | * |
||
28 | * @return void |
||
29 | 51 | */ |
|
30 | protected function start() |
||
67 | |||
68 | /** |
||
69 | * Triggers a new visitor. Picks a new experiment and saves it to the session. |
||
70 | * |
||
71 | * @return \Ben182\AbTesting\Models\Experiment|void |
||
72 | 51 | */ |
|
73 | public function pageView() |
||
90 | |||
91 | 42 | /** |
|
92 | 42 | * Calculates a new experiment and sets it to the session. |
|
93 | * |
||
94 | 42 | * @return void |
|
95 | 42 | */ |
|
96 | protected function setNextExperiment() |
||
105 | |||
106 | 42 | /** |
|
107 | * Calculates a new experiment. |
||
108 | 42 | * |
|
109 | * @return \Ben182\AbTesting\Models\Experiment|null |
||
110 | */ |
||
111 | protected function getNextExperiment() |
||
117 | |||
118 | 9 | /** |
|
119 | * Checks if the currently active experiment is the given one. |
||
120 | 9 | * |
|
121 | * @param string $name The experiments name |
||
122 | 9 | * |
|
123 | * @return bool |
||
124 | */ |
||
125 | public function isExperiment(string $name) |
||
131 | |||
132 | 15 | /** |
|
133 | * Completes a goal by incrementing the hit property of the model and setting its ID in the session. |
||
134 | 15 | * |
|
135 | 12 | * @param string $goal The goals name |
|
136 | * |
||
137 | * @return \Ben182\AbTesting\Models\Goal|false |
||
138 | 15 | */ |
|
139 | public function completeGoal(string $goal) |
||
162 | |||
163 | 42 | /** |
|
164 | * Returns the currently active experiment. |
||
165 | * |
||
166 | * @return \Ben182\AbTesting\Models\Experiment|null |
||
167 | */ |
||
168 | public function getExperiment() |
||
172 | |||
173 | 3 | /** |
|
174 | * Returns all the completed goals. |
||
175 | * |
||
176 | * @return \Illuminate\Support\Collection|false |
||
177 | */ |
||
178 | 3 | public function getCompletedGoals() |
|
188 | } |
||
189 |