1 | <?php |
||
15 | class AbTesting |
||
16 | { |
||
17 | protected $experiments; |
||
18 | protected $visitor; |
||
19 | 48 | ||
20 | const SESSION_KEY_GOALS = 'ab_testing_goals'; |
||
21 | 48 | ||
22 | 48 | public function __construct() |
|
26 | |||
27 | /** |
||
28 | * Validates the config items and puts them into models. |
||
29 | 48 | * |
|
30 | * @return void |
||
31 | 48 | */ |
|
32 | 48 | protected function start() |
|
69 | |||
70 | 48 | /** |
|
71 | 48 | * Resets the visitor data. |
|
72 | 42 | * |
|
73 | * @return void |
||
74 | 42 | */ |
|
75 | public function resetVisitor() |
||
80 | |||
81 | /** |
||
82 | * Triggers a new visitor. Picks a new experiment and saves it to the Visitor. |
||
83 | * |
||
84 | * @param int $visitor_id An optional visitor identifier |
||
85 | 42 | * |
|
86 | * @return \Ben182\AbTesting\Models\Experiment|void |
||
87 | 42 | */ |
|
88 | 42 | public function pageView($visitor_id = null) |
|
106 | |||
107 | /** |
||
108 | * Calculates a new experiment and sets it to the Visitor. |
||
109 | * |
||
110 | * @param VisitorInterface $visitor An object implementing VisitorInterface |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | 9 | protected function setNextExperiment(VisitorInterface $visitor) |
|
121 | |||
122 | /** |
||
123 | * Calculates a new experiment. |
||
124 | * |
||
125 | * @return \Ben182\AbTesting\Models\Experiment |
||
126 | */ |
||
127 | protected function getNextExperiment() |
||
133 | |||
134 | 15 | /** |
|
135 | * Checks if the currently active experiment is the given one. |
||
136 | 15 | * |
|
137 | 3 | * @param string $name The experiments name |
|
138 | * |
||
139 | * @return bool |
||
140 | 12 | */ |
|
141 | 3 | public function isExperiment(string $name) |
|
147 | 12 | ||
148 | /** |
||
149 | 12 | * Completes a goal by incrementing the hit property of the model and setting its ID in the session. |
|
150 | * |
||
151 | * @param string $goal The goals name |
||
152 | * @param int $visitor_id An optional visitor identifier |
||
153 | * |
||
154 | * @return \Ben182\AbTesting\Models\Goal|false |
||
155 | */ |
||
156 | public function completeGoal(string $goal, $visitor_id = null) |
||
177 | |||
178 | /** |
||
179 | * Returns the currently active experiment. |
||
180 | * |
||
181 | * @param int $visitor_id An optional visitor identifier |
||
182 | * |
||
183 | * @return \Ben182\AbTesting\Models\Experiment|null |
||
184 | */ |
||
185 | public function getExperiment($visitor_id = null) |
||
189 | |||
190 | /** |
||
191 | * Returns all the completed goals. |
||
192 | * |
||
193 | * @return \Illuminate\Support\Collection|false |
||
194 | */ |
||
195 | public function getCompletedGoals() |
||
205 | |||
206 | /** |
||
207 | * Returns a visitor instance. |
||
208 | * |
||
209 | * @param int $visitor_id An optional visitor identifier |
||
210 | * |
||
211 | * @return \Ben182\AbTesting\Models\SessionVisitor|\Ben182\AbTesting\Models\DatabaseVisitor |
||
212 | */ |
||
213 | public function getVisitor($visitor_id = null) |
||
225 | } |
||
226 |