Added trust levels to site settings for dfp

This commit is contained in:
vi 2015-09-01 11:27:31 +10:00
parent 2f1ac77380
commit 6452c9c5b1
4 changed files with 13 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import loadScript from 'discourse/lib/load-script';
var const_width = ''; var const_width = '';
var const_height = ''; var const_height = '';
var currentUser = Discourse.User.current();
var _loaded = false, var _loaded = false,
_promise = null; _promise = null;
@ -91,7 +92,7 @@ function loadGoogle(settings) {
} }
googletag.cmd.push(function() { googletag.cmd.push(function() {
if (settings.dfp_topic_list_top_code && !settings.dfp_show_topic_list_top && settings.topic_list_top_ad_sizes) { if (settings.dfp_topic_list_top_code && !settings.dfp_show_topic_list_top && settings.topic_list_top_ad_sizes && !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.dfp_through_trust_level))) {
const_width = parseInt(splitWidthInt(settings.topic_list_top_ad_sizes)); const_width = parseInt(splitWidthInt(settings.topic_list_top_ad_sizes));
const_height = parseInt(splitHeightInt(settings.topic_list_top_ad_sizes)); const_height = parseInt(splitHeightInt(settings.topic_list_top_ad_sizes));
if (Discourse.Mobile.mobileView) { if (Discourse.Mobile.mobileView) {
@ -99,11 +100,12 @@ function loadGoogle(settings) {
} }
else { else {
googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_list_top_code, [parseInt(splitWidthInt(settings.topic_list_top_ad_sizes)), parseInt(splitHeightInt(settings.topic_list_top_ad_sizes))], 'div-gpt-ad-topic-list-top') googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_list_top_code, [parseInt(splitWidthInt(settings.topic_list_top_ad_sizes)), parseInt(splitHeightInt(settings.topic_list_top_ad_sizes))], 'div-gpt-ad-topic-list-top')
custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_value_code))) .setTargeting('gender', ['female'])
googletag.addService(googletag.pubads()); //custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_value_code)))
.addService(googletag.pubads());
} }
} }
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_width = parseInt(splitWidthInt(settings.topic_above_post_stream_ad_sizes));
const_height = parseInt(splitHeightInt(settings.topic_above_post_stream_ad_sizes)); const_height = parseInt(splitHeightInt(settings.topic_above_post_stream_ad_sizes));
if (Discourse.Mobile.mobileView) { if (Discourse.Mobile.mobileView) {
@ -116,7 +118,7 @@ function loadGoogle(settings) {
.addService(googletag.pubads()); .addService(googletag.pubads());
} }
} }
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_width = parseInt(splitWidthInt(settings.topic_above_suggested_ad_sizes));
const_height = parseInt(splitHeightInt(settings.topic_above_suggested_ad_sizes)); const_height = parseInt(splitHeightInt(settings.topic_above_suggested_ad_sizes));
if (Discourse.Mobile.mobileView) { if (Discourse.Mobile.mobileView) {
@ -130,7 +132,7 @@ function loadGoogle(settings) {
googletag.addService(googletag.pubads()); googletag.addService(googletag.pubads());
} }
} }
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_width = parseInt(splitWidthInt(settings.post_bottom_ad_sizes));
const_height = parseInt(splitHeightInt(settings.post_bottom_ad_sizes)); const_height = parseInt(splitHeightInt(settings.post_bottom_ad_sizes));
if (Discourse.Mobile.mobileView) { if (Discourse.Mobile.mobileView) {

View File

@ -1,5 +1,3 @@
<div class="google-dfp-ad-label"><h2>Google Ad Plugin Display</h2></div>
{{#if site.mobileView}} {{#if site.mobileView}}
{{#if loadedGoogletag}} {{#if loadedGoogletag}}
<div id={{divId}} style={{adWrapperStyleMobile}} class="dfp-ad-unit" align=center> <div id={{divId}} style={{adWrapperStyleMobile}} class="dfp-ad-unit" align=center>

View File

@ -1,6 +1,7 @@
en: en:
site_settings: site_settings:
dfp_publisher_id: "Put in your publisher id here" 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_show_topic_list_top: "Disable topic_list_top ad"
dfp_topic_list_top_code: "Show leaderboard ad above topic lists." dfp_topic_list_top_code: "Show leaderboard ad above topic lists."
topic_list_top_ad_sizes: "Choose your ad size" topic_list_top_ad_sizes: "Choose your ad size"

View File

@ -98,6 +98,10 @@ ad_plugin:
dfp_publisher_id: dfp_publisher_id:
client: true client: true
default: '' default: ''
dfp_through_trust_level:
client: true
default: 2
enum: 'TrustLevelSetting'
dfp_topic_list_top_code: dfp_topic_list_top_code:
client: true client: true
default: '' default: ''