The website is set up to opt in for cookie consent but when a first time visitor clicks the accept cookies button the adsense code does not load unless the whole page is refreshed.
Is there a way to achieve loading ads once the cookie acceptance button is clicked instead of having to refresh the whole page?
Using this cookie consent jquery plug: IHaveCookies
This is part of the code I am using that allows adsense to load:
$(document).ready(function() {
$('body').ihavecookies(options);
if ($.fn.ihavecookies.preference('ads') === true) {
var src = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
var newScript = document.createElement("script");
newScript.type = "text/javascript";
newScript.setAttribute("async", "true");
newScript.setAttribute("src", src);
document.body.appendChild(newScript);
}
The above code does work but it does not allow ads to appear until after page refresh. Is it possible to add a "refresh" attribute to the above code to make the ads load on "ihavecookies.preference('ads') === true)" without page refresh?
The website where I've implemented this can be viewed Here
fyi.... currently no ads are loading for EU or Californian visitors (but this is a separate issue not to be addressed with this topic)