diff --git a/includes/DeactivationSurvey.php b/includes/DeactivationSurvey.php index f6f4149..476b5f6 100644 --- a/includes/DeactivationSurvey.php +++ b/includes/DeactivationSurvey.php @@ -79,6 +79,12 @@ public function __construct() { __( 'Need Help? Check the help center 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 diff --git a/static/js/deactivation-survey.js b/static/js/deactivation-survey.js index e5b6a11..350b207 100644 --- a/static/js/deactivation-survey.js +++ b/static/js/deactivation-survey.js @@ -105,6 +105,11 @@
+
@@ -185,6 +190,7 @@ isSubmitting(); let surveyInput = 'No input'; + let deactivationDuration = ''; if ( ! skipped ) { const inputValue = document.getElementById( 'nfd-deactivation-survey__input' @@ -192,27 +198,32 @@ 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: { @@ -220,7 +231,7 @@ 'X-WP-Nonce': runtimeData.restApiNonce, }, body: JSON.stringify( { - action: 'deactivation_survey_freeform', + action: actionName, data: eventData, } ), } );