Titolo
Old | New |
---|
1 | | 1 | How to Create an A/B Test |
---|
Collegamento permanente
Old | New |
---|
1 | | 1 | how_to_create_a_b_testing |
---|
contenuto
Old | New |
---|
1 | | 1 | # How To Create an A/B Test
|
---|
| | 2 |
|
---|
| | 3 | Creating 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])
|
---|
| | 7 | if (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
|
---|
| | 13 | switch (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 |
|
---|
| | 29 | Report 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 |
|
---|
| | 40 | Report 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 | ``` |
---|
Modificato da tim il 26 feb 2025 alle 20:29