#adsense #dfp #turbolinks

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.

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.

Qihuan Piao

Qihuan Piao

Originally from China and now living in Tokyo, I started this blog to practice English. Over the years, writing helped me find my own voice and explore thoughts about identity, life, and ordinary things that catch my curiosity. I mostly write for myself, but I love it when something here connects with someone else.

Meanwhile, what I wrote in Japanese

人を幸せにするのは非常に難しい

April 15, 2016

Meanwhile, what I wrote in Chinese

电影:丹麦女孩(The Danish Girl)

May 6, 2016