This snippet allows you to ask permission and if required prevent loading external scripts that will write cookies on the visitors computer.
Use this module if you want to include non-javascript code only on permission too, e.g. if your opt-in code also contains HTML or noscript parts.
See the module's homepage how to install and customize the module.