Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Press0 1415 #14

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions includes/DeactivationSurvey.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public function __construct() {
__( 'Need Help? Check the <a href="%s">help center</a> for support.', 'wp-module-deactivation' ),
'/wp-admin/admin.php?page=' . container()->plugin()->id . '#/help'
),
'durationOption1' => __( '1 Hour','wp-module-deactivation' ),
'durationOption1Value' => __( '1_hour','wp-module-deactivation' ),
'durationOption2' => __( '24 Hours','wp-module-deactivation' ),
'durationOption2Value' => __( '24_hours','wp-module-deactivation' ),
'durationOption3' => __( 'Until I turn it back on','wp-module-deactivation' ),
'durationOption3Value' => __( 'until_manual','wp-module-deactivation' ),
);

// Merge defaults with container values from plugin
Expand Down
23 changes: 17 additions & 6 deletions static/js/deactivation-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
</div>
<div class="nfd-deactivation-survey__content-actions">
<button type="button" class="nfd-deactivation-survey-action" nfd-deactivation-survey-skip aria-label="${ runtimeData.strings.skipAriaLabel }">${ runtimeData.strings.skip }</button>
<select id="deactivation-duration" name="deactivation_duration" class="nfd-deactivation-duration">
<option value=${ runtimeData.strings.durationOption1Value }>${ runtimeData.strings.durationOption1 }</option>
<option value=${ runtimeData.strings.durationOption2Value }>${ runtimeData.strings.durationOption2 }</option>
<option value=${ runtimeData.strings.durationOption3Value } selected>${ runtimeData.strings.durationOption3 }</option>
</select>
<input type="submit" value="${ runtimeData.strings.submit }" nfd-deactivation-survey-submit class="button button-primary" aria-label="${ runtimeData.strings.submitAriaLabel }"/>
</div>
</div></div>
Expand Down Expand Up @@ -185,42 +190,48 @@
isSubmitting();

let surveyInput = 'No input';
let deactivationDuration = '';
if ( ! skipped ) {
const inputValue = document.getElementById(
'nfd-deactivation-survey__input'
).value;
if ( inputValue.length > 0 ) {
surveyInput = inputValue;
}
deactivationDuration = document.getElementById(
'deactivation-duration'
).value;
}

// Send event
const send = await sendEvent( surveyInput );
const sendSurveyInput = await sendEvent( surveyInput,'');
const sendDeactivationDuration = await sendEvent( '', deactivationDuration);
deactivatePlugin();
};

const sendEvent = async ( surveyInput ) => {
const sendEvent = async ( surveyInput = '', deactivationDuration = '' ) => {
const eventData = {
label_key: 'survey_input',
survey_input: surveyInput,
label_key: surveyInput ? 'survey_input' : 'deactivation_duration',
category: 'user_action',
brand: runtimeData.brand,
page: window.location.href,
...surveyInput && { survey_input: surveyInput },
...deactivationDuration && { deactivation_duration: deactivationDuration },
};

// Attach abTestPluginHome flag value if exists
if ( typeof getABTestPluginHome() === 'boolean' ) {
eventData.abTestPluginHome = getABTestPluginHome();
}

const actionName = surveyInput ? 'deactivation_survey_freeform' : 'deactivation_duration';
await fetch( runtimeData.eventsEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': runtimeData.restApiNonce,
},
body: JSON.stringify( {
action: 'deactivation_survey_freeform',
action: actionName,
data: eventData,
} ),
} );
Expand Down
Loading