Removing AdSense Ads for Your Paying Members on Ghost

How do I remove my Google AdSense ads for my paid Ghost memberships? Turns out, Ghost has made it easy to do.

Removing AdSense Ads for Your Paying Members on Ghost

With Ghost 4.0 memberships and paid memberships became part of the core platform. You might run ads on your Ghost website, like I do, however you might not want to show ads to your paying members.

Whether a user is a member of not is handled by the @member object - which looks like this:

{{#if @member.paid}}
  <p>Thanks for becoming a paying member 🎉</p>
{{else if @member}}
  <p>Thanks for being a member 🙌</p>
{{else}}
  <p>You should totally sign up... 🖋</p>
{{/if}}

With that in mind, when you set up AdSense, you get given a script that looks kinda like this:

<!-- Google AdSense -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-0000000000000000" crossorigin="anonymous"></script>

And you've probably either put that in your handlebars template or in the Code Injection area of your Ghost website in order to wire up your ads.

So putting two and two together, in order to prevent your paid members from getting ads, you just need to put that AdSense wiring up script inside the check if the member has (or hasn't) paid.

In your root template, (for instance mine is default.hbs) just above the {{ghost_head}} helper put the following:

{{^if @member.paid}}
	<!-- Google AdSense -->
	<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-0000000000000000" crossorigin="anonymous"></script>
{{/if}}

The ^ before the if is a negation.

Remember to remove the AdSense script from the Ghost Code Injection area if you are doing this. You don't want to load this for paying members.

The above will only properly work if you have Auto Ads. If you've manually placed Ad Units, then you will also need to apply the same {{if}} blocks around those units too. For instance, for one of my ad units:

{{^if @member.paid}}
	<div class="adsense">
		<!-- Post Ad - Top -->     
		<ins class="adsbygoogle"
			style="display:block"
			data-ad-client="ca-pub-0000000000000000"
			data-ad-slot="4764185050"
			data-ad-format="horizontal"
			data-full-width-responsive="true">
		</ins>
		<script>
			(adsbygoogle = window.adsbygoogle || []).push({});
		</script>
		<!-- End Post Ad - Top -->
	</div>            
{{/if}}

And that's that!