diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index b95fede..49c8896 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -15,7 +15,7 @@ function splitHeightInt(value) { var str = value.substring(4, 7); return str.trim(); } - + function loadGoogle(settings) { if (_loaded) { return Ember.RSVP.resolve(); @@ -34,6 +34,7 @@ function loadGoogle(settings) { } // Define our ad units - extend for mobile view. + // 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)); @@ -42,8 +43,11 @@ function loadGoogle(settings) { googletag.defineSlot(settings.dfp_topic_list_top_code, [320,50], 'div-gpt-ad-topic-list-top').addService(googletag.pubads()); } else { - googletag.defineSlot(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').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)); @@ -52,8 +56,7 @@ 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_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').addService(googletag.pubads()); } if (settings.dfp_topic_above_suggested_code && !settings.dfp_show_topic_above_suggested && settings.topic_above_suggested_ad_sizes) { const_width = parseInt(splitWidthInt(settings.topic_above_suggested_ad_sizes)); @@ -62,8 +65,7 @@ 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_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').addService(googletag.pubads()); } if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes) { const_width = parseInt(splitWidthInt(settings.post_bottom_ad_sizes)); @@ -72,9 +74,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_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').addService(googletag.pubads()); } + + // Page Level custom targeting goes here - needs an input section and also ad tags on the relevant pages googletag.pubads().enableSingleRequest(); googletag.enableServices(); }); diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 6df20c8..2a609f3 100755 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1,15 +1,20 @@ en: site_settings: + dfp_publisher_id: "Put in your publisher id here" 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 f076fb3..728065b 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -1,4 +1,7 @@ ad_plugin: + dfp_publisher_id: + client: true + default: '' dfp_topic_list_top_code: client: true default: '' @@ -20,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: '' @@ -41,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: '' @@ -62,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: '' @@ -85,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