-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetting-started.html
More file actions
262 lines (241 loc) · 13.6 KB
/
getting-started.html
File metadata and controls
262 lines (241 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Getting started - The A/B testing framework for PHP.</title>
<meta name="description"
content="PhpAb is a A/B testing framework which can be used to perform multivariate testing.">
<meta name="keywords" content="ab testing,phpab,multivariate,framework,tests,test">
<meta name="application-name" content="PhpAb">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css">
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/styles/default.min.css">
<link rel="stylesheet" href="https://phpab.github.io/css/website.css">
<link rel="icon" href="https://phpab.github.io/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="https://phpab.github.io/favicon.ico" type="image/x-icon"/>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"
integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/highlight.min.js"></script>
<script>
$(function () {
hljs.initHighlightingOnLoad();
});
</script>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-76115045-1', 'auto');
ga('send', 'pageview');
</script>
<script src="//www.google-analytics.com/cx/api.js"></script>
<script>ga('set', 'VCq5cVWGS3mbuUyCXmUN2w', 0);</script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://phpab.github.io/"><strong>PhpAb</strong></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="https://phpab.github.io/docs/index.html">Documentation</a></li>
<li><a class="github" href="https://github.com/phpab/phpab"><i class="fa fa-github"></i></a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-3 documentation-menu">
<strong>Introduction</strong>
<ul>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/getting-started.html">
Getting started
</a>
</li>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/library-layout.html">
Library layout
</a>
</li>
</ul>
<strong>Components</strong>
<ul>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/components/analytics.html">
Analytics
</a>
</li>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/components/events.html">
Events
</a>
</li>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/components/participation.html">
Participation
</a>
</li>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/components/storage.html">
Storage
</a>
</li>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/components/variants.html">
Variants
</a>
</li>
</ul>
<strong>Frameworks Integrations</strong>
<ul>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/frameworks/symfony2.html">
Symfony 2
</a>
</li>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/frameworks/wordpress.html">
Wordpress
</a>
</li>
<li role="presentation" class="">
<a href="https://phpab.github.io/docs/frameworks/zf2.html">
Zend Framework 2
</a>
</li>
</ul>
</div>
<div class="col-md-9">
<article>
<div class="pull-right">
<a href="https://github.com/phpab/phpab.github.io/blob/source/source/docs/getting-started.md"
class="btn btn-default btn-sm">
Edit this page on GitHub
<i class="fa fa-github"></i>
</a>
</div>
<h1 id="getting-started-with-phpab">Getting started with PhpAb</h1>
<p>Hello world! This guide will help you get started with using php in your project.</p>
<p>Before you start using phpab/phpab, you need to know what A/B testing is. If you are new to
A/B testing we recommend you read the documentation index where we explain the basics of A/B testing
especially for you: <a href="index.html">Understanding A/B testing</a>.</p>
<h2 id="installation">Installation</h2>
<p>The recommended way of installing phpab/phpab is via <a href="http://getcomposer.org/doc/00-intro.html">Composer</a>.</p>
<pre><code>composer require phpab/phpab</code></pre>
<h2 id="basic-usage">Basic usage</h2>
<h3 id="1-participation-and-storage">1. Participation and Storage</h3>
<p>It's common to only run tests for a selected group of people. This can be done using a participation
manager. When tests are activated, we need to store the choice that has been made for the user. This
is done using a storage type. In this case we use cookies.</p>
<pre><code class="language-php">$storage = new \PhpAb\Storage\Cookie('phpab');
$participationManager = new \PhpAb\Participation\Manager($storage);</code></pre>
<p>We have implemented several storage types, you can read more about them <a href="storage.html">here</a>.</p>
<h3 id="2-analytics-collecting">2. Analytics Collecting</h3>
<p>It makes no sense to run tests without analyzing the results. A common way is to use Google Analytics to
meassure what tests are used. Phpab makes used of data collectors to collect the started tests.</p>
<pre><code class="language-php">$analyticsData = new \PhpAb\Analytics\Google\DataCollector();</code></pre>
<h3 id="3-events">3. Events</h3>
<p>An event dispatcher must be created which is used later on. This event dispatcher can be used to hook
into the API and listen to tests. The analytics data collector should be attached to the event dispatcher
so that it registers statistics about the tests.</p>
<pre><code class="language-php">$dispatcher = new \PhpAb\Event\Dispatcher();
$dispatcher->addSubscriber($analyticsData);</code></pre>
<h3 id="4-engine">4. Engine</h3>
<p>The engine is used to run tests. You can pass along a default variant chooser and participation filter
here as well. More about that later on.</p>
<pre><code class="language-php">$filter = new \PhpAb\Participation\PercentageFilter(50);
$chooser = new \PhpAb\Variant\RandomChooser();
$engine = new PhpAb\Engine\Engine($participationManager, $dispatcher, $filter, $chooser);</code></pre>
<h3 id="5-adding-tests">5. Adding Tests</h3>
<p>Adding a test is simple,</p>
<pre><code class="language-php">$test = new \PhpAb\Test\Test('foo_test');
$test->addVariant(new \PhpAb\Variant\SimpleVariant('_control'));
$test->addVariant(new \PhpAb\Variant\CallbackVariant('v1', function () {
echo 'v1';
}));
$test->addVariant(new \PhpAb\Variant\CallbackVariant('v2', function () {
echo 'v2';
}));
$test->addVariant(new \PhpAb\Variant\CallbackVariant('v3', function () {
echo 'v3';
}));
$engine->addTest($test);</code></pre>
<h3 id="6-start-your-engines">6. Start your engines</h3>
<p>The last step is to start the engine and render the Google Analytics script.</p>
<pre><code class="language-php">$engine->start();</code></pre>
<pre><code class="language-php">$analytics = new \PhpAb\Analytics\Renderer\GoogleUniversalAnalytics($analyticsData->getTestsData());
echo $analytics->getScript();</code></pre>
</article>
</div>
</div>
</div>
<footer>
<div class="container">
<p>
For questions, bugs or if you want to let us know how much you appreciate this library,
please <a href="https://github.com/phpab/phpab/issues/new">create an issue</a>
or chat with us on <a href="https://gitter.im/phpab">Gitter</a>.
</p>
<p>
</p>
<p>
Created by
<a href="http://waltertamboer.nl/">Walter Tamboer</a>,
<a href="https://github.com/pachico">Mariano Benítez Mulet</a>,
<a href="https://github.com/psren">Patrick Heller</a>
and all <a href="https://github.com/phpab/phpab/graphs/contributors">contributors</a>
</p>
<p>
Website generated with <a href="http://couscous.io">Couscous</a> | Design is heavily inspired by
<a href="http://php-di.org">PHP-DI</a>
</p>
<p style="margin-top: 25px;">
<a href="https://packagist.org/packages/phpab/phpab"><img src="https://img.shields.io/packagist/v/phpab/phpab.svg?style=flat-square" style="max-width:100%;"></a>
<a href="https://github.com/phpab/phpab/blob/master/LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square" style="max-width:100%;"></a>
<a href="https://travis-ci.org/phpab/phpab"><img src="https://img.shields.io/travis/phpab/phpab/master.svg?style=flat-square" style="max-width:100%;"></a>
<a href="https://scrutinizer-ci.com/g/phpab/phpab/code-structure"><img src="https://img.shields.io/scrutinizer/coverage/g/phpab/phpab.svg?style=flat-square" style="max-width:100%;"></a>
<a href="https://scrutinizer-ci.com/g/phpab/phpab"><img src="https://img.shields.io/scrutinizer/g/phpab/phpab.svg?style=flat-square" style="max-width:100%;"></a>
<a href="https://packagist.org/packages/phpab/phpab"><img src="https://img.shields.io/packagist/dt/phpab/phpab.svg?style=flat-square" style="max-width:100%;"></a></p>
</div>
</footer>
<script>
((window.gitter = {}).chat = {}).options = {
room: 'phpab'
};
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>
</body>
</html>