To protect the ads, think about creating a protective layer, that is, a transparent div after there are two or three clicks by the same user and, thus, avoid more clicks by the same visitor.
$(document).ready(function() { $(".ads iframe").load(function() { $(".layer-protect").hide(); }); }); .ads { position: relative; } .layer-protect { position: absolute; } iframe { position: absolute; } <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="ads"> <iframe src="https://es.stackoverflow.com/"></iframe> </div> <div class="layer-protect"> <p>Hi! Testing...</p> </div> But of course this was not enough, so apart from creating a layer I would have to delete all the links that the iframe contains
let i = 0; $("iframe *").each(function() { this.pos = i; $(this).on("click", (e) => { if (localStorage.getItem("link"+i) == null) { localStorage.setItem("link"+i, 1); } else { let clicks = localStorage.getItem("link"+i); if (clicks >= 3) { if (typeof e.target.getAttribute("href") == "string" && e.target.getAttribute("href").toLowerCase().search(location.hostname.toString().toLowerCase()) == -1) { e.preventDefault(); } } else { localStorage.removeItem("link"+i); clicks++; localStorage.setItem("link"+i, clicks); } } }); i++; }); But the problem is that this code developed in jquery will disable me forever the clicks in the ad for that user since the click count is saved in localStorage and to restore or delete the localStorage session it is necessary to do it manually since this is not it will erase by itself.
So, how to replace the localStorage with a cookie that is active for 24 or 48 hours, so that user can click on the ads again.