April 27, 2016 #turbolinks #adsense #dfp

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.

Continue reading...

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.

  1. Change the markup where you want to display the ads from data-gpt-div-id="div-gpt-ad-123456789-0" to id="div-gpt-ad-123456789-0"
  2. Change the javascript code 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.