From 86054c51640e54a4e2d8cf7c95aa2520e904ee7f Mon Sep 17 00:00:00 2001 From: vi Date: Fri, 21 Aug 2015 11:19:18 +1000 Subject: [PATCH] Added input slots for custom targeting in dfp --- .../discourse/components/google-dfp-ad.js.es6 | 14 ++++++++------ config/locales/server.en.yml | 4 ++++ config/settings.yml | 14 +++++++++++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 6784355..99f2d90 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -16,7 +16,7 @@ function splitHeightInt(value) { var str = value.substring(4, 7); return str.trim(); } - + function loadGoogle(settings) { if (_loaded) { return Ember.RSVP.resolve(); @@ -35,14 +35,16 @@ function loadGoogle(settings) { } // Define our ad units - extend for mobile view. - // Inventory or slot level custom targeting goes here for each of the defined ad units - needs input and injection. - // For each ad slot, if there is set target, then don't put semicolon in after addService, if so, then add it in to close off function. - // Need to add something to the actual site itself... on the page googletag.pubads().setTargeting(‘publisher’, ‘affiliate1′);: + // if statement? the code should be able to run without the custom targeting settings googletag.cmd.push(function() { if (settings.dfp_topic_list_top_code && !settings.dfp_show_topic_list_top && 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)); - 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').setTargeting('gender', ['female']).addService(googletag.pubads()); + 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') + // Inventory or slot level custom targeting goes here for each of the defined ad units - needs input and injection. + // The ad runs with .setTargeting('gender', ['female']) + .settings.dfp_topic_list_top_custom_targeting_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) { const_width = parseInt(splitWidthInt(settings.topic_above_post_stream_ad_sizes)); @@ -61,7 +63,6 @@ function loadGoogle(settings) { } // Page Level custom targeting goes here - needs an input section and also ad tags on the relevant pages - // googletag.pubads().setTargeting("gender","female"); googletag.pubads().enableSingleRequest(); googletag.enableServices(); }); @@ -84,6 +85,7 @@ export default Ember.Component.extend({ return "div-gpt-ad-" + this.get('placement'); }.property('placement'), +//settings.dfp_topic_list_top_custom_targeting_code _initGoogleDFP: function() { var self = this; loadGoogle(this.siteSettings).then(function() { diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index b4701ec..2a609f3 100755 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -4,13 +4,17 @@ en: dfp_show_topic_list_top: "Disable topic_list_top ad" dfp_topic_list_top_code: "Show leaderboard ad above topic lists." topic_list_top_ad_sizes: "Choose your ad size" + dfp_topic_list_top_custom_targeting_code: "Add your custom targeting code - see instructions" 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_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_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" \ No newline at end of file diff --git a/config/settings.yml b/config/settings.yml index 93a492a..728065b 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -23,6 +23,9 @@ ad_plugin: dfp_show_topic_list_top: client: true default: false + dfp_topic_list_top_custom_targeting_code: + client: true + default: '' dfp_topic_above_post_stream_code: client: true default: '' @@ -44,6 +47,9 @@ ad_plugin: dfp_show_topic_above_post_stream: client: true default: false + dfp_topic_above_post_stream_custom_targeting_code: + client: true + default: '' dfp_topic_above_suggested_code: client: true default: '' @@ -65,6 +71,9 @@ ad_plugin: dfp_show_topic_above_suggested: client: true default: false + dfp_topic_above_suggested_custom_targeting_code: + client: true + default: '' dfp_post_bottom_code: client: true default: '' @@ -88,4 +97,7 @@ ad_plugin: - 250*250 - square dfp_show_post_bottom: client: true - default: false \ No newline at end of file + default: false + dfp_post_bottom_custom_targeting_code: + client: true + default: '' \ No newline at end of file