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