Hello,
I have installed Mixpanel in Figma to track events, and I would like to track an event when the user exits the plugin. I have written the following code:
figma.on('close', () => {
figma.ui.postMessage({
type: 'bg:exit',
});
});
In the UI, I retrieve the message to send the event to Mixpanel :
React.useEffect(() => {
// This is how we read messages sent from the plugin controller
window.onmessage = async (event) => {
const {type, message} = event.data.pluginMessage;
switch (type) {
case 'bg:exit':
mixpanel.track('leave-app'); //
break;
...
However, I believe that once we exit, the UI closes, and the event is never sent. I tried adding a sleep function in the close event, but that didn’t work either. Does anyone have any ideas?
(Note: “Sleep” in this context likely refers to a delay or pause in the code execution.)