Web push notifications – best practice to obtain user consent?

I'm thinking about the idea of creating web push notifications for a website, which should serve as a re-targeting method.

I'm not even sure what kind of developer I should take for this task, and whether it is possible to monitor the engagement of users with the messages, up to the individual user resolution, and save the data in my own DB.

But before I start, does anyone here has any experience with this method? what would be the best practice to obtain user's consent to the notifications? simply pop the alert as soon as the user lands on the website?