How to Create an A/B Test

Título

OldNew
11How to Create an A/B Test

Permalink

OldNew
11how_to_create_a_b_testing

Conteúdo

OldNew
11# How To Create an A/B Test
2
3Creating an A/B test can be done very simple with LiteCart. Here is how you can randomize the testing of different variations and report the results to an analytics service like Google Analytics or Matomo.
4
5```php
6// Determine if we need to assign a variation (A, B [, or C])
7if (empty(session::$data['ab_tests']['test1'])) {
8 $variations = ['a', 'b', 'c'];
9 session::$data['ab_tests']['test1'] = $variations[array_rand($variations)];
10}
11
12// Do variation
13switch (session::$data['ab_tests']['test1']) {
14
15 case 'a':
16 // Do something for A
17 break;
18
19 case 'b':
20 // Do something for B
21 break;
22
23 case 'c':
24 // Do something for C
25 break;
26}
27```
28
29Report Variation with Google GTag:
30
31```html
32<script>
33 gtag('event', 'experiment_impression', {
34 'experiment_id': 'test_1',
35 'variant_id': '<?php echo session::$data['ab_tests']['test1']; ?>'
36 });
37</script>
38```
39
40Report Variation with Matomo:
41
42```html
43<script>
44 _paq.push(['AbTesting::enter', {
45 experiment: 'test_1',
46 variation: '<?php echo session::$data['ab_tests']['test1']; ?>'
47 }]);
48</script>
49```

Edited by tim on 26 fev 2025 at 20:29

This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.