Skip to content

Instantly share code, notes, and snippets.

@Dellos7
Last active December 5, 2023 22:51
Show Gist options
  • Save Dellos7/63f8b4f2f54ba44d19904b2b42ab0d2c to your computer and use it in GitHub Desktop.
Save Dellos7/63f8b4f2f54ba44d19904b2b42ab0d2c to your computer and use it in GitHub Desktop.
How to block Spotify and most apps ads (valid also for Android & iOS)

Block Spotify ads (and most app ads)

This is a how-to guide in order to block Spotify ads. However, this will also block most apps ads as apps usually use very similar ad providers.

Disclaimer

This guide was done with the only aim of learning.

Blocks ads in desktop and mobile

This is valid for:

  • Desktop apps
  • Android apps
  • iOS apps

How does it work?

The main idea is to modify the hosts file in a server in order redirect to our localhost (127.0.0.1) the HTTP calls to the ads urls. This way, ads can't load and apps just don't show them.

Just modify your hosts file in order to contain these lines, and the ads should be already be blocked in the server.

So if you've got a Windows PC and want to use your PC as a server that blocks these ads, once you modify the hosts file you should have already blocked the ads in your Windows Spotify application.

Where is my hosts file?

Depending on the server that you are running, the hosts file may be in one of the below paths:

  • Linux: /etc/hosts
  • Windows: C:\Windows\System32\drivers\etc\hosts
  • OSX: /etc/hosts or /private/etc/hosts

If you want to block the ads in your Mobile Apps, install a proxy server

Install a proxy server

The idea here is to install a proxy server in the server where you've modified the hosts file and connect your device to the proxy server. This way, your device will redirect all the traffic through the server, and the server will block the ads via the hosts file.

So install a proxy server in your server. I like Squid:

Connect your device to your proxy server

TODO

Hosts file configuration

Modify your hosts file in order to include the following:

127.0.0.1 adclick.g.doublecklick.net
127.0.0.1 adeventtracker.spotify.com
127.0.0.1 ads-fa.spotify.com
127.0.0.1 analytics.spotify.com
127.0.0.1 audio2.spotify.com
127.0.0.1 b.scorecardresearch.com
127.0.0.1 bounceexchange.com
127.0.0.1 bs.serving-sys.com
127.0.0.1 content.bitsontherun.com
127.0.0.1 core.insightexpressai.com
127.0.0.1 crashdump.spotify.com
127.0.0.1 d2gi7ultltnc2u.cloudfront.net
127.0.0.1 d3rt1990lpmkn.cloudfront.net
127.0.0.1 desktop.spotify.com
127.0.0.1 doubleclick.net
127.0.0.1 ds.serving-sys.com
127.0.0.1 googleadservices.com
127.0.0.1 googleads.g.doubleclick.net
127.0.0.1 gtssl2-ocsp.geotrust.com
127.0.0.1 js.moatads.com
127.0.0.1 log.spotify.com
127.0.0.1 media-match.com
127.0.0.1 omaze.com
127.0.0.1 open.spotify.com
127.0.0.1 pagead46.l.doubleclick.net
127.0.0.1 pagead2.googlesyndication.com
127.0.0.1 partner.googleadservices.com
127.0.0.1 pubads.g.doubleclick.net
127.0.0.1 redirector.gvt1.com
127.0.0.1 s0.2mdn.net
127.0.0.1 securepubads.g.doubleclick.net
127.0.0.1 spclient.wg.spotify.com
127.0.0.1 tpc.googlesyndication.com
127.0.0.1 v.jwpcdn.com
127.0.0.1 video-ad-stats.googlesyndication.com
127.0.0.1 weblb-wg.gslb.spotify.com
127.0.0.1 www.googleadservices.com
127.0.0.1 www.googletagservices.com

...

@HeIp
Copy link

HeIp commented Dec 5, 2023

Is this still valid on iOS 17, Spotify 2023 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment