Today, the Federal Commissioner for Data Protection again points out that websites can be accessed by Tracking of your users must obtain consent before tracking begins.
Instead, so-called pre-load consents (consents prior to loading and performing tracking) must be obtained, and based on this consent, tracking may or may not occur (depending on what the user has chosen).
Common purchase solutions for e.g. WordPress are the use of plugins such as the here.
As a web developer you can of course build your own overlay which then dynamically loads the plugins via Java Script and executes the tracking commands after the user has agreed to this tracking, that's not witchcraft and only a small effort to move the current tracking code under an onClick event and to design an overlay and load it.