From f94bf791926559cb18cc81d2ea2a98f388d8a490 Mon Sep 17 00:00:00 2001 From: vi Date: Fri, 28 Aug 2015 12:21:40 +1000 Subject: [PATCH 1/7] Added custom targeting to all slots and Sebastian fixed the variable issue in adsense - thanks Seb! --- .../components/google-adsense.js.es6 | 42 +++++++++++++------ .../discourse/components/google-dfp-ad.js.es6 | 17 +++++--- .../post-bottom/discourse-google-dfp.hbs | 3 +- .../initializers/extend-post-model.js.es6 | 2 +- config/locales/server.en.yml | 9 ++-- config/settings.yml | 15 +++++-- 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6 index b167d85..dad8958 100644 --- a/assets/javascripts/discourse/components/google-adsense.js.es6 +++ b/assets/javascripts/discourse/components/google-adsense.js.es6 @@ -1,5 +1,7 @@ import PageTracker from 'discourse/lib/page-tracker'; +console.log(Discourse.SiteSettings.adsense_nth_post_code); + var ad_width = ''; var ad_height = ''; var ad_code = ''; @@ -7,6 +9,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 +23,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 +61,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 +101,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..f4e0be3 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -55,8 +55,6 @@ function loadGoogle(settings) { .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"]) .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 +64,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 +77,10 @@ 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') + .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"]) + .addService(googletag.pubads()); } } if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes) { @@ -86,7 +90,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/post-bottom/discourse-google-dfp.hbs b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-dfp.hbs index 1cdb5c9..67d6664 100644 --- a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-dfp.hbs +++ b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-dfp.hbs @@ -1,4 +1,3 @@ {{#if postSpecificCountDFP}} {{google-dfp-ad placement="post-bottom"}} -{{/if}} - +{{/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..053035d 100644 --- a/assets/javascripts/initializers/extend-post-model.js.es6 +++ b/assets/javascripts/initializers/extend-post-model.js.es6 @@ -10,7 +10,7 @@ export default { postSpecificCountAdsense: function() { return this.get('post_number') === parseInt(Discourse.SiteSettings.adsense_nth_post_code); - }.property('post_number') + }.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..ce14c00 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -142,7 +142,10 @@ ad_plugin: dfp_show_topic_above_post_stream: client: true default: false - dfp_topic_above_post_stream_custom_targeting_code: + dfp_target_topic_above_post_stream_key_code: + client: true + default: '' + dfp_target_topic_above_post_stream_value_code: client: true default: '' dfp_topic_above_suggested_code: @@ -166,7 +169,10 @@ ad_plugin: dfp_show_topic_above_suggested: client: true default: false - dfp_topic_above_suggested_custom_targeting_code: + dfp_target_topic_above_suggested_key_code: + client: true + default: '' + dfp_target_topic_above_suggested_value_code: client: true default: '' dfp_post_bottom_code: @@ -193,6 +199,9 @@ ad_plugin: dfp_show_post_bottom: client: true default: false - dfp_post_bottom_custom_targeting_code: + dfp_target_post_bottom_key_code: + client: true + default: '' + dfp_target_post_bottom_value_code: client: true default: '' \ No newline at end of file From e3dded27d9c004633ba6a45fb7a3c152a77bab31 Mon Sep 17 00:00:00 2001 From: vi Date: Fri, 28 Aug 2015 15:25:11 +1000 Subject: [PATCH 2/7] how to approach the .setTargeting issue --- .../discourse/components/google-dfp-ad.js.es6 | 19 +++++++++++++++++-- .../initializers/extend-post-model.js.es6 | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index f4e0be3..4ac5b76 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -78,9 +78,24 @@ function loadGoogle(settings) { } 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') - .setTargeting(settings.dfp_target_topic_above_suggested_key_code, valueParse(settings.dfp_target_topic_above_suggested_value_code)) + + 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"]) - .addService(googletag.pubads()); + googletag.addService(googletag.pubads()); + + + var Foo = function() {} + Foo.prototype.bar = function() { + // Stuff + return this; + } + + var f = new Foo(); + f.bar().bar().bar(); + f.bar(); + f.bar(); + f.bar(); + } } if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes) { diff --git a/assets/javascripts/initializers/extend-post-model.js.es6 b/assets/javascripts/initializers/extend-post-model.js.es6 index 053035d..22f911d 100644 --- a/assets/javascripts/initializers/extend-post-model.js.es6 +++ b/assets/javascripts/initializers/extend-post-model.js.es6 @@ -9,7 +9,7 @@ export default { }.property('post_number'), postSpecificCountAdsense: function() { - return this.get('post_number') === parseInt(Discourse.SiteSettings.adsense_nth_post_code); + return this.get('post_number') === parseInt(Discourse.SiteSettings.adsense_nth_post_code); }.property('post_number'), }); } From 6d8cbb72e436b5aabdbd26fe08642ab51dc26589 Mon Sep 17 00:00:00 2001 From: Sarah Ni Date: Mon, 31 Aug 2015 12:21:43 +1000 Subject: [PATCH 3/7] Added key slots via url_list and created prototype setTargeting function --- .../discourse/components/google-dfp-ad.js.es6 | 56 ++++++++++++++----- config/settings.yml | 28 ++++++---- 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 4ac5b76..0d9e10b 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -17,6 +17,11 @@ function splitHeightInt(value) { 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) { var final = value.replace(/ /g,''); @@ -25,6 +30,41 @@ 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) { + this.locationKey = key; + this.locationValue = value; +} + +// setTargeting is not defined. We want to return as a method - PROBLEM 1 +Foo.prototype.bar = function() { + return setTargeting((this.locationKey), (this.locationValue)); +} + +// This should call googletag.setTargeting(key for that location, value for that location) +var googletag = new Foo(keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_key_code), valueParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_value_code)); +googletag.bar(); + +// 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,7 +92,7 @@ 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)) + .setTargeting(keyParse(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"]) .addService(googletag.pubads()); } @@ -82,20 +122,6 @@ function loadGoogle(settings) { 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()); - - - var Foo = function() {} - Foo.prototype.bar = function() { - // Stuff - return this; - } - - var f = new Foo(); - f.bar().bar().bar(); - f.bar(); - f.bar(); - f.bar(); - } } if (settings.dfp_post_bottom_code && !settings.dfp_show_post_bottom && settings.post_bottom_ad_sizes) { diff --git a/config/settings.yml b/config/settings.yml index ce14c00..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 @@ -143,11 +145,13 @@ ad_plugin: client: true default: false dfp_target_topic_above_post_stream_key_code: - client: true default: '' + type: url_list + client: true dfp_target_topic_above_post_stream_value_code: - client: true default: '' + type: url_list + client: true dfp_topic_above_suggested_code: client: true default: '' @@ -170,11 +174,13 @@ ad_plugin: client: true default: false dfp_target_topic_above_suggested_key_code: - client: true default: '' + type: url_list + client: true dfp_target_topic_above_suggested_value_code: - client: true default: '' + type: url_list + client: true dfp_post_bottom_code: client: true default: '' @@ -200,8 +206,10 @@ ad_plugin: client: true default: false dfp_target_post_bottom_key_code: - client: true default: '' - dfp_target_post_bottom_value_code: + 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 From 8989d9c5ea8143fd07ec34c28c2c1b14de2b0ecd Mon Sep 17 00:00:00 2001 From: Sarah Ni Date: Mon, 31 Aug 2015 13:49:09 +1000 Subject: [PATCH 4/7] fixed up with Jo's help setTargeting base method --- .../discourse/components/google-dfp-ad.js.es6 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 0d9e10b..7b4f6a3 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -39,19 +39,20 @@ function keyParse(word) { } // This sets the key and value for custom targeting -var Foo = function(key, value) { +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 setTargeting((this.locationKey), (this.locationValue)); + return googletag.setTargeting((this.locationKey), (this.locationValue)); } // This should call googletag.setTargeting(key for that location, value for that location) -var googletag = new Foo(keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_key_code), valueParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_value_code)); -googletag.bar(); +var f = new Foo(keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_key_code), valueParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_value_code), googletag); +f.bar(); // END of Coaches Note From cdb4c50eff300ec045a8f8961a598af326253b68 Mon Sep 17 00:00:00 2001 From: Sarah Ni Date: Mon, 31 Aug 2015 14:44:47 +1000 Subject: [PATCH 5/7] Added custom targeting function error on line 50 when calling f.bar --- .../discourse/components/google-dfp-ad.js.es6 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 7b4f6a3..111985e 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -47,12 +47,20 @@ var Foo = function(key, value, googletag) { // setTargeting is not defined. We want to return as a method - PROBLEM 1 Foo.prototype.bar = function() { - return googletag.setTargeting((this.locationKey), (this.locationValue)); + return this.googletag.setTargeting(this.locationKey, this.locationValue); } // This should call googletag.setTargeting(key for that location, value for that location) -var f = new Foo(keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_key_code), valueParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_value_code), googletag); -f.bar(); +function custom_targeting(key_array, value_array) { + var i = 0; + while (i < key_array.length) { + var custom_values = []; + var wordValue = valueParse(value_array[i]) + var f = new Foo(key_array[i], wordValue, googletag); + f.bar(); + i++; + } +} // END of Coaches Note @@ -93,9 +101,8 @@ 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(keyParse(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"]) - .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))) + googletag.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) { From a7258f48488d97451fe7d0df7386bff05765d051 Mon Sep 17 00:00:00 2001 From: Sarah Ni Date: Mon, 31 Aug 2015 15:25:42 +1000 Subject: [PATCH 6/7] For loop replaces while loop but line 50 doesn't work --- .../discourse/components/google-adsense.js.es6 | 2 -- .../javascripts/discourse/components/google-dfp-ad.js.es6 | 8 +++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6 index dad8958..74e5a1d 100644 --- a/assets/javascripts/discourse/components/google-adsense.js.es6 +++ b/assets/javascripts/discourse/components/google-adsense.js.es6 @@ -1,7 +1,5 @@ import PageTracker from 'discourse/lib/page-tracker'; -console.log(Discourse.SiteSettings.adsense_nth_post_code); - var ad_width = ''; var ad_height = ''; var ad_code = ''; diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index 111985e..acb92f5 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -52,13 +52,11 @@ Foo.prototype.bar = function() { // This should call googletag.setTargeting(key for that location, value for that location) function custom_targeting(key_array, value_array) { - var i = 0; - while (i < key_array.length) { - var custom_values = []; - var wordValue = valueParse(value_array[i]) + 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(); - i++; + console.log("works!"); } } From c38eb3134e14746e562d8568f5e71a9a180df3a5 Mon Sep 17 00:00:00 2001 From: Sarah Ni Date: Mon, 31 Aug 2015 16:10:26 +1000 Subject: [PATCH 7/7] Fixed post-bottom if statement and reduced duplication in connectors --- .../discourse/components/google-dfp-ad.js.es6 | 13 +++++++------ ...se-google-adsense.hbs => discourse-adplugin.hbs} | 3 +++ .../discourse-google-dfp.hbs | 3 --- ...se-google-adsense.hbs => discourse-adplugin.hbs} | 3 +++ .../connectors/post-bottom/discourse-google-dfp.hbs | 3 --- ...se-google-adsense.hbs => discourse-adplugin.hbs} | 3 +++ .../discourse-google-dfp.hbs | 3 --- ...se-google-adsense.hbs => discourse-adplugin.hbs} | 3 +++ .../topic-above-suggested/discourse-google-dfp.hbs | 3 --- 9 files changed, 19 insertions(+), 18 deletions(-) rename assets/javascripts/discourse/templates/connectors/discovery-list-container-top/{discourse-google-adsense.hbs => discourse-adplugin.hbs} (50%) delete mode 100755 assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-dfp.hbs rename assets/javascripts/discourse/templates/connectors/post-bottom/{discourse-google-adsense.hbs => discourse-adplugin.hbs} (50%) delete mode 100644 assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-dfp.hbs rename assets/javascripts/discourse/templates/connectors/topic-above-post-stream/{discourse-google-adsense.hbs => discourse-adplugin.hbs} (50%) delete mode 100755 assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-dfp.hbs rename assets/javascripts/discourse/templates/connectors/topic-above-suggested/{discourse-google-adsense.hbs => discourse-adplugin.hbs} (50%) delete mode 100755 assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-dfp.hbs diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index acb92f5..80db160 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(); } - +/* // 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. @@ -99,8 +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') - custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_value_code))) - 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))) + .setTargeting('gender', 'female') + .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) { @@ -111,7 +112,7 @@ function loadGoogle(settings) { } 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') - .setTargeting(settings.dfp_target_topic_above_post_stream_key_code, valueParse(settings.dfp_target_topic_above_post_stream_value_code)) + //.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()); } @@ -125,7 +126,7 @@ function loadGoogle(settings) { 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') - googletag.setTargeting(settings.dfp_target_topic_above_suggested_key_code, valueParse(settings.dfp_target_topic_above_suggested_value_code)) + //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()); } @@ -138,7 +139,7 @@ function loadGoogle(settings) { } 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') - .setTargeting(settings.dfp_target_post_bottom_key_code, valueParse(settings.dfp_target_post_bottom_value_code)) + //.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 67d6664..0000000 --- a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-dfp.hbs +++ /dev/null @@ -1,3 +0,0 @@ -{{#if postSpecificCountDFP}} - {{google-dfp-ad placement="post-bottom"}} -{{/if}} \ No newline at end of file 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