Block contextual ads based on browser activity from Google

I have entered AliExpress site to buy something. Now I always get ads in YouTube and other sites; some ads advertising some underwear and so on. This is annoying. How can I block them?


Assuming you don’t have spyware installed showing you those ads, use Chrome and the AD Block extension and they should disappear.

To prevent tracking (retargeting) as opposed to blocking the ads have a look at something like Ghostery. More do not track info can be found here.


For Google Ads specifically, you can configure what kinds of advertisements Google will show you at https://www.google.com/settings/ads.

In particular, near the bottom of the page, there's a section titled "Opt-out settings", with two links that you can click to opt out of contextual ("interest-based", in Google terminology) ads both on Google itself, and on other sites using Google ads. You'll still see ads, but they will not be targeted based on your demographics or browsing history. See this help page for more details.

(Apparently, what those opt-out links technically do is set a cookie in your browser, on the domain .doubleclick.net, with the content id=OPT_OUT, which Google uses as a signal not to show you targeted ads. There's also a browser plugin by Google that you can install to set that cookie permanently; you can browse the source code to see what it does internally.)

If you'd prefer somewhat more fine-grained control on which ads you'll see, you can also block unwanted ads from specific advertisers or for specific sites. That said, you may also want to check your interests and demographic info on the Google Ads Settings page I linked to above, since if Google thinks that you're, say, interested in lingerie, just blocking specific advertisements for them may not be particularly effective, as Google will just show you other ads for the same stuff.


There are also a few things you can do directly in your browser settings to avoid being subjected to contextual ads:

  • Clear any cookies. In particular, for Google ads, you'll want to remove any cookies from the domain doubleclick.net (except maybe the opt-out cookie mentioned above). If you've been browsing with default privacy settings, you'll probably find you have cookies from dozens and dozens of domains that you've never visited — those are third-party cookies, most of them set by advertisers, and you can pretty safely just clear them all out.

  • To keep those cookies from coming back, you may want to disable third-party cookies in your browser. There are a very few legitimate sites that may need such cookies to function properly (the Google Play Books online reader is one example), but most browsers will let you configure specific exemptions to allow cookies from those sites.

  • While you're at it, consider also setting your browser to clear out all cookies at the end of each session; you probably will want to configure exemptions to that, for sites that you want to stay logged in on, but it does wonders for keeping your browser from accumulating cookie cruft.

  • Configure your browser to send the Do Not Track header, which essentially acts as a global opt-out from targeted ads, telling any compliant sites not to store any tracking information about you that could be used to customize ads. Of course, there's no guarantee that any particular site or ad network will respect it, but it can't really hurt, either.

There are also several browser extensions that you can install to improve your browser's privacy and security. (But do be careful — just because an extension says it improves your privacy doesn't mean it actually will, and any extension you install has effectively full access to everything you do on the web. You do not want to install a malicious browser extension.)

One extension I'd personally recommend is NoScript for Firefox — it's not an ad-blocking extension per se, but it does tend to eliminate 99% of the annoying JavaScript-based ads (as well as, alas, some generally legitimate and harmless ads, unless you explicitly whitelist those), and it includes a number of other security features in addition to its main feature (the ability to selectively allow which sites may execute JavaScript), such as the Application Boundary Enforcer, which can be used to block third-party requests from/to specific sites.