How we do adsense with google dfp



Over on I have had some problems getting the adsense plugin to work. It simply didn’t work for us for some reason.
Instead I injected an ad in the DiscoveryView which is working quite well for us.

Adsense doesn’t support refreshing ads with ajax but adsense together with google dfp does!

I found this neat little jQuery plugin that makes it a lot easier to use dfp.

Include the script in </body> in the dashboard and then add this after:

Discourse.DiscoveryView = Ember.View.extend({
  _insertAd: function() {
    this.$(".list-container").prepend( "<div class='toplist_ad' data-adunit='ad_ID' data-size-mapping='toplist'></div>" );
      sizeMapping: {
        'toplist': [
          {browser: [1100, 0], ad_sizes: [970, 90]},
          {browser: [810, 0], ad_sizes: [728, 90]},
          {browser: [530, 0], ad_sizes: [468, 60]},
          {browser: [0, 0], ad_sizes: [320, 50]}

This will add a div and then add the ad into the div. It will show an ad on the list and category pages but not when on a topic. So the ad don’t fresh when you go from latest to top, but it does when you go from a topic back to a list. sizeMapping is for showing different ads on different window sizes.

I have made a few apps in Ember.js but Discourse is still way out of my league :slight_smile: . If anyone have a better/cleaner way to do this then feel free to add it here.


@riking Just saw your edit.

Can you explain why that is better? Am I interfering with discourse using didInsertElement?
And why use an underscore in _insertAd ?

(Mittineague) #3

This is commonly used to signify “private”