Exit Function on Popups not working on native webiste

Hello, I would like to a/b test having a popup on my website page vs not having one. I want this popup to appear on exit intent only.

However, I am using Google Optimize to run this a/b test, so I am adding the script that Unbounce generates to one of the test variants in Optimize. The popup works in the sense that it appears on the right variant and on the right pages but it does not appear when I try to exit the page (rather it appears a few seconds of just being on the page).

Is there a way to make this functionality work in my case? Maybe using cookies? Thank you!