diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6 index 3e7aa3e..976f716 100644 --- a/assets/javascripts/discourse/components/google-adsense.js.es6 +++ b/assets/javascripts/discourse/components/google-adsense.js.es6 @@ -28,40 +28,39 @@ PageTracker.current().on('change', function(url) { var ads = document.getElementById("adsense_loader"); if (ads) { ads.parentNode.removeChild(ads); - for (var key in window) { - if (key.indexOf("google") !== -1){ - window[key] = undefined; - } - // for (var i = 0; i < postGoogleVars.length; i++) { - // var key = postGoogleVars[i]; - // window[key] = undefined; - } - } + // for (var key in window) { + // if (key.indexOf("google") !== -1){ + // window[key] = undefined; + // } + for (var i = 0; i < postGoogleVars.length; i++) { + var key = postGoogleVars[i]; + window[key] = undefined; + } + } - // if(preGoogleVars === null) { - // preGoogleVars = []; - // for(var key in window) { - // if(key.indexOf("google") !== -1) { - // preGoogleVars.push(key); - // } - // } - // } + if(preGoogleVars === null) { + preGoogleVars = []; + for(var key in window) { + if(key.indexOf("google") !== -1) { + preGoogleVars.push(key); + } + } + } var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.id="adsense_loader"; ga.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'; - // ga.addEventListener('load', function(e) { - // if(postGoogleVars === null) { - // postGoogleVars = []; + ga.addEventListener('load', function(e) { + if(postGoogleVars === null) { + postGoogleVars = []; - // for(var key in window) { - // if(key.indexOf("google") !== -1 && preGoogleVars.indexOf(key) == -1) { - // postGoogleVars.push(key); - // } - // } - // } - // }); + for(var key in window) { + if(key.indexOf("google") !== -1 && preGoogleVars.indexOf(key) == -1) { + postGoogleVars.push(key); + } + } + } + }); var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - }); var data = { diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index f2459e4..a8916b9 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -7,9 +7,6 @@ var const_mobile_width = 320; var const_mobile_height = 50; var currentUser = Discourse.User.current(); -var mobile_width = 320; -var mobile_height = 50; - var _loaded = false, _promise = null; @@ -57,12 +54,6 @@ function loadGoogle(settings) { } googletag.cmd.push(function() { - - 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').addService(googletag.pubads()); - var topic_above_post_stream = googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_post_stream_code, [parseInt(splitWidthInt(Discourse.SiteSettings.topic_above_post_stream_top_ad_sizes)), parseInt(splitHeightInt(Discourse.SiteSettings.topic_above_post_stream_ad_sizes))], 'div-gpt-ad-topic-above-post-stream').addService(googletag.pubads()); - var topic_above_suggested = googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_suggested_code, [parseInt(splitWidthInt(Discourse.SiteSettings.topic_above_suggested_ad_sizes)), parseInt(splitHeightInt(Discourse.SiteSettings.topic_above_suggested_ad_sizes))], 'div-gpt-ad-topic-above-suggested').addService(googletag.pubads()); - var post_bottom = googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_post_bottom_code, [parseInt(splitWidthInt(Discourse.SiteSettings.post_bottom_ad_sizes)), parseInt(splitHeightInt(Discourse.SiteSettings.post_bottom_ad_sizes))], 'div-gpt-ad-post-bottom').addService(googletag.pubads()); - // This sets the key and value for custom targeting var Foo = function(key, value, googletag) { this.locationKey = key; @@ -80,7 +71,7 @@ function loadGoogle(settings) { var f; for (var i = 0; i < key_array.length; i++) { var wordValue = valueParse(value_array[i]); - f = new Foo(key_array[i], wordValue, location); + f = new Foo(key_array[i], wordValue, location); f.bar(); } } @@ -92,6 +83,11 @@ function loadGoogle(settings) { googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + 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(Discourse.SiteSettings.topic_list_top_ad_sizes)), parseInt(splitHeightInt(Discourse.SiteSettings.topic_list_top_ad_sizes))], 'div-gpt-ad-topic-list-top') + // .setTargeting('gender', 'male') + // .setTargeting('category', 'clothes') + // .addService(googletag.pubads()); + 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').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)), topic_list_top) } } @@ -102,6 +98,7 @@ function loadGoogle(settings) { googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_post_stream_code, [320,50], 'div-gpt-ad-topic-above-post-stream').addService(googletag.pubads()); } else { + var topic_above_post_stream = googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_post_stream_code, [parseInt(splitWidthInt(Discourse.SiteSettings.topic_above_post_stream_top_ad_sizes)), parseInt(splitHeightInt(Discourse.SiteSettings.topic_above_post_stream_ad_sizes))], 'div-gpt-ad-topic-above-post-stream').addService(googletag.pubads()); custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_above_post_stream_value_code)), topic_above_post_stream) } } @@ -112,6 +109,7 @@ function loadGoogle(settings) { googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_suggested_code, [320,50], 'div-gpt-ad-topic-above-suggested').addService(googletag.pubads()); } else { + var topic_above_suggested = googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_topic_above_suggested_code, [parseInt(splitWidthInt(Discourse.SiteSettings.topic_above_suggested_ad_sizes)), parseInt(splitHeightInt(Discourse.SiteSettings.topic_above_suggested_ad_sizes))], 'div-gpt-ad-topic-above-suggested').addService(googletag.pubads()); custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_above_suggested_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_above_suggested_value_code)), topic_above_suggested) } } @@ -122,6 +120,7 @@ function loadGoogle(settings) { googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_post_bottom_code, [320,50], 'div-gpt-ad-post-bottom').addService(googletag.pubads()); } else { + var post_bottom = googletag.defineSlot('/' + settings.dfp_publisher_id + '/' + settings.dfp_post_bottom_code, [parseInt(splitWidthInt(Discourse.SiteSettings.post_bottom_ad_sizes)), parseInt(splitHeightInt(Discourse.SiteSettings.post_bottom_ad_sizes))], 'div-gpt-ad-post-bottom').addService(googletag.pubads()); custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_post_bottom_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_post_bottom_value_code)), post_bottom) } } @@ -146,9 +145,6 @@ export default Ember.Component.extend({ classNames: ['google-dfp-ad'], loadedGoogletag: false, - mobile_width: mobile_width, - mobile_height: mobile_height, - // Part of the divID of the div part of the GPT divId: function() { return "div-gpt-ad-" + this.get('placement'); diff --git a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs index 6400ab1..20b187d 100644 --- a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs @@ -3,4 +3,4 @@ {{/if}} {{#if siteSettings.dfp_topic_list_top_code}} {{google-dfp-ad placement="topic-list-top"}} -{{/if}} \ No newline at end of file +{{/if}}