If you want to add AdSense to your confluence, that is super easy by adding AdSense scripts at Settings → General configuration → Custom HTML

To Enable AdSense in your confluence, all the action you need to do is copy & paste AdSense JS Code to "At end of the BODY" in Custom HTML at General Configuration.


If you want to enable AdSense only for anonymous user (a.k.a. remote user), you will need some trick as following. You will need to modify your advertiser code below:

<!-- Google Ad Sense -->
<script>
function run_adsense()
{
 	(adsbygoogle = window.adsbygoogle || []).push({
 		google_ad_client: "ca-pub-9892107127037407",
 		enable_page_level_ads: true
	});

	const script = document.createElement("script");
	script.type="text/javascript";
	script.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-0012785825429529";
	script.async = true;
	script.crossorigin="anonymous";
	document.body.appendChild(script);
	eval(script);
}
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
AJS.toInit(function(){
	if (AJS.params.remoteUser == ''){
		run_adsense();
	}
});
</script>

For your information, the original AdSense JS Code was like below:

<!-- Google Ad Sense -->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-9892107127037407",
    enable_page_level_ads: true
  });
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-0012785825429529" crossorigin="anonymous"></script>