diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6 index b167d85..74e5a1d 100644 --- a/assets/javascripts/discourse/components/google-adsense.js.es6 +++ b/assets/javascripts/discourse/components/google-adsense.js.es6 @@ -7,6 +7,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 +21,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 +59,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 +99,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'), diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 7343c34..80db160 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -16,6 +16,11 @@ function splitHeightInt(value) { var str = value.substring(4, 7); return str.trim(); } +/* +// Coaches Note! +// Background: We want to call on google.setTargeting using googletag.bar so that we can can take in inputs from users (key and value) for custom targeting. +// Look at 26 - 55 which should call on googletag.setTargeting. +// Error is occuring on link 49 which is returning "Uncaught ReferenceError: setTargeting is not defined" // This creates an array for the values of the custom targeting key function valueParse(value) { @@ -25,6 +30,48 @@ function valueParse(value) { return final; } +// This creates an array for the key of the custom targeting key +function keyParse(word) { + var key = word; + key = key.replace(/['"]+/g, ''); + key = key.split("\n"); + return key; +} + +// This sets the key and value for custom targeting +var Foo = function(key, value, googletag) { + this.locationKey = key; + this.locationValue = value; + this.googletag = googletag; +} + +// setTargeting is not defined. We want to return as a method - PROBLEM 1 +Foo.prototype.bar = function() { + return this.googletag.setTargeting(this.locationKey, this.locationValue); +} + +// This should call googletag.setTargeting(key for that location, value for that location) +function custom_targeting(key_array, value_array) { + for (var i = 0; i < key_array.length; i++) { + var wordValue = valueParse(value_array[i]); + var f = new Foo(key_array[i], wordValue, googletag); + f.bar(); + console.log("works!"); + } +} + +// END of Coaches Note + +// splitting values +/*var custom_values = []; +var word = keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_value_code); +var wordValue; +for (var i = 0; i < word.length; i++) { + wordValue = valueParse(word[i]); + custom_values.push(wordValue); +}*/ + + //PageTracker.current().on('change', function(url) { function loadGoogle(settings) { if (_loaded) { @@ -52,11 +99,9 @@ function loadGoogle(settings) { } 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') - .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"]) + //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') .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 +111,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 +124,11 @@ 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') + + //googletag.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"]) + googletag.addService(googletag.pubads()); } } if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes) { @@ -86,7 +138,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()); } } diff --git a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-adsense.hbs b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs similarity index 50% rename from assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-adsense.hbs rename to assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs index 6ea3613..6400ab1 100644 --- a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-adsense.hbs +++ b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs @@ -1,3 +1,6 @@ {{#if siteSettings.adsense_topic_list_top_code}} {{google-adsense placement="topic-list-top"}} +{{/if}} +{{#if siteSettings.dfp_topic_list_top_code}} + {{google-dfp-ad placement="topic-list-top"}} {{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-dfp.hbs b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-dfp.hbs deleted file mode 100755 index cc027b1..0000000 --- a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-dfp.hbs +++ /dev/null @@ -1,3 +0,0 @@ -{{#if siteSettings.dfp_topic_list_top_code}} - {{google-dfp-ad placement="topic-list-top"}} -{{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-adsense.hbs b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-adplugin.hbs similarity index 50% rename from assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-adsense.hbs rename to assets/javascripts/discourse/templates/connectors/post-bottom/discourse-adplugin.hbs index 32e47ed..813f65e 100644 --- a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-adsense.hbs +++ b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-adplugin.hbs @@ -1,3 +1,6 @@ {{#if postSpecificCountAdsense}} {{google-adsense placement="post-bottom"}} +{{/if}} +{{#if postSpecificCountDFP}} + {{google-dfp-ad placement="post-bottom"}} {{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-dfp.hbs b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-dfp.hbs deleted file mode 100644 index 1cdb5c9..0000000 --- a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-dfp.hbs +++ /dev/null @@ -1,4 +0,0 @@ -{{#if postSpecificCountDFP}} - {{google-dfp-ad placement="post-bottom"}} -{{/if}} - diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-adsense.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs similarity index 50% rename from assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-adsense.hbs rename to assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs index 5349f0e..b9d5657 100644 --- a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-adsense.hbs +++ b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs @@ -1,3 +1,6 @@ {{#if siteSettings.adsense_topic_above_post_stream_code}} {{google-adsense placement="topic-above-post-stream"}} +{{/if}} +{{#if siteSettings.dfp_topic_above_post_stream_code}} + {{google-dfp-ad placement="topic-above-post-stream"}} {{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-dfp.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-dfp.hbs deleted file mode 100755 index d9a81de..0000000 --- a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-dfp.hbs +++ /dev/null @@ -1,3 +0,0 @@ -{{#if siteSettings.dfp_topic_above_post_stream_code}} - {{google-dfp-ad placement="topic-above-post-stream"}} -{{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-adsense.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs similarity index 50% rename from assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-adsense.hbs rename to assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs index 8f281a9..c429a37 100644 --- a/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-adsense.hbs +++ b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs @@ -1,3 +1,6 @@ {{#if siteSettings.adsense_topic_above_suggested_code}} {{google-adsense placement="topic-above-suggested"}} +{{/if}} +{{#if siteSettings.dfp_topic_above_suggested_code}} + {{google-dfp-ad placement="topic-above-suggested"}} {{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-dfp.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-dfp.hbs deleted file mode 100755 index 0234980..0000000 --- a/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-dfp.hbs +++ /dev/null @@ -1,3 +0,0 @@ -{{#if siteSettings.dfp_topic_above_suggested_code}} - {{google-dfp-ad placement="topic-above-suggested"}} -{{/if}} \ No newline at end of file diff --git a/assets/javascripts/initializers/extend-post-model.js.es6 b/assets/javascripts/initializers/extend-post-model.js.es6 index dbb6aa4..22f911d 100644 --- a/assets/javascripts/initializers/extend-post-model.js.es6 +++ b/assets/javascripts/initializers/extend-post-model.js.es6 @@ -9,8 +9,8 @@ export default { }.property('post_number'), postSpecificCountAdsense: function() { - return this.get('post_number') === parseInt(Discourse.SiteSettings.adsense_nth_post_code); - }.property('post_number') + return this.get('post_number') === parseInt(Discourse.SiteSettings.adsense_nth_post_code); + }.property('post_number'), }); } }; diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 779922c..75ff3e3 100755 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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." diff --git a/config/settings.yml b/config/settings.yml index ab127ee..2a3d648 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -112,12 +112,14 @@ ad_plugin: - 180*150 - small rectangle - 200*200 - small square - 250*250 - square - dfp_target_topic_list_top_key_code: - client: true + dfp_target_topic_list_top_key_code: default: '' + type: url_list + client: true dfp_target_topic_list_top_value_code: - client: true default: '' + type: url_list + client: true dfp_show_topic_list_top: client: true default: false @@ -142,9 +144,14 @@ ad_plugin: dfp_show_topic_above_post_stream: client: true default: false - dfp_topic_above_post_stream_custom_targeting_code: - client: true + dfp_target_topic_above_post_stream_key_code: default: '' + type: url_list + client: true + dfp_target_topic_above_post_stream_value_code: + default: '' + type: url_list + client: true dfp_topic_above_suggested_code: client: true default: '' @@ -166,9 +173,14 @@ ad_plugin: dfp_show_topic_above_suggested: client: true default: false - dfp_topic_above_suggested_custom_targeting_code: - client: true + dfp_target_topic_above_suggested_key_code: default: '' + type: url_list + client: true + dfp_target_topic_above_suggested_value_code: + default: '' + type: url_list + client: true dfp_post_bottom_code: client: true default: '' @@ -193,6 +205,11 @@ ad_plugin: dfp_show_post_bottom: client: true default: false - dfp_post_bottom_custom_targeting_code: + dfp_target_post_bottom_key_code: + default: '' + type: url_list client: true - default: '' \ No newline at end of file + dfp_target_post_bottom_value_code: + default: '' + type: url_list + client: true \ No newline at end of file