Skip to content

Instantly share code, notes, and snippets.

@fernandohenriques
Created January 31, 2018 05:49
Show Gist options
  • Save fernandohenriques/d5d2a59ebe741f434cadde1c33ce96d4 to your computer and use it in GitHub Desktop.
Save fernandohenriques/d5d2a59ebe741f434cadde1c33ce96d4 to your computer and use it in GitHub Desktop.
Intelligence when show ads - Five times one, one time other
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Intelligence when show ads - Five times one, one time other</title>
<style type="text/css">
#googleadsheader.ads1{ width:728px; height:90px }
#googleadsheader.ads2{ width:970px; height:250px }
</style>
<script type="text/javascript">
/* Replace 'data-ad-client' and 'data-ad-slo' with your ads data. */
var ad1 = '<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-12345698989" data-ad-slot="10101010101"></ins>';
var ad2 = '<ins class="adsbygoogle" style="display:inline-block;width:970px;height:250px" data-ad-client="ca-pub-1234566999" data-ad-slot="10101010101"></ins>';
function writeAds(ads,fatherid,fatherclass) {
var fatherdiv = document.getElementById(fatherid);
fatherdiv.setAttribute("class",fatherclass);
document.write(ads);
}
function showads() {
if (typeof(Storage) !== "undefined") {
if (localStorage.totalads1) {
var totalads1 = parseInt(localStorage.getItem("totalads1"));
if(totalads1 > 5) {
writeAds(ad2,'googleadsheader','ads2');
localStorage.removeItem("totalads1");
} else {
writeAds(ad1,'googleadsheader','ads1');
totalads1++;
localStorage.setItem("totalads1",totalads1);
}
} else {
writeAds(ad1,'googleadsheader','ads1');
localStorage.setItem("totalads1","1");
}
} else writeAds(ad1,'googleadsheader','ads1');
}
</script>
</head>
<body>
<!-- Position this block where the ad should appear. -->
<div id="googleadsheader" style="margin:0 auto">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script type="text/javascript">showads();</script>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
</div>
</body>
</html>
<!-- Separate HTML, JS and CSS when using. This is just an example. ;) -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment