PluginProbe
Extendify / 3.2.3
Extendify v3.2.3
3.2.3 3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 All 129 releases
← All changes | app/Insights.php +38 -11 3.1.0 → 3.2.3 View file →
@@ -7,8 +7,11 @@
7 7 namespace Extendify;
8 8
9 9 defined('ABSPATH') || die('No direct access.');
10 10
11 +use Extendify\Mcp\Availability;
12 +use Extendify\Mcp\Connections;
13 +use Extendify\Mcp\Log;
11 14 use Extendify\Shared\Services\Sanitizer;
12 15 use Extendify\PartnerData;
13 16
14 17 /**
@@ -19,9 +22,9 @@
19 22 class Insights
20 23 {
21 24 /**
22 25 * Option name storing each site's A/B test assignments, keyed by the
23 - * screen/feature under test (e.g. 'AutoLaunch.WebsiteTitle').
26 + * screen/feature under test (e.g. 'AutoLaunch.HideEnhanceAI').
24 27 *
25 28 * @var string
26 29 */
27 30 // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound
@@ -27,15 +30,19 @@
27 30 // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound
28 31 const ACTIVE_TESTS_OPTION = 'extendify_active_tests';
29 32
30 33 /**
31 - * Tests the plugin knows how to run, each mapped to its available variants.
34 + * Tests the plugin knows how to run. Each is rolled independently against
35 + * its own rollout percentage, which the partner config supplies.
32 36 *
33 - * @var array<string, string[]>
37 + * @var string[]
34 38 */
35 39 // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound
36 - const ACTIVE_TESTS = [
37 - 'AutoLaunch.WebsiteTitle' => ['A', 'B'],
40 + const AVAILABLE_TESTS = [
41 + 'AutoLaunch.HideEnhanceAI',
42 + 'AutoLaunch.SubmitCreateWebsite',
43 + 'AutoLaunch.DescriptionPlaceholderLaw',
44 + 'AutoLaunch.MigrateScreen',
38 45 ];
39 46
40 47 /**
41 48 * Process the readme file to get version and name
@@ -68,12 +75,14 @@
68 75 }
69 76
70 77 /**
71 78 * Assign A/B variants for the known tests based on the partner's active
72 - * tests. Each active test is rolled once and kept on return visits;
79 + * tests. Each active test is rolled once;
73 80 * inactive tests are dropped.
74 81 *
75 - * @param string[] $activeTests Test keys the partner has enabled.
82 + * @param string[] $activeTests Active tests in `Name:Percentage` form
83 + * (e.g. 'AutoLaunch.HideEnhanceAI:20'); a bare
84 + * name defaults to a 50% rollout.
76 85 * @return void
77 86 */
78 87 public static function setup(array $activeTests = [])
79 88 {
@@ -78,17 +87,30 @@
78 87 public static function setup(array $activeTests = [])
79 88 {
80 89 $assignments = \get_option(self::ACTIVE_TESTS_OPTION, []);
81 90
82 - foreach (self::ACTIVE_TESTS as $key => $variants) {
83 - if (!in_array($key, $activeTests, true)) {
91 + $percentages = [];
92 + foreach ($activeTests as $entry) {
93 + list($key, $percentage) = array_pad(explode(':', $entry, 2), 2, null);
94 + $percentages[$key] = is_numeric($percentage) ? (float) $percentage : 50.0;
95 + }
96 +
97 + foreach (self::AVAILABLE_TESTS as $key) {
98 + if (!array_key_exists($key, $percentages)) {
84 99 unset($assignments[$key]);
85 100 continue;
86 101 }
87 102
88 - // Roll once so a returning visitor keeps the same variant.
103 + // Roll once so the site keeps the same variant.
89 104 if (!isset($assignments[$key])) {
90 - $assignments[$key] = $variants[random_int(0, count($variants) - 1)];
105 + $assignments[$key] = [
106 + // The percentage is variant B's rollout share: 50 -> 50% A / 50% B,
107 + // 20 -> 80% A / 20% B.
108 + 'variant' => random_int(1, 10000) <= $percentages[$key] * 100 ? 'B' : 'A',
109 + 'percentage' => $percentages[$key],
110 + // ISO 8601 (UTC)
111 + 'assignedAt' => gmdate('c'),
112 + ];
91 113 }
92 114 }
93 115
94 116 \update_option(self::ACTIVE_TESTS_OPTION, Sanitizer::sanitizeArray($assignments));
@@ -130,8 +152,13 @@
130 152 'lastUpdatedPost' => $this->getLastUpdatedPost('post'),
131 153 'lastLoginAdmin' => $this->getLastAdminLogin(),
132 154 'hasImprint' => $this->hasImprint(),
133 155 ]);
156 +
157 + if (Availability::offered()) {
158 + $insights['mcp'] = ['usage' => Log::usage(), 'connections' => Connections::count()];
159 + }
160 +
134 161 return $insights;
135 162 });
136 163 }
137 164