PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.53.2
Advanced Ads – Ad Manager & AdSense v1.53.2
2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / modules / pef / class-module.php
advanced-ads / modules / pef Last commit date
assets 2 years ago views 2 years ago class-module.php 2 years ago main.php 2 years ago
class-module.php
229 lines
1 <?php
2 /**
3 * PEF module
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 */
8
9 namespace AdvancedAds\Modules\ProductExperimentationFramework;
10
11 /**
12 * Module main class
13 */
14 class Module {
15 /**
16 * Current running features
17 *
18 * @var array[]
19 */
20 const FEATURES = [
21 'labs-video-ads' => [
22 'name' => 'Video Ads',
23 'weight' => 1,
24 'text' => 'The Advanced Ads team is developing a new feature to support video ads. This enables embedding videos from your WordPress media library and video ad networks. Like image ads, they would be fully compatible with all conditions and placements. We are curious whether our users want us to prioritize this feature.',
25 ],
26 'labs-email-notifications' => [
27 'name' => 'Email Notifications',
28 'weight' => 1,
29 'text' => 'The Advanced Ads team is developing a new feature to improve email notifications. Imagine receiving timely reminders in your inbox, giving you ample time to take action. Whether renewing an ad, adjusting ad groups, or checking the statistics after a campaign has ended, you’ll be in the know every step of the way. We are curious whether our users want us to prioritize this feature.',
30 ],
31 'labs-image-mapping' => [
32 'name' => 'Image Mapping',
33 'weight' => 1,
34 'text' => 'The Advanced Ads team is developing a new feature to allow serving multiple images with the same ad unit. This workflow can save you time in certain setups and is an alternative to ad groups when it comes to multiple campaigns from the same advertiser. We are curious whether our users want us to prioritize this feature.',
35 ],
36 'labs-automated-split-tests' => [
37 'name' => 'Automated Split Tests',
38 'weight' => 1,
39 'text' => 'The Advanced Ads team is working on a new feature to simplify your workload: automated split testing. Let us handle the heavy lifting for you by automatically maximizing your ad performance based on the CTR of your ad units. We are curious whether our users want us to prioritize this feature.',
40 ],
41 'labs-ad-preview' => [
42 'name' => 'Ad Preview',
43 'weight' => 1,
44 'text' => 'The Advanced Ads team is developing a new feature: ad previews. Simply input the code in the Parameter box, and watch your ad come to life on the Edit Ad page. We are curious whether our users want us to prioritize this feature.',
45 ],
46 'labs-animated-ads' => [
47 'name' => 'Animated Ads',
48 'weight' => 1,
49 'text' => 'The Advanced Ads team is developing a new feature to allow animating ads. Captivate your audience with eye-catching effects like flip, slider, and fade. Enhance engagement and leave a lasting impression with dynamic ad displays. We are curious whether our users want us to prioritize this feature.',
50 ],
51 'labs-active-view-tracking' => [
52 'name' => 'Active View Tracking',
53 'weight' => 1,
54 'text' => 'The Advanced Ads team is developing a new feature to enable active view tracking. Gain precise insights into ad viewability and upgrade your metrics. With active view tracking, you’ll know if your ad is loaded and visible in the viewport. We are curious whether our users want us to prioritize this feature.',
55 ],
56 'labs-ad-schedule-wizard' => [
57 'name' => 'Ad Schedule Wizard',
58 'weight' => 1,
59 'text' => 'The Advanced Ads team is developing a better ad scheduling and planning interface. Simplify your workflow and maximize efficiency. With an improved user experience, managing your ads could be easier than ever. We are curious whether our users want us to prioritize this feature.',
60 ],
61 'labs-reports-insights' => [
62 'name' => 'Reports & Insights',
63 'weight' => 1,
64 'text' => 'The Advanced Ads team is improving the reporting. Customize your email reports to focus on the metrics that most matter to you and easily share them as PDFs. Empower yourself with actionable data and streamline communication with stakeholders. We are curious whether our users want us to prioritize this feature.',
65 ],
66 ];
67
68 /**
69 * User meta key where the dismiss flag is stored.
70 *
71 * @var string
72 */
73 const USER_META = 'advanced_ads_pef_dismiss';
74
75 /**
76 * The singleton
77 *
78 * @var Module
79 */
80 private static $instance;
81
82 /**
83 * Sum of all weights
84 *
85 * @var int
86 */
87 private $weight_sum = 0;
88
89 /**
90 * ID => weight association
91 *
92 * @var int[]
93 */
94 private $weights = [];
95
96 /**
97 * Whether the PEF can be displayed based on user meta
98 *
99 * @var bool
100 */
101 private $can_display = true;
102
103 /**
104 * Private constructor
105 */
106 private function __construct() {
107 // Wait for `admin_init` to get the current user.
108 add_action( 'admin_init', [ $this, 'admin_init' ] );
109 }
110
111 /**
112 * Initialization
113 *
114 * @return void
115 */
116 public function admin_init() {
117 $meta = get_user_meta( get_current_user_id(), self::USER_META, true );
118 if ( $this->get_minor_version( ADVADS_VERSION ) === $this->get_minor_version( $meta ) ) {
119 $this->can_display = false;
120
121 return;
122 }
123 $this->collect_weights();
124 add_action( 'wp_ajax_advanced_ads_pef', [ $this, 'dismiss' ] );
125 }
126
127 /**
128 * Ajax action to hie PEF for the current user until next plugin update
129 *
130 * @return void
131 */
132 public function dismiss() {
133 if ( ! check_ajax_referer( 'advanced_ads_pef' ) ) {
134 wp_send_json_error( 'Unauthorized', 401 );
135 }
136 update_user_meta( get_current_user_id(), self::USER_META, ADVADS_VERSION );
137 wp_send_json_success( 'OK', 200 );
138 }
139
140 /**
141 * Collect feature ID with their weight as recorded in the class constant. Also calculate the weight sum
142 */
143 private function collect_weights() {
144 if ( 0 !== $this->weight_sum ) {
145 return;
146 }
147 foreach ( self::FEATURES as $id => $feature ) {
148 $this->weights[ $id ] = (int) $feature['weight'];
149 $this->weight_sum += $this->weights[ $id ];
150 }
151 }
152
153 /**
154 * Get a random feature based on weights and a random number
155 *
156 * @return array
157 */
158 public function get_winner_feature() {
159 $random_weight = mt_rand( 1, $this->weight_sum );
160 $current_weight = 0;
161 foreach ( self::FEATURES as $id => $feature ) {
162 $current_weight += $this->weights[ $id ];
163 if ( $random_weight <= $current_weight ) {
164 return array_merge(
165 [
166 'id' => $id,
167 'weight' => $this->weights[ $id ],
168 ],
169 self::FEATURES[ $id ]
170 );
171 }
172 }
173 }
174
175 /**
176 * Render PEF
177 *
178 * @param string $screen the screen on which PEF is displayed, used in the utm_campaign parameter.
179 *
180 * @return void
181 */
182 public function render( $screen ) {
183 if ( ! $this->can_display ) {
184 return;
185 }
186 $winner = $this->get_winner_feature();
187 require_once DIR . '/views/template.php';
188 }
189
190 /**
191 * Get minor part of a version
192 *
193 * @param string $version version to get the minor part from.
194 *
195 * @return string
196 */
197 public function get_minor_version( $version ) {
198 return explode( '.', $version )[1] ?? '0';
199 }
200
201 /**
202 * Build the link for the winner feature with all its utm parameters
203 *
204 * @param array $winner the winner feature.
205 * @param string $screen the screen on which it was displayed.
206 *
207 * @return string
208 */
209 public function build_link( $winner, $screen ) {
210 $link = "https://wpadvancedads.com/advanced-ads-labs/?utm_source=advanced-ads&utm_medium=link&utm_campaign=$screen-aa-labs&utm_term=b";
211 $link .= str_replace( '.', '-', ADVADS_VERSION ) . "w{$winner['weight']}-{$this->weight_sum}&utm_content={$winner['id']}";
212
213 return $link;
214 }
215
216 /**
217 * Return the singleton. Create it if needed
218 *
219 * @return Module
220 */
221 public static function get_instance() {
222 if ( null === self::$instance ) {
223 self::$instance = new self();
224 }
225
226 return self::$instance;
227 }
228 }
229