Skip to content

Commit 57a30fe

Browse files
feat: add tracking opt-in checkbox (#507)
1 parent 9791418 commit 57a30fe

5 files changed

Lines changed: 53 additions & 0 deletions

File tree

assets/css/style-wizard.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,19 @@ h2.wpmm-title span img {
296296
font-size: 18px;
297297
}
298298

299+
.subscribe-step .opt-in-container {
300+
display: flex;
301+
gap: 8px;
302+
margin-top: 20px;
303+
}
304+
305+
.subscribe-step .opt-in-container svg.components-checkbox-control__checked {
306+
top: 20%;
307+
}
308+
309+
.subscribe-step .opt-in-container label {
310+
text-align: left;
311+
}
299312
#email-input-wrap {
300313
position: relative;
301314
display: flex;

assets/js/scripts-admin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,13 @@ jQuery( function( $ ) {
429429

430430
emailInput.removeClass( 'invalid' );
431431
subscribeButton.addClass( 'is-busy' );
432+
const optIn = $('#wizard-opt-in').is( ':checked' );
432433

433434
$.post( wpmmVars.ajaxURL, {
434435
action: 'wpmm_subscribe',
435436
email,
436437
_wpnonce: wpmmVars.wizardNonce,
438+
opt_in: optIn ? 1 : 0,
437439
}, function( response ) {
438440
if ( ! response.success ) {
439441
alert( response.data );

includes/classes/wp-maintenance-mode-admin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,10 @@ public function subscribe_newsletter() {
806806
die( esc_html__( 'Empty field: email', 'wp-maintenance-mode' ) );
807807
}
808808

809+
if ( isset( $_POST['opt_in'] ) && sanitize_text_field( $_POST['opt_in'] ) ) {
810+
update_option( 'wp_maintenance_mode_logger_flag', 'yes' );
811+
}
812+
809813
$response = wp_remote_post(
810814
self::SUBSCRIBE_ROUTE,
811815
array(

includes/classes/wp-maintenance-mode.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ function() {
159159
}
160160
);
161161
}
162+
163+
add_action( 'init', array( $this, 'initialize_telemetry' ) );
164+
162165
}
163166

164167
/**
@@ -1449,6 +1452,30 @@ public function set_current_page_category( $category ) {
14491452
public function get_current_page_category() {
14501453
return $this->current_page_category;
14511454
}
1455+
1456+
/**
1457+
* Initialize telemetry.
1458+
*
1459+
* @return void
1460+
*/
1461+
public function initialize_telemetry() {
1462+
if ( 'yes' === get_option( 'wp_maintenance_mode_logger_flag' ) ) {
1463+
add_filter( 'themeisle_sdk_enable_telemetry', '__return_true' );
1464+
add_filter(
1465+
'themeisle_sdk_telemetry_products',
1466+
function( $products ) {
1467+
foreach ( $products as &$product ) {
1468+
if ( isset( $product['slug'] ) && 'wp' === $product['slug'] ) {
1469+
$product['slug'] = 'wp_maintenance_mode';
1470+
}
1471+
}
1472+
1473+
return $products;
1474+
}
1475+
);
1476+
}
1477+
1478+
}
14521479
}
14531480

14541481
}

views/wizard.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@
116116
<input type="text" value="<?php echo esc_attr( get_bloginfo( 'admin_email' ) ); ?>" />
117117
<input type="button" class="button button-primary button-big subscribe-button" value="<?php esc_attr_e( 'Sign me up', 'wp-maintenance-mode' ); ?>" />
118118
</div>
119+
<div class="opt-in-container">
120+
<span class="components-checkbox-control__input-container">
121+
<input id="wizard-opt-in" type="checkbox" class="components-checkbox-control__input" checked>
122+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="presentation" class="components-checkbox-control__checked" aria-hidden="true" focusable="false"><path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"></path></svg>
123+
</span>
124+
<label for="wizard-opt-in"><?php echo esc_html__( 'Help us improve LightStart by opting in to anonymous usage tracking. No sensitive data is collected.', 'wp-maintenance-mode' ); ?></label>
125+
</div>
119126
<input id="skip-subscribe" type="button" class="button button-link skip-link" value="<?php esc_attr_e( 'I\'ll skip for now, thanks!', 'wp-maintenance-mode' ); ?>" />
120127
</div>
121128
</div>

0 commit comments

Comments
 (0)