GithubHelp home page GithubHelp logo

Comments (11)

pmaojo avatar pmaojo commented on August 17, 2024 1

With modifications.

class @Gpt
  constructor: ->
    @slots = {}
    window.googletag = googletag || {}
    window.googletag.cmd = googletag.cmd || []

    $(document).on 'turbolinks:before-visit', => @clearAds()
    $(document).on 'turbolinks:load', => @evaluate()

    @evaluate()

  evaluate: ->
    for slot in $('.gpt-ad')
      $slot = $(slot)
      cachedSlot = @slots[$slot.attr('id')]

      if cachedSlot? then @refreshSlot(cachedSlot) else @defineSlot($slot)

  defineSlot: ($slot) ->
    divId = $slot.attr('id')
    path = $slot.data('gpt-path')
    dimensions = $slot.data('gpt-dimensions')

    googletag.cmd.push =>
      slot = googletag.defineSlot(path, dimensions, divId).addService(googletag.pubads())
      googletag.enableServices()
      googletag.display(divId)
      @slots[divId] = slot

  refreshSlot: (slot) ->
    googletag.cmd.push ->
      googletag.pubads().refresh([slot])

  clearAds: ->
    googletag.cmd.push ->
      googletag.pubads().clear()
$ ->
  @gpt ||= new Gpt()

from turbolinks-compatibility.

richardvenneman avatar richardvenneman commented on August 17, 2024

Taking in account that Google has terminated the Adsense AJAX program, I searched for other solutions. It is still possible to dynamically load ads trough DoubleClick for Publishers, which supports Adsense. I successfully implement a solution for DFP which runs in production.

Related pull request: #37

from turbolinks-compatibility.

reed avatar reed commented on August 17, 2024

Yeah, I don't use AdSense in any of my projects, so my knowledge on the subject is limited. Thanks for doing the research and coming up with a solution that works. I'll add a note to the AdSense page telling people that Google cancelled the program and that they'll need to use DFP.

from turbolinks-compatibility.

pmaojo avatar pmaojo commented on August 17, 2024

Hello. I get
Exception in queued GPT command TypeError: Cannot read property 'addService' of null at Arguments.<anonymous>

The ad is loaded once but not changing on page load.

from turbolinks-compatibility.

robypez avatar robypez commented on August 17, 2024

Hello. I get
Exception in queued GPT command TypeError: Cannot read property 'addService' of null at Arguments.<anonymous>

The ad is loaded once but not changing on page load.

Have you solved?

from turbolinks-compatibility.

pmaojo avatar pmaojo commented on August 17, 2024

@robypez I ended up using Google DoubleClick for Publishers to solve this. I won't use Turbolinks again on any project.

starting point: http://reed.github.io/turbolinks-compatibility/doubleclick_for_publishers.html

I had to learn how to use the platform, so different than AdSense

from turbolinks-compatibility.

robypez avatar robypez commented on August 17, 2024

I'm using Google DoubleClick for Publishers, but I still have some issue with turbolinks 5 with this guide

http://reed.github.io/turbolinks-compatibility/doubleclick_for_publishers.html

It doesn't work anymore...

from turbolinks-compatibility.

pmaojo avatar pmaojo commented on August 17, 2024

Sometimes banners are not clickable but, you can see it working here:
https://motilladelpalancar.net
If I get the time to do it, I will document how I set it up

from turbolinks-compatibility.

robypez avatar robypez commented on August 17, 2024

Sometimes banners are not clickable but, you can see it working here:
https://motilladelpalancar.net
If I get the time to do it, I will document how I set it up

Are you using Turbolinks 5?
The issue is with turbolinks 5

from turbolinks-compatibility.

pmaojo avatar pmaojo commented on August 17, 2024

gem 'turbolinks', '~> 5'

from turbolinks-compatibility.

robypez avatar robypez commented on August 17, 2024

And without any modification to the code here?

http://reed.github.io/turbolinks-compatibility/doubleclick_for_publishers.html

Because

$(document).on 'page:fetch', => @clearAds()
$(document).on 'page:load', => @evaluate()

are not for Turbolinks 5

from turbolinks-compatibility.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.