AFAIK, you can use cookie banners, but opting in has to be as easy as opting out. The .eu sites do that.
https://news.ycombinator.com/item?id=28134437
https://news.ycombinator.com/item?id=28134437