Make Turbolinks work with DoubleClick for Publishers(alternative of Google Adsense)
Turbolinks Compatibility with DoubleClick for Publishers has already provided great solution to let Turbolinks compatible with DoubleClick for Publishers(DFP), but unfortunately just copy and paste the code didn't work for me, I need to make some modifications to the original code.
According to the same site, you can no longer use Google Adsense with Turbolinks so you have to use the DFP.
Google has cancelled AJAX support for AdSense, so this solution no longer works. Your best course of action is to use DoubleClick for Publishers.
I'll provide the whole snippets all involved later, here are the changes you need to make in addition to the code snippet.
- Change the markup where you want to display the ads from
divId = $slot.data('gpt-div-id')to
divId = $slot.attr('id')
Make sure you disabled your browser AdBlock extension, or whitelist your domain(both local and production) to be able to see the ads. Open browser in incognito mode also works.
Here is all the code for it.