Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Problem with Adsense reload and DFP cmd push #9
Recently, we refactored the Adsense reload code because DFP ads did not load in the presence of an Adsense Ads. See 50ee40c
This worked because the original
However, it brought 2 issues that were discovered recently.
1) DFP Ad not showing on page change
This is the DFP ad not loading - you can see the adsense ad there though - next picture shows what the dfp ad (orange) and the adsense ad together
This is the DFP and Adsense Ad
2) Adsense Ad not showing
A 400 Error appears after 3-5 minutes of navigating to posts and back (without refreshing the page). We think this is a reloading error. It only happened after 50ee40c was put in. The error appears regardless of whether DFP ads are present or not.
Adsense ad not showing - 400 error
To replicate this in your local machine, download the latest version of this repo and checkout to the development branch (remember to pull the latest version of Discourse-main) and put the following settings in:
Your help would be greatly appreciated!
Thanks in advance!
key.indexOf('google') !== -1 means that any element in the window starting will google will be not false, and therefore true. key.indexOf('googletag') === -1 means that any element starting within googletag will be false. Therefore, the keys that will be undefined (see next line) and therefore reloaded in the following lines will be those that start with google but not googletag. This means that DFP can load and Adsense will reload.
There is a problem with this in that everything starting with google will reload and while it is a good patch for now, it may present issues if google changes its element names, another google ad platform is developed that uses etc.... (for noting)
The problem was that the post Google and pre Google vars were loading elements starting with google for both dfp and adsense at the same time as opposed to loading the adsense elements first and undefining them. This was also messing up the reload.
Solution was to default back to original working reload code and add
Thank you again to Myles for his help!!!!!