From e255a65e320e643a97bd3d982cb4c308c1a510b5 Mon Sep 17 00:00:00 2001 From: vi Date: Tue, 1 Sep 2015 16:04:21 +1000 Subject: [PATCH] Custom targeting working for one key and associated values for that one key per ad slot available - problem in multiple keys --- .../discourse/components/google-dfp-ad.js.es6 | 68 +++++++++---------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index acb92f5..1ec5478 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -38,41 +38,9 @@ function keyParse(word) { 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) { return Ember.RSVP.resolve(); @@ -90,6 +58,37 @@ function loadGoogle(settings) { console.log('googletag is undefined!'); } + var topic_list_top = googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_list_top_code, [parseInt(splitWidthInt(Discourse.SiteSettings.topic_list_top_ad_sizes)), parseInt(splitHeightInt(Discourse.SiteSettings.topic_list_top_ad_sizes))], 'div-gpt-ad-topic-list-top'); + + var DefineSlotFactory = { + create: function(type){ + return type; + } + } + + // 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, DefineSlotFactory.create(topic_list_top)); + return f.bar(); + } + } + + + 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)); @@ -98,9 +97,8 @@ 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_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()); + .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) {