From cdb4c50eff300ec045a8f8961a598af326253b68 Mon Sep 17 00:00:00 2001 From: Sarah Ni Date: Mon, 31 Aug 2015 14:44:47 +1000 Subject: [PATCH] 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) {