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 | 48 | public function __construct() |
|
23 | |||
24 | /** |
||
25 | * Validates the config items and puts them into models. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | 48 | protected function start() |
|
66 | |||
67 | /** |
||
68 | 48 | * Triggers a new visitor. Picks a new experiment and saves it to the session. |
|
69 | * |
||
70 | 48 | * @return \Ben182\AbTesting\Models\Experiment|void |
|
71 | 48 | */ |
|
72 | 42 | public function pageView() |
|
83 | |||
84 | /** |
||
85 | 42 | * Calculates a new experiment and sets it to the session. |
|
86 | * |
||
87 | 42 | * @return void |
|
88 | 42 | */ |
|
89 | protected function setNextExperiment() |
||
98 | |||
99 | /** |
||
100 | 42 | * Calculates a new experiment. |
|
101 | * |
||
102 | 42 | * @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 | 9 | * @param string $name The experiments name |
|
115 | * |
||
116 | 9 | * @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 | 15 | * @param string $goal The goals name |
|
129 | * |
||
130 | 15 | * @return \Ben182\AbTesting\Models\Goal|false |
|
131 | 12 | */ |
|
132 | public function completeGoal(string $goal) |
||
155 | |||
156 | /** |
||
157 | 42 | * Returns the currently active experiment. |
|
158 | * |
||
159 | 42 | * @return \Ben182\AbTesting\Models\Experiment|null |
|
160 | */ |
||
161 | public function getExperiment() |
||
165 | |||
166 | /** |
||
167 | 3 | * Returns all the completed goals. |
|
168 | * |
||
169 | 3 | * @return \Illuminate\Support\Collection|false |
|
170 | */ |
||
171 | public function getCompletedGoals() |
||
181 | } |
||
182 |