Added custom targeting to all slots and Sebastian fixed the variable issue in adsense - thanks Seb!

This commit is contained in:
vi 2015-08-28 12:21:40 +10:00
parent 514fed55c9
commit f94bf79192
6 changed files with 62 additions and 26 deletions

View File

@ -1,5 +1,7 @@
import PageTracker from 'discourse/lib/page-tracker';
console.log(Discourse.SiteSettings.adsense_nth_post_code);
var ad_width = '';
var ad_height = '';
var ad_code = '';
@ -7,6 +9,7 @@ var publisher_id = Discourse.SiteSettings.adsense_publisher_code;
var preGoogleVars = null;
var postGoogleVars = null;
function splitWidthInt(value) {
var str = value.substring(0, 3);
return str.trim();
@ -20,6 +23,7 @@ function splitHeightInt(value) {
PageTracker.current().on('change', function(url) {
var ads = document.getElementById("adsense_loader");
if (ads) {
// clear the old element and its state
@ -57,27 +61,34 @@ PageTracker.current().on('change', function(url) {
});
var data = {
"topic-list-top" : {},
"topic-above-post-stream" : {},
"topic-above-suggested" : {},
"post-bottom" : {}
}
if (Discourse.SiteSettings.adsense_publisher_code) {
if (Discourse.SiteSettings.adsense_topic_list_top_code && !Discourse.SiteSettings.adsense_show_topic_list_top) {
ad_code = Discourse.SiteSettings.adsense_topic_list_top_code;
ad_width = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes));
ad_height = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes));
data["topic-list-top"]["ad_code"] = Discourse.SiteSettings.adsense_topic_list_top_code;
data["topic-list-top"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes));
data["topic-list-top"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes));
}
if (Discourse.SiteSettings.adsense_topic_above_post_stream_code && !Discourse.SiteSettings.adsense_show_topic_above_post_stream) {
ad_code = Discourse.SiteSettings.adsense_topic_above_post_stream_code;
ad_width = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes));
ad_height = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes));
data["topic-above-post-stream"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_post_stream_code;
data["topic-above-post-stream"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes));
data["topic-above-post-stream"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_post_stream_ad_sizes));
}
if (Discourse.SiteSettings.adsense_topic_above_suggested_code && !Discourse.SiteSettings.adsense_show_topic_above_suggested) {
ad_code = Discourse.SiteSettings.adsense_topic_above_suggested_code;
ad_width = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
ad_height = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
data["topic-above-suggested"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_suggested_code;
data["topic-above-suggested"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
data["topic-above-suggested"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
}
if (Discourse.SiteSettings.adsense_post_bottom_code && !Discourse.SiteSettings.adsense_show_post_bottom) {
ad_code = Discourse.SiteSettings.adsense_post_bottom_code;
ad_width = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
ad_height = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
data["post-bottom"]["ad_code"] = Discourse.SiteSettings.adsense_post_bottom_code;
data["post-bottom"]["ad_width"] = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
data["post-bottom"]["ad_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
}
}
@ -90,6 +101,13 @@ export default Ember.Component.extend({
ad_width: ad_width,
ad_height: ad_height,
init: function() {
this.set('ad_width', data[this.placement]["ad_width"] );
this.set('ad_height', data[this.placement]["ad_height"] );
this.set('ad_code', data[this.placement]["ad_code"] );
this._super();
},
adWrapperStyle: function() {
return `width: ${this.get('ad_width')}px; height: ${this.get('ad_height')}px; margin:0 auto;`.htmlSafe();
}.property('ad_width', 'ad_height'),

View File

@ -55,8 +55,6 @@ function loadGoogle(settings) {
.setTargeting(settings.dfp_target_topic_list_top_key_code, valueParse(settings.dfp_target_topic_list_top_value_code))
// This hardcoded code works: .setTargeting('category', ["clothes", "handbags", "makeup"])
.addService(googletag.pubads());
console.log(valueParse(settings.dfp_target_topic_list_top_value_code));
}
}
if (settings.dfp_topic_above_post_stream_code && !settings.dfp_show_topic_above_post_stream && settings.topic_above_post_stream_ad_sizes) {
@ -66,7 +64,10 @@ function loadGoogle(settings) {
googletag.defineSlot(settings.dfp_topic_above_post_stream_code, [320,50], 'div-gpt-ad-topic-above-post-stream').addService(googletag.pubads());
}
else {
googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_post_stream_code, [parseInt(splitWidthInt(settings.topic_above_post_stream_ad_sizes)), parseInt(splitHeightInt(settings.topic_above_post_stream_ad_sizes))], 'div-gpt-ad-topic-above-post-stream').addService(googletag.pubads());
googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_post_stream_code, [parseInt(splitWidthInt(settings.topic_above_post_stream_ad_sizes)), parseInt(splitHeightInt(settings.topic_above_post_stream_ad_sizes))], 'div-gpt-ad-topic-above-post-stream')
.setTargeting(settings.dfp_target_topic_above_post_stream_key_code, valueParse(settings.dfp_target_topic_above_post_stream_value_code))
// This hardcoded code works: .setTargeting('category', ["clothes", "handbags", "makeup"])
.addService(googletag.pubads());
}
}
if (settings.dfp_topic_above_suggested_code && !settings.dfp_show_topic_above_suggested && settings.topic_above_suggested_ad_sizes) {
@ -76,7 +77,10 @@ function loadGoogle(settings) {
googletag.defineSlot(settings.dfp_topic_above_suggested_code, [320,50], 'div-gpt-ad-topic-above-suggested').addService(googletag.pubads());
}
else {
googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_suggested_code, [parseInt(splitWidthInt(settings.topic_above_suggested_ad_sizes)), parseInt(splitHeightInt(settings.topic_above_suggested_ad_sizes))], 'div-gpt-ad-topic-above-suggested').addService(googletag.pubads());
googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_suggested_code, [parseInt(splitWidthInt(settings.topic_above_suggested_ad_sizes)), parseInt(splitHeightInt(settings.topic_above_suggested_ad_sizes))], 'div-gpt-ad-topic-above-suggested')
.setTargeting(settings.dfp_target_topic_above_suggested_key_code, valueParse(settings.dfp_target_topic_above_suggested_value_code))
// This hardcoded code works: .setTargeting('category', ["clothes", "handbags", "makeup"])
.addService(googletag.pubads());
}
}
if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes) {
@ -86,7 +90,10 @@ function loadGoogle(settings) {
googletag.defineSlot(settings.dfp_post_bottom_code, [320,50], 'div-gpt-ad-post-bottom').addService(googletag.pubads());
}
else {
googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_post_bottom_code, [parseInt(splitWidthInt(settings.post_bottom_ad_sizes)), parseInt(splitHeightInt(settings.post_bottom_ad_sizes))], 'div-gpt-ad-post-bottom').addService(googletag.pubads());
googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_post_bottom_code, [parseInt(splitWidthInt(settings.post_bottom_ad_sizes)), parseInt(splitHeightInt(settings.post_bottom_ad_sizes))], 'div-gpt-ad-post-bottom')
.setTargeting(settings.dfp_target_post_bottom_key_code, valueParse(settings.dfp_target_post_bottom_value_code))
// This hardcoded code works: .setTargeting('category', ["clothes", "handbags", "makeup"])
.addService(googletag.pubads());
}
}

