Merged mobile slots and trust levels to multiple targeting keys branch
This commit is contained in:
commit
14bd843ac1
|
@ -3,6 +3,10 @@ import PageTracker from 'discourse/lib/page-tracker';
|
|||
var ad_width = '';
|
||||
var ad_height = '';
|
||||
var ad_code = '';
|
||||
var ad_mobile_width = 320;
|
||||
var ad_mobile_height = 50;
|
||||
var ad_mobile_code = '';
|
||||
var currentUser = Discourse.User.current();
|
||||
var publisher_id = Discourse.SiteSettings.adsense_publisher_code;
|
||||
var preGoogleVars = null;
|
||||
var postGoogleVars = null;
|
||||
|
@ -18,43 +22,42 @@ function splitHeightInt(value) {
|
|||
return str.trim();
|
||||
}
|
||||
|
||||
|
||||
PageTracker.current().on('change', function(url) {
|
||||
|
||||
|
||||
var ads = document.getElementById("adsense_loader");
|
||||
if (ads) {
|
||||
// clear the old element and its state
|
||||
//ads.remove();
|
||||
ads.parentNode.removeChild(ads);
|
||||
for (var i = 0; i < postGoogleVars.length; i++) {
|
||||
var key = postGoogleVars[i];
|
||||
window[key] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if(preGoogleVars === null) {
|
||||
preGoogleVars = [];
|
||||
for(var key in window) {
|
||||
if(key.indexOf("google") !== -1) {
|
||||
preGoogleVars.push(key);
|
||||
for (var key in window) {
|
||||
if (key.indexOf("google") !== -1){
|
||||
window[key] = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (var i = 0; i < postGoogleVars.length; i++) {
|
||||
// var key = postGoogleVars[i];
|
||||
// window[key] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// if(preGoogleVars === null) {
|
||||
// preGoogleVars = [];
|
||||
// for(var key in window) {
|
||||
// if(key.indexOf("google") !== -1) {
|
||||
// preGoogleVars.push(key);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.id="adsense_loader";
|
||||
ga.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
|
||||
ga.addEventListener('load', function(e) {
|
||||
if(postGoogleVars === null) {
|
||||
postGoogleVars = [];
|
||||
// ga.addEventListener('load', function(e) {
|
||||
// if(postGoogleVars === null) {
|
||||
// postGoogleVars = [];
|
||||
|
||||
for(var key in window) {
|
||||
if(key.indexOf("google") !== -1 && preGoogleVars.indexOf(key) == -1) {
|
||||
postGoogleVars.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// for(var key in window) {
|
||||
// if(key.indexOf("google") !== -1 && preGoogleVars.indexOf(key) == -1) {
|
||||
// postGoogleVars.push(key);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
|
||||
});
|
||||
|
@ -68,22 +71,27 @@ var data = {
|
|||
|
||||
|
||||
if (Discourse.SiteSettings.adsense_publisher_code) {
|
||||
if (Discourse.SiteSettings.adsense_topic_list_top_code && !Discourse.SiteSettings.adsense_show_topic_list_top) {
|
||||
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_show_topic_list_top && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level))) {
|
||||
if (!Discourse.Mobile.mobileView && Discourse.SiteSettings.adsense_topic_list_top_code) {
|
||||
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.Mobile.mobileView && Discourse.SiteSettings.adsense_mobile_topic_list_top_code) {
|
||||
data["topic-list-top"]["ad_mobile_code"] = Discourse.SiteSettings.adsense_mobile_topic_list_top_code;
|
||||
}
|
||||
}
|
||||
if (Discourse.SiteSettings.adsense_topic_above_post_stream_code && !Discourse.SiteSettings.adsense_show_topic_above_post_stream) {
|
||||
if (Discourse.SiteSettings.adsense_topic_above_post_stream_code && !Discourse.SiteSettings.adsense_show_topic_above_post_stream && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level))) {
|
||||
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) {
|
||||
if (Discourse.SiteSettings.adsense_topic_above_suggested_code && !Discourse.SiteSettings.adsense_show_topic_above_suggested && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level))) {
|
||||
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) {
|
||||
if (Discourse.SiteSettings.adsense_post_bottom_code && !Discourse.SiteSettings.adsense_show_post_bottom && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.adsense_through_trust_level))) {
|
||||
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));
|
||||
|
@ -98,11 +106,14 @@ export default Ember.Component.extend({
|
|||
publisher_id: publisher_id,
|
||||
ad_width: ad_width,
|
||||
ad_height: ad_height,
|
||||
ad_mobile_width: ad_mobile_width,
|
||||
ad_mobile_height: ad_mobile_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.set('ad_mobile_code', data[this.placement]["ad_mobile_code"] );
|
||||
this._super();
|
||||
},
|
||||
|
||||
|
@ -115,8 +126,8 @@ export default Ember.Component.extend({
|
|||
}.property('adWrapperStyle'),
|
||||
|
||||
adWrapperStyleMobile: function() {
|
||||
return `width: 320px; height: 50px; margin:0 auto;`.htmlSafe();
|
||||
},
|
||||
return `width: ${this.get('ad_mobile_width')}px; height: ${this.get('ad_mobile_height')}px; margin:0 auto;`.htmlSafe();
|
||||
}.property('ad_mobile_width', 'ad_mobile_height'),
|
||||
|
||||
adInsStyleMobile: function() {
|
||||
return `display: inline-block; ${this.get('adWrapperStyleMobile')}`.htmlSafe();
|
||||
|
|
|
@ -3,6 +3,9 @@ import loadScript from 'discourse/lib/load-script';
|
|||
|
||||
var const_width = '';
|
||||
var const_height = '';
|
||||
var const_mobile_width = 320;
|
||||
var const_mobile_height = 50;
|
||||
var currentUser = Discourse.User.current();
|
||||
|
||||
var _loaded = false,
|
||||
_promise = null;
|
||||
|
@ -86,7 +89,7 @@ function loadGoogle(settings) {
|
|||
custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_value_code)), topic_list_top)
|
||||
}
|
||||
}
|
||||
if (settings.dfp_topic_above_post_stream_code && !settings.dfp_show_topic_above_post_stream && settings.topic_above_post_stream_ad_sizes) {
|
||||
if (settings.dfp_topic_above_post_stream_code && !settings.dfp_show_topic_above_post_stream && settings.topic_above_post_stream_ad_sizes && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.dfp_through_trust_level))) {
|
||||
const_width = parseInt(splitWidthInt(settings.topic_above_post_stream_ad_sizes));
|
||||
const_height = parseInt(splitHeightInt(settings.topic_above_post_stream_ad_sizes));
|
||||
if (Discourse.Mobile.mobileView) {
|
||||
|
@ -96,7 +99,7 @@ function loadGoogle(settings) {
|
|||
custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_value_code)), topic_above_post_stream)
|
||||
}
|
||||
}
|
||||
if (settings.dfp_topic_above_suggested_code && !settings.dfp_show_topic_above_suggested && settings.topic_above_suggested_ad_sizes) {
|
||||
if (settings.dfp_topic_above_suggested_code && !settings.dfp_show_topic_above_suggested && settings.topic_above_suggested_ad_sizes && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.dfp_through_trust_level))) {
|
||||
const_width = parseInt(splitWidthInt(settings.topic_above_suggested_ad_sizes));
|
||||
const_height = parseInt(splitHeightInt(settings.topic_above_suggested_ad_sizes));
|
||||
if (Discourse.Mobile.mobileView) {
|
||||
|
@ -106,7 +109,7 @@ function loadGoogle(settings) {
|
|||
custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_above_suggested_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_above_suggested_value_code)), topic_above_suggested)
|
||||
}
|
||||
}
|
||||
if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes) {
|
||||
if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.dfp_through_trust_level))) {
|
||||
const_width = parseInt(splitWidthInt(settings.post_bottom_ad_sizes));
|
||||
const_height = parseInt(splitHeightInt(settings.post_bottom_ad_sizes));
|
||||
if (Discourse.Mobile.mobileView) {
|
||||
|
@ -131,6 +134,8 @@ function loadGoogle(settings) {
|
|||
export default Ember.Component.extend({
|
||||
const_width: const_width,
|
||||
const_height: const_height,
|
||||
const_mobile_width: const_mobile_width,
|
||||
const_mobile_height: const_mobile_height,
|
||||
|
||||
classNames: ['google-dfp-ad'],
|
||||
loadedGoogletag: false,
|
||||
|
@ -145,8 +150,8 @@ export default Ember.Component.extend({
|
|||
}.property('const_width', 'const_height'),
|
||||
|
||||
adWrapperStyleMobile: function() {
|
||||
return `width: 320px; height: 50px;`.htmlSafe();
|
||||
},
|
||||
return `width: ${this.get('const_mobile_width')}px; height: ${this.get('const_mobile_height')}px;`.htmlSafe();
|
||||
}.property('const_mobile_width', 'const_mobile_height'),
|
||||
|
||||
_initGoogleDFP: function() {
|
||||
var self = this;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<ins class="adsbygoogle"
|
||||
style={{adInsStyleMobile}}
|
||||
data-ad-client="ca-pub-{{publisher_id}}"
|
||||
data-ad-slot={{ad_code}}>
|
||||
data-ad-slot={{ad_mobile_code}}>
|
||||
</ins>
|
||||
|
||||
<script>
|
||||
|
|
|
@ -1,38 +1,48 @@
|
|||
en:
|
||||
site_settings:
|
||||
dfp_publisher_id: "Put in your publisher id here"
|
||||
dfp_through_trust_level: "Show your ads to users based on trust."
|
||||
dfp_show_topic_list_top: "Disable topic_list_top ad"
|
||||
dfp_topic_list_top_code: "Show leaderboard ad above topic lists."
|
||||
dfp_mobile_topic_list_top_code: "Mobile - Show leaderboard ad above topic lists."
|
||||
topic_list_top_ad_sizes: "Choose your ad size"
|
||||
dfp_target_topic_list_top_key_code: "Input key values - Inventory Level"
|
||||
dfp_target_topic_list_top_value_code: "Input key values - Inventory Level"
|
||||
dfp_show_topic_above_post_stream: "Disable topic_above_post_stream ad"
|
||||
dfp_topic_above_post_stream_code: "Show leaderboard ad above post stream"
|
||||
dfp_mobile_topic_above_post_stream_code: "Mobile - Show leaderboard ad above post stream"
|
||||
topic_above_post_stream_ad_sizes: "Choose your ad size"
|
||||
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"
|
||||
dfp_mobile_topic_above_suggested_code: "Mobile - Show leaderboard ad above suggested topics"
|
||||
topic_above_suggested_ad_sizes: "Choose your ad size"
|
||||
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_mobile_post_bottom_code: "Mobile - 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_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_through_trust_level: "Show your ads to users based on trust."
|
||||
adsense_show_topic_list_top: "Disable topic_list_top ad"
|
||||
adsense_topic_list_top_code: "Show leaderboard ad above topic lists."
|
||||
adsense_mobile_topic_list_top_code: "Mobile - Show leaderboard ad above topic lists."
|
||||
adsense_topic_list_top_ad_sizes: "Choose your ad sizes"
|
||||
adsense_show_topic_above_post_stream: "Disable topic_above_post_stream ad"
|
||||
adsense_topic_above_post_stream_code: "Show leaderboard ad above post stream"
|
||||
adsense_mobile_topic_above_post_stream_code: "Mobile - Show leaderboard ad above post stream"
|
||||
adsense_topic_above_post_stream_ad_sizes: "Choose your ad sizes"
|
||||
adsense_show_topic_above_suggested: "Disable topic_above_suggested ad"
|
||||
adsense_topic_above_suggested_code: "Show leaderboard ad above suggested topics"
|
||||
adsense_mobile_topic_above_suggested_code: "Mobile - Show leaderboard ad above suggested topics"
|
||||
adsense_topic_above_suggested_ad_sizes: "Choose your ad sizes"
|
||||
adsense_post_bottom_code: "Show leaderboard ad post_bottom topics"
|
||||
adsense_mobile_post_bottom_code: "Mobile - Show leaderboard ad post_bottom topics"
|
||||
adsense_show_post_bottom: "Disable post_bottom ad"
|
||||
adsense_post_bottom_ad_sizes: "Choose your ad sizes"
|
||||
adsense_nth_post_code: "Choose the Nth position for your ad to show"
|
|
@ -2,9 +2,16 @@ adsense_plugin:
|
|||
adsense_publisher_code:
|
||||
client: true
|
||||
default: ''
|
||||
adsense_through_trust_level:
|
||||
client: true
|
||||
default: 2
|
||||
enum: 'TrustLevelSetting'
|
||||
adsense_topic_list_top_code:
|
||||
client: true
|
||||
default: ''
|
||||
adsense_mobile_topic_list_top_code:
|
||||
client: true
|
||||
default: ''
|
||||
adsense_show_topic_list_top:
|
||||
client: true
|
||||
default: false
|
||||
|
@ -26,6 +33,9 @@ adsense_plugin:
|
|||
adsense_topic_above_post_stream_code:
|
||||
client: true
|
||||
default: ''
|
||||
adsense_mobile_topic_above_post_stream_code:
|
||||
client: true
|
||||
default: ''
|
||||
adsense_show_topic_above_post_stream:
|
||||
client: true
|
||||
default: false
|
||||
|
@ -47,6 +57,9 @@ adsense_plugin:
|
|||
adsense_topic_above_suggested_code:
|
||||
client: true
|
||||
default: ''
|
||||
adsense_mobile_topic_above_suggested_code:
|
||||
client: true
|
||||
default: ''
|
||||
adsense_show_topic_above_suggested:
|
||||
client: true
|
||||
default: false
|
||||
|
@ -68,6 +81,9 @@ adsense_plugin:
|
|||
adsense_post_bottom_code:
|
||||
client: true
|
||||
default: ''
|
||||
adsense_mobile_post_bottom_code:
|
||||
client: true
|
||||
default: ''
|
||||
adsense_show_post_bottom:
|
||||
client: true
|
||||
default: false
|
||||
|
@ -94,9 +110,16 @@ ad_plugin:
|
|||
dfp_publisher_id:
|
||||
client: true
|
||||
default: ''
|
||||
dfp_through_trust_level:
|
||||
client: true
|
||||
default: 2
|
||||
enum: 'TrustLevelSetting'
|
||||
dfp_topic_list_top_code:
|
||||
client: true
|
||||
default: ''
|
||||
dfp_mobile_topic_list_top_code:
|
||||
client: true
|
||||
default: ''
|
||||
topic_list_top_ad_sizes:
|
||||
client: true
|
||||
default: '728*90 - leaderboard'
|
||||
|
@ -126,6 +149,9 @@ ad_plugin:
|
|||
dfp_topic_above_post_stream_code:
|
||||
client: true
|
||||
default: ''
|
||||
dfp_mobile_topic_above_post_stream_code:
|
||||
client: true
|
||||
default: ''
|
||||
topic_above_post_stream_ad_sizes:
|
||||
client: true
|
||||
default: '728*90 - leaderboard'
|
||||
|
@ -155,6 +181,9 @@ ad_plugin:
|
|||
dfp_topic_above_suggested_code:
|
||||
client: true
|
||||
default: ''
|
||||
dfp_mobile_topic_above_suggested_code:
|
||||
client: true
|
||||
default: ''
|
||||
topic_above_suggested_ad_sizes:
|
||||
client: true
|
||||
default: '728*90 - leaderboard'
|
||||
|
@ -184,6 +213,9 @@ ad_plugin:
|
|||
dfp_post_bottom_code:
|
||||
client: true
|
||||
default: ''
|
||||
dfp_mobile_post_bottom_code:
|
||||
client: true
|
||||
default: ''
|
||||
dfp_nth_post_code:
|
||||
client: true
|
||||
default: ''
|
||||
|
|
Loading…
Reference in New Issue