Adsense ads not reloading on topic navigations or on ToC pages, frame-src refused CSP errors and uncaught exception errors EmberJS

I am having a bunch of problems with running ads on Discourse site on https://howtodiscuss.com.

  1. Many uncaught DOM Exception errors, just goto any topic pages in incognio mode u will see them https://howtodiscuss.com/t/profit/7022

  1. And other error is when i navigate to a new topic from an old topic page, i get this warning in console, a google Vignette ad is shown but due to this warning the ad disappears and page navigates, hence user is never able to click Google Vignette Interstitial ads that appear between page loads/navigations.

    Deprecation notice: Removing all event listeners at once is deprecated, please remove each listener individually. https://howtodiscuss.com/t/how-many-ounces-is-a-1-4-cup/18390

  1. I am also trying to show a fixed sticky google ad on right side bar of single topic page, using this code,

Javascript code to inset sticky fixed ad on topic side bar, need to make it work with ToC too

<!-- plugin code to show fixed ad-->

<script type = "text/discourse-plugin"
version = "0.8" >
	var friends_retries = 0;
var friends_timeout;

api.decorateWidget('topic-timeline-container:before', helper => {
	return helper.h('div.side-block', [
		helper.rawHtml('<div id="friends"></div>'),
	]);
});

api.onPageChange(() => {


	if (window.location.href.indexOf("/t/") > -1) {
		console.log('page changed - topic');
		friends_retries = 0;
		window.setTimeout(loadFriends, 100);

	} else {
		//console.log( 'page changed - not topic');
	}
});

function loadFriends() {

	if (!document.getElementById('friends')) {
		//var timer;
		friends_retries++;
		if (friends_retries < 10) {
			//console.log('timeout rescheduled, try ' + friends_retries);
			window.setTimeout(loadFriends, 100);
		} else {
			clearTimeout(friends_timeout);
			// window.clearTimeout(loadFriends);

			console.log('timeout cleared, gave up');
			// loadFriends();
		}
	} else {


		var bHTML = ' <!-- Topic side bar timeline HTD --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-7087907313091932" data-ad-slot="5067761793" data-ad-format="auto" data-full-width-responsive="true"></ins>';

		// var bHTML = '<img src="https://via.placeholder.com/300x250?text=300x250+MPU" alt="Girl in a jacket">';

		$("#friends").html(bHTML);


	}
}


</script>
<!-- plugin code to show fixed ad-->

Here is its CSS code:

/*for fixed ad*/
/* timeline layout fix 2.6.0.beta5 */
@media screen and (min-width: 925px) {
    .container.posts .topic-navigation {
        margin-left: 7em;
    }
}

#friends {
    display:block;
    //width:300px; 

    height:150px;
    margin-left:-90px;
    margin-top:-25px;
    margin-bottom:90px;
}
/*for fixed ad*/

Sometimes this code works, but it does not work on the page where ToC appears, e.g not working on https://howtodiscuss.com/t/how-many-grams-in-a-quarter-ounce/12300

Can someone correct my mistake in my code so that it can show on ToC pages too?

  1. I have also noticed another bug in my code and overall discourse ad plugin code, when i m navigating from one page to another, my adsense ad code is never refreshed and never reloaded, so it doesn’t trigger any ad impression. May be because Discourse does not fully reload enitre page when we navigate. I want ads to be refreshed and full page to be reloaded from any link navigation, how can i fix this?

  2. I am also getting many of these frame-src errors on my site, https://howtodiscuss.com/t/how-mouthwash-rinse-become-a-necessary-step-in-oral-hygiene/30631

Refused to frame 'https://pagead2.googlesyndication.com/' because it violates the following Content Security Policy directive: "frame-src cm.g.doubleclick.net googleads.g.doubleclick.net www.google.com accounts.google.com pagead2.googlesyndication.com/pagead/s/cookie_push.html gmsg: https://tpc.googlesyndication.com/sadbundle/$csp=er3$/1522577804659956528/index.html".

This is how my CSP settings look like,

But i dont know how to whitelist Google ads iframe requests? I also tried this code, but its not working well, i m still seeing the above frame-src errors,
if i add values next to frame-src in meta, it gives me error that we cannot use frame-src in meta tag.

<!--<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; frame-src  ; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />-->

It will be huge help if anyone can help me solve my problems,

I am even getting such errors on my homepage, https://howtodiscuss.com/ (to replicate errors, open the page in incognito, or use vpn or just refresh few times or navigate to other pages, you will find the errors in JS console, and will also see the Google vignette dismissing without giving chance to user to click the ad)

Hope someone can help.

My site is on cloudflare, i m on latest discourse version 2.6.0.beta6, i have updated everything all plugins and also have rebuilt docker just now. still i see these errors.

It is possible that this is the cause of the issues you are running into. Have a look at some Cloudflare related support topics to see if any of them give hints about Cloudflare configuration issues that could be causing the problems: Search results for 'cloudflare #support' - Discourse Meta.

It is my understanding that you need to make sure that Cloudflare’s speed/performance optimizations for JavaScript, CSS and HTML are disabled for it to work properly with Discourse.

3 Likes

Thanks @simon for your prompt response.

As per your advice, i turned off Clodflare, brotoli, and turned off all its minifications on css,js,html, i also turned off rocket loader,

I have also cleared my CF caching, and waited for 30 min to test results, but i am still getting weird JS console errors when on my homepage https://howtodiscuss.com and

when i am navigating to my topics pages, Catholic rosary - How To Discuss

You can replicate these errors by opening my site in chrome incognito browser and try navigating to few pages/topics on my site.

Also, do you know why my sticky fixed adsense ad on right side of topic timeline/topic navigation only shows when i fully reload the my page using browser refresh icon, or when i first land on my website, but on any subsequent page loads, the function doesn’t trigger my ad, it doesn’t detect that my topic page has changed

it comes in this else block everytime, is there any bug in my custom discourse plugin logic to detect when a user navigated to a topic page, i want to show and reload a new adsense ad each time, but its going to else block, the code things the ID #friends already exists, but its never reloaded unless i do a FULL HARD REFRESH. timeout cleared, gave up.

Please help me, you can browser my website topics yourself, you will find all issues in console JS, i am also getting this warning in JS console and google vignette ad never stays for user to click it.

Deprecation notice: Removing all event listeners at once is deprecated, please remove each listener individually.

I have turned off my CF speed optimizations as per your suggestions, css/js/html minifications, rocket loader, brotoli. What else could be the issue now? Could a discourse plugin could be an issue? These are my plugins right now,

My SSL is strict, could that be issue?

I have just done a fresh rebuilt as well now, just in case if changes take place after rebuild… but errors are still the same, just tested again :frowning:

2 Likes