Is there any way to do custom action while leaving the SharePoint site

I have a scenario, I need to get feedback from the user who is leaving the SharePoint site.

Is there any way to achieve this kind of functionality? Please share any reference for this functionality.

Thanks in Advance!