Comments (11)
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.
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.
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.
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.
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.
@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.
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.
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.
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.
gem 'turbolinks', '~> 5'
from turbolinks-compatibility.
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)
- Turbolinks not working with google ads or LiveHelpNow
- Google Tag Manager HOT 5
- Facebook like/share button still disappearing HOT 1
- Marketo munchkin tracker integration request
- Integration with Google TagManager HOT 4
- Happyfox Chat loading problem after language change HOT 4
- Can't find a way to change Facebook language HOT 1
- Loading Javascripts Problem HOT 1
- React Native HOT 1
- Turbolinks 5 compatibility HOT 8
- Should the solutions propose both coffee script and standart js version?
- Segment.com HOT 1
- Olark Hummingbird theme
- New Sharethis implementation and Turbolinks' incompatibility HOT 3
- owlCarousel not Loaded
- Zendesk old and new tab displayed HOT 2
- Turbolink 5 and Google DFP not working
- LiveZilla Compatability
- Using the Freshdesk/Freshdesk Widget with Turbolinks HOT 4
- SaleForce Widget with turbolinks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from turbolinks-compatibility.