From 6b3ad34d1274e0c47ba0dc05fe677c256bf6ce86 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 5 Jun 2024 13:42:33 -0400 Subject: [PATCH 1/3] tweak survey input event this sends (No Input) or (Skipped) if the input field is blank so we can distinguish between them --- static/js/deactivation-survey.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/static/js/deactivation-survey.js b/static/js/deactivation-survey.js index e5b6a11..169816f 100644 --- a/static/js/deactivation-survey.js +++ b/static/js/deactivation-survey.js @@ -183,15 +183,17 @@ const submitSurvey = async ( skipped = false ) => { isSubmitting(); + let surveyInput = ''; - let surveyInput = 'No input'; - if ( ! skipped ) { - const inputValue = document.getElementById( - 'nfd-deactivation-survey__input' - ).value; - if ( inputValue.length > 0 ) { - surveyInput = inputValue; - } + const input = document.getElementById( + 'nfd-deactivation-survey__input' + ).value; + if ( input.length > 0 ) { + surveyInput = input; + } else if ( skipped ) { + surveyInput = '(Skipped)'; + } else { + surveyInput = '(No Input)'; } // Send event From d934fd877824859d23a853625687a215f14c8cac Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 5 Jun 2024 13:43:25 -0400 Subject: [PATCH 2/3] return promises and deactivate plugin in `then` to ensure the event has been sent --- static/js/deactivation-survey.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/static/js/deactivation-survey.js b/static/js/deactivation-survey.js index 169816f..8da55bb 100644 --- a/static/js/deactivation-survey.js +++ b/static/js/deactivation-survey.js @@ -197,8 +197,9 @@ } // Send event - const send = await sendEvent( surveyInput ); - deactivatePlugin(); + return await sendEvent( surveyInput ).then( () => { + deactivatePlugin(); + } ); }; const sendEvent = async ( surveyInput ) => { @@ -215,7 +216,7 @@ eventData.abTestPluginHome = getABTestPluginHome(); } - await fetch( runtimeData.eventsEndpoint, { + return await fetch( runtimeData.eventsEndpoint, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -226,7 +227,6 @@ data: eventData, } ), } ); - return true; }; const getABTestPluginHome = () => { From ad58130f68f572cca69fde16c59e290cdc895d1f Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Wed, 5 Jun 2024 13:46:07 -0400 Subject: [PATCH 3/3] simplify default value --- static/js/deactivation-survey.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/static/js/deactivation-survey.js b/static/js/deactivation-survey.js index 8da55bb..7bd520d 100644 --- a/static/js/deactivation-survey.js +++ b/static/js/deactivation-survey.js @@ -183,17 +183,13 @@ const submitSurvey = async ( skipped = false ) => { isSubmitting(); - let surveyInput = ''; + let surveyInput = skipped ? '(Skipped)' : '(No Input)'; const input = document.getElementById( 'nfd-deactivation-survey__input' ).value; if ( input.length > 0 ) { surveyInput = input; - } else if ( skipped ) { - surveyInput = '(Skipped)'; - } else { - surveyInput = '(No Input)'; } // Send event