Skip to content

Commit

Permalink
AdButler support (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
communiteq authored and nlalonde committed Sep 16, 2019
1 parent b500ea1 commit 19f0457
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This is the official Discourse advertising plugin. It allows advertisements to
* [Amazon Affiliates](http://affiliate-program.amazon.com) - Banner and Product Link Ads
* [CodeFund](https://codefund.io) - Ethical Ad Platform for Developers
* [Carbon Ads](https://www.carbonads.net/)
* [AdButler](https://www.adbutler.com/)


## Quick Start in 3 Steps
Expand Down Expand Up @@ -81,6 +82,7 @@ the ad slots. The ads will start showing as soon as you add them to slots.
<li>DFP - if using the DoubleClick for Publishers advertisement platform.</li>
<li>CodeFund - if using the CodeFund ethical advertisement platform.</li>
<li>Carbon Ads - if using the Carbon Ads advertisement platform.</li>
<li>AdButler - if using the AdButler advertisement platform.</li>
</ul>
</ul>

Expand Down Expand Up @@ -113,6 +115,13 @@ Only for Product Link and Banner Ads.

![Carbon Ads](https://d11a6trkgmumsb.cloudfront.net/original/3X/3/a/3acc7488db2b53733cdd427d3cb1b76361c786e1.png)

##### AdButler Ads Zone URL to Discourse's Site Settings

If you browse to a zone in the AdButler admin, then you can find the Publisher ID (PPPPPP) and the Zone ID (ZZZZZZ) in the URL:

`https://admin.adbutler.com/?ID=PPPPPP&p=textadzone.view&zoneID=ZZZZZZ`


### Step 3 - See Your Ad

Once you've configured your settings and your advertising platform has ads that are ready to serve, navigate to the page where you've inputted for the location and you should see ads.
Expand Down
17 changes: 17 additions & 0 deletions assets/javascripts/discourse/components/ad-slot.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ const adConfig = Ember.Object.create({
"topic-above-post-stream": "carbonads_above_post_stream_enabled",
"topic-above-suggested": false
}
},
"adbutler-ad": {
settingPrefix: "adbutler",
enabledSetting: "adbutler_publisher_id",
desktop: {
"topic-list-top": "adbutler_topic_list_top_zone_id",
"post-bottom": "adbutler_post_bottom_zone_id",
"topic-above-post-stream": "adbutler_topic_above_post_stream_zone_id",
"topic-above-suggested": "adbutler_topic_above_suggested_zone_id"
},
mobile: {
"topic-list-top": "adbutler_mobile_topic_list_top_zone_id",
"post-bottom": "adbutler_mobile_post_bottom_zone_id",
"topic-above-post-stream":
"adbutler_mobile_topic_above_post_stream_zone_id",
"topic-above-suggested": "adbutler_mobile_topic_above_suggested_zone_id"
}
}
});

Expand Down
131 changes: 131 additions & 0 deletions assets/javascripts/discourse/components/adbutler-ad.js.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
import { default as computed, observes } from "ember-addons/ember-computed-decorators";
import loadScript from "discourse/lib/load-script";

const publisherId = Discourse.SiteSettings.adbutler_publisher_id;
const adserverHostname = Discourse.SiteSettings.adbutler_adserver_hostname;

let _loaded = false,
_promise = null,
_c = 0;

function loadAdbutler() {
if (_loaded) {
return Ember.RSVP.resolve();
}

if (_promise) {
return _promise;
}

_promise = loadScript('https://' + adserverHostname + '/app.js', { scriptTag: true }).then(function() {
_loaded = true;
});

return _promise;
}

export default AdComponent.extend({

divs: null,

init() {
let dimensions = [728,90];
let configKey = 'adbutler_';
let className = 'adbutler-';
let dimClassName = 'adbutler-ad';

this.set('divs', []);

if (this.site.mobileView) {
dimensions = [320,50];
configKey += 'mobile_';
className += 'mobile-';
dimClassName = 'adbutler-mobile-ad';
}

configKey += this.get("placement").replace(/-/g, '_') + '_zone_id';
this.set("configKey", configKey);

className += this.get("placement");
this.set("className", className + ' ' + dimClassName);

let zoneId = this.siteSettings[configKey];
this.set("zoneId", zoneId);

let divId = 'placement-' + zoneId + '-' + _c;
this.set("divId", divId);
_c++;
this.divs.push({
divId: divId,
publisherId: publisherId,
zoneId: zoneId,
dimensions: dimensions
});

this.set("publisherId", publisherId);
this._super();
},

_triggerAds() {
loadAdbutler().then(function() {
if(this.divs.length > 0) {
let abkw = window.abkw || '';
AdButler.ads.push({
handler: function(opt){
AdButler.register(opt.place.publisherId, opt.place.zoneId, opt.place.dimensions, opt.place.divId, opt);
},
opt: { place: this.divs.pop(), keywords: abkw, domain: adserverHostname, click:'CLICK_MACRO_PLACEHOLDER' }
});
}
}.bind(this));
},

didInsertElement() {
this._super();
Ember.run.scheduleOnce("afterRender", this, this._triggerAds);
},

@observes("listLoading")
waitForLoad() {
if (this.get("adRequested")) {
return;
} // already requested that this ad unit be populated
if (!this.get("listLoading")) {
Ember.run.scheduleOnce("afterRender", this, this._triggerAds);
}
},

@computed("currentUser.trust_level")
showToTrustLevel(trustLevel) {
return !(
trustLevel &&
trustLevel > Discourse.SiteSettings.adbutler_through_trust_level
);
},

@computed(
"showToTrustLevel",
"showToGroups",
"showAfterPost",
"showOnCurrentPage",
)
showAd(showToTrustLevel, showToGroups, showAfterPost, showOnCurrentPage) {
return (
publisherId &&
showToTrustLevel &&
showToGroups &&
showAfterPost &&
showOnCurrentPage
);
},

@computed("postNumber")
showAfterPost(postNumber) {
if (!postNumber) {
return true;
}
return this.isNthPost(parseInt(this.siteSettings.adbutler_nth_post));
}

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#if showAd}}
<div id={{divId}} class={{className}}></div>
{{/if}}
24 changes: 24 additions & 0 deletions assets/stylesheets/adplugin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,30 @@
color: $quaternary !important;
}

.adbutler-ad {
width: 728px;
height: 90px;
}

.adbutler-mobile-ad {
width: 320px;
height: 50px;
}

.adbutler-topic-list-top, .adbutler-topic-above-suggested {
margin: 10px;
text-align: center;
}

.adbutler-topic-above-post-stream {
margin: 10px 0px 10px 0px;
}

.adbutler-post-bottom {
margin: 10px 0px 10px 56px;
}


.adplugin-mgmt {
.house-ads-actions {
.btn {
Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ en:
amazon_plugin: 'Amazon'
codefund_plugin: 'CodeFund'
carbonads_plugin: 'Carbon Ads'
adbutler_plugin: 'AdButler'
adplugin:
house_ads:
title: "House Ads"
Expand Down
13 changes: 13 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,16 @@ en:
carbonads_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads."
carbonads_topic_list_top_enabled: "Show an ad above the topic list"
carbonads_above_post_stream_enabled: "Show an ad above the post stream"

adbutler_publisher_id: "AdButler Publisher ID"
adbutler_mobile_topic_list_top_zone_id: "Zone ID for mobile topic list top location"
adbutler_mobile_topic_above_post_stream_zone_id: "Zone ID for mobile topic above post stream location"
adbutler_mobile_post_bottom_zone_id: "Zone ID for mobile post bottom location"
adbutler_mobile_topic_above_suggested_zone_id: "Zone ID for mobile topic above suggested location"
adbutler_topic_list_top_zone_id: "Zone ID for topic list top location"
adbutler_topic_above_post_stream_zone_id: "Zone ID for topic above post stream location"
adbutler_post_bottom_zone_id: "Zone ID for post bottom location"
adbutler_topic_above_suggested_zone_id: "Zone ID for topic above suggested location"
adbutler_nth_post: "Show an ad after every N posts, where N is this value"
adbutler_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads"
adbutler_adserver_hostname: "The hostname that AdButler is serving your ads from"
40 changes: 40 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,43 @@ carbonads_plugin:
carbonads_above_post_stream_enabled:
client: true
default: false

adbutler_plugin:
adbutler_publisher_id:
client: true
default: ""
adbutler_through_trust_level:
client: true
default: 2
enum: "TrustLevelSetting"
adbutler_topic_list_top_zone_id:
client: true
default: ""
adbutler_mobile_topic_list_top_zone_id:
client: true
default: ""
adbutler_topic_above_post_stream_zone_id:
client: true
default: ""
adbutler_mobile_topic_above_post_stream_zone_id:
client: true
default: ""
adbutler_topic_above_suggested_zone_id:
client: true
default: ""
adbutler_mobile_topic_above_suggested_zone_id:
client: true
default: ""
adbutler_post_bottom_zone_id:
client: true
default: ""
adbutler_mobile_post_bottom_zone_id:
client: true
default: ""
adbutler_nth_post:
client: true
default: 4
min: 1
adbutler_adserver_hostname:
client: true
default: "servedbyadbutler.com"

0 comments on commit 19f0457

Please sign in to comment.