View File

@ -1,4 +1,3 @@
{{#if postSpecificCountDFP}}
{{google-dfp-ad placement="post-bottom"}}
{{/if}}
{{/if}}

View File

@ -10,7 +10,7 @@ export default {
postSpecificCountAdsense: function() {
return this.get('post_number') === parseInt(Discourse.SiteSettings.adsense_nth_post_code);
}.property('post_number')
}.property('post_number'),
});
}
};

View File

@ -9,16 +9,19 @@ en:
dfp_show_topic_above_post_stream: "Disable topic_above_post_stream ad"
dfp_topic_above_post_stream_code: "Show leaderboard ad above post stream"
topic_above_post_stream_ad_sizes: "Choose your ad size"
dfp_topic_above_post_stream_custom_targeting_code: "Add your custom targeting code - see instructions"
dfp_target_topic_above_post_stream_key_code: "Input key values - Inventory Level"
dfp_target_topic_above_post_stream_value_code: "Input key values - Inventory Level"
dfp_show_topic_above_suggested: "Disable topic_above_suggested ad"
dfp_topic_above_suggested_code: "Show leaderboard ad above suggested topics"
topic_above_suggested_ad_sizes: "Choose your ad size"
dfp_topic_above_suggested_custom_targeting_code: "Add your custom targeting code - see instructions"
dfp_target_topic_above_suggested_key_code: "Input key values - Inventory Level"
dfp_target_topic_above_suggested_value_code: "Input key values - Inventory Level"
dfp_show_post_bottom: "Disable post_bottom ad"
dfp_post_bottom_code: "Show leaderboard ad post_bottom topics"
dfp_nth_post_code: "Choose the Nth position for your ad to show"
post_bottom_ad_sizes: "Choose your ad size"
dfp_post_bottom_custom_targeting_code: "Add your custom targeting code - see instructions"
dfp_target_post_bottom_key_code: "Input key values - Inventory Level"
dfp_target_post_bottom_value_code: "Input key values - Inventory Level"
adsense_publisher_code: "Insert your Publisher ID here"
adsense_show_topic_list_top: "Disable topic_list_top ad"
adsense_topic_list_top_code: "Show leaderboard ad above topic lists."

View File

@ -142,7 +142,10 @@ ad_plugin:
dfp_show_topic_above_post_stream:
client: true
default: false
dfp_topic_above_post_stream_custom_targeting_code:
dfp_target_topic_above_post_stream_key_code:
client: true
default: ''
dfp_target_topic_above_post_stream_value_code:
client: true
default: ''
dfp_topic_above_suggested_code:
@ -166,7 +169,10 @@ ad_plugin:
dfp_show_topic_above_suggested:
client: true
default: false
dfp_topic_above_suggested_custom_targeting_code:
dfp_target_topic_above_suggested_key_code:
client: true
default: ''
dfp_target_topic_above_suggested_value_code:
client: true
default: ''
dfp_post_bottom_code:
@ -193,6 +199,9 @@ ad_plugin:
dfp_show_post_bottom:
client: true
default: false
dfp_post_bottom_custom_targeting_code:
dfp_target_post_bottom_key_code:
client: true
default: ''
dfp_target_post_bottom_value_code:
client: true
default: ''