Code to Close survey embed once survey is completed and pass custom variable

window.sparrowConfig = {

triggerOnLoad: false

}

window.SparrowLauncher('popup', {

variables: {

name: "John Doe", 

useremail: "john@acmeinc.com"

}

})

window.addEventListener('message', (e) => {

if(e && e.data && e.data.type === 'surveyCompleted') {

const { response, customParams } = e.data;

window.SparrowLauncher('remove')

}

});

For more visit: https://help.surveysparrow.com/surveysparrow-widgets-how-to-make-the-maximum-use-of-it