Below code snippet is Drift chat method to get the email id provided by user in chat.
I am trying to access email id (e.data.email) outside of given function scope by storing it in a global variable data_email.
I have tried three method to make data_email global variable - window, let, const.
window.drift.on("emailCapture", function(e) {
console.log("user identified as: " + e.data.email);
window.data_email = e.data.email;
// let data_email = e.data.email;
// const data_email = e.data.email;
ga('send', 'event', {
eventCategory: 'driftemail',
eventAction: 'driftemailCaptured',
});
});
console.log(data_email);
After trying all that I am getting error - Uncaught ReferenceError: data_email is not defined.
Please anyone suggest me a work around, i will be very thankful. My goal is to access captured email outside of the given function.