Merge pull request #7 from team-melbourne-rgsoc2015/test-initializer-function

All plugin outlet locations now have one hbs file for connectors - solved the post-bottom problem.
This commit is contained in:
Sarah Ni 2015-08-31 16:12:51 +10:00
commit a03d2532d5
13 changed files with 136 additions and 46 deletions

View File

@ -7,6 +7,7 @@ var publisher_id = Discourse.SiteSettings.adsense_publisher_code;
var preGoogleVars = null; var preGoogleVars = null;
var postGoogleVars = null; var postGoogleVars = null;
function splitWidthInt(value) { function splitWidthInt(value) {
var str = value.substring(0, 3); var str = value.substring(0, 3);
return str.trim(); return str.trim();
@ -20,6 +21,7 @@ function splitHeightInt(value) {
PageTracker.current().on('change', function(url) { PageTracker.current().on('change', function(url) {
var ads = document.getElementById("adsense_loader"); var ads = document.getElementById("adsense_loader");
if (ads) { if (ads) {
// clear the old element and its state // 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_publisher_code) {
if (Discourse.SiteSettings.adsense_topic_list_top_code && !Discourse.SiteSettings.adsense_show_topic_list_top) { if (Discourse.SiteSettings.adsense_topic_list_top_code && !Discourse.SiteSettings.adsense_show_topic_list_top) {
ad_code = Discourse.SiteSettings.adsense_topic_list_top_code; data["topic-list-top"]["ad_code"] = Discourse.SiteSettings.adsense_topic_list_top_code;
ad_width = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_list_top_ad_sizes)); data["topic-list-top"]["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_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) { 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; data["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)); data["topic-above-post-stream"]["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_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) { if (Discourse.SiteSettings.adsense_topic_above_suggested_code && !Discourse.SiteSettings.adsense_show_topic_above_suggested) {
ad_code = Discourse.SiteSettings.adsense_topic_above_suggested_code; data["topic-above-suggested"]["ad_code"] = Discourse.SiteSettings.adsense_topic_above_suggested_code;
ad_width = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes)); data["topic-above-suggested"]["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_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_topic_above_suggested_ad_sizes));
} }
if (Discourse.SiteSettings.adsense_post_bottom_code && !Discourse.SiteSettings.adsense_show_post_bottom) { if (Discourse.SiteSettings.adsense_post_bottom_code && !Discourse.SiteSettings.adsense_show_post_bottom) {
ad_code = Discourse.SiteSettings.adsense_post_bottom_code; data["post-bottom"]["ad_code"] = Discourse.SiteSettings.adsense_post_bottom_code;
ad_width = parseInt(splitWidthInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes)); data["post-bottom"]["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_height"] = parseInt(splitHeightInt(Discourse.SiteSettings.adsense_post_bottom_ad_sizes));
} }
} }
@ -90,6 +99,13 @@ export default Ember.Component.extend({
ad_width: ad_width, ad_width: ad_width,
ad_height: ad_height, 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() { adWrapperStyle: function() {
return `width: ${this.get('ad_width')}px; height: ${this.get('ad_height')}px; margin:0 auto;`.htmlSafe(); return `width: ${this.get('ad_width')}px; height: ${this.get('ad_height')}px; margin:0 auto;`.htmlSafe();
}.property('ad_width', 'ad_height'), }.property('ad_width', 'ad_height'),

View File

@ -16,6 +16,11 @@ function splitHeightInt(value) {
var str = value.substring(4, 7); var str = value.substring(4, 7);
return str.trim(); 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 // This creates an array for the values of the custom targeting key
function valueParse(value) { function valueParse(value) {
@ -25,6 +30,48 @@ function valueParse(value) {
return final; 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) { //PageTracker.current().on('change', function(url) {
function loadGoogle(settings) { function loadGoogle(settings) {
if (_loaded) { if (_loaded) {
@ -52,11 +99,9 @@ function loadGoogle(settings) {
} }
else { 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') 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)) //custom_targeting((keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_key_code)), (keyParse(Discourse.SiteSettings.dfp_target_topic_list_top_value_code)))
// This hardcoded code works: .setTargeting('category', ["clothes", "handbags", "makeup"]) .setTargeting('gender', 'female')
.addService(googletag.pubads()); .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) { 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()); googletag.defineSlot(settings.dfp_topic_above_post_stream_code, [320,50], 'div-gpt-ad-topic-above-post-stream').addService(googletag.pubads());
} }
else { 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) { 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()); googletag.defineSlot(settings.dfp_topic_above_suggested_code, [320,50], 'div-gpt-ad-topic-above-suggested').addService(googletag.pubads());
} }
else { 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) { 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()); googletag.defineSlot(settings.dfp_post_bottom_code, [320,50], 'div-gpt-ad-post-bottom').addService(googletag.pubads());
} }
else { 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());
} }
} }

View File

@ -1,3 +1,6 @@
{{#if siteSettings.adsense_topic_list_top_code}} {{#if siteSettings.adsense_topic_list_top_code}}
{{google-adsense placement="topic-list-top"}} {{google-adsense placement="topic-list-top"}}
{{/if}} {{/if}}
{{#if siteSettings.dfp_topic_list_top_code}}
{{google-dfp-ad placement="topic-list-top"}}
{{/if}}

View File

@ -1,3 +0,0 @@
{{#if siteSettings.dfp_topic_list_top_code}}
{{google-dfp-ad placement="topic-list-top"}}
{{/if}}

View File

@ -1,3 +1,6 @@
{{#if postSpecificCountAdsense}} {{#if postSpecificCountAdsense}}
{{google-adsense placement="post-bottom"}} {{google-adsense placement="post-bottom"}}
{{/if}} {{/if}}
{{#if postSpecificCountDFP}}
{{google-dfp-ad placement="post-bottom"}}
{{/if}}

View File

@ -1,4 +0,0 @@
{{#if postSpecificCountDFP}}
{{google-dfp-ad placement="post-bottom"}}
{{/if}}

View File

@ -1,3 +1,6 @@
{{#if siteSettings.adsense_topic_above_post_stream_code}} {{#if siteSettings.adsense_topic_above_post_stream_code}}
{{google-adsense placement="topic-above-post-stream"}} {{google-adsense placement="topic-above-post-stream"}}
{{/if}} {{/if}}
{{#if siteSettings.dfp_topic_above_post_stream_code}}
{{google-dfp-ad placement="topic-above-post-stream"}}
{{/if}}

View File

@ -1,3 +0,0 @@
{{#if siteSettings.dfp_topic_above_post_stream_code}}
{{google-dfp-ad placement="topic-above-post-stream"}}
{{/if}}

View File

@ -1,3 +1,6 @@
{{#if siteSettings.adsense_topic_above_suggested_code}} {{#if siteSettings.adsense_topic_above_suggested_code}}
{{google-adsense placement="topic-above-suggested"}} {{google-adsense placement="topic-above-suggested"}}
{{/if}} {{/if}}
{{#if siteSettings.dfp_topic_above_suggested_code}}
{{google-dfp-ad placement="topic-above-suggested"}}
{{/if}}

View File

@ -1,3 +0,0 @@
{{#if siteSettings.dfp_topic_above_suggested_code}}
{{google-dfp-ad placement="topic-above-suggested"}}
{{/if}}

View File

@ -10,7 +10,7 @@ export default {
postSpecificCountAdsense: function() { 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') }.property('post_number'),
}); });
} }
}; };

View File

@ -9,16 +9,19 @@ en:
dfp_show_topic_above_post_stream: "Disable topic_above_post_stream ad" dfp_show_topic_above_post_stream: "Disable topic_above_post_stream ad"
dfp_topic_above_post_stream_code: "Show leaderboard ad above post stream" dfp_topic_above_post_stream_code: "Show leaderboard ad above post stream"
topic_above_post_stream_ad_sizes: "Choose your ad size" 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_show_topic_above_suggested: "Disable topic_above_suggested ad"
dfp_topic_above_suggested_code: "Show leaderboard ad above suggested topics" dfp_topic_above_suggested_code: "Show leaderboard ad above suggested topics"
topic_above_suggested_ad_sizes: "Choose your ad size" 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_show_post_bottom: "Disable post_bottom ad"
dfp_post_bottom_code: "Show leaderboard ad post_bottom topics" dfp_post_bottom_code: "Show leaderboard ad post_bottom topics"
dfp_nth_post_code: "Choose the Nth position for your ad to show" dfp_nth_post_code: "Choose the Nth position for your ad to show"
post_bottom_ad_sizes: "Choose your ad size" 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_publisher_code: "Insert your Publisher ID here"
adsense_show_topic_list_top: "Disable topic_list_top ad" adsense_show_topic_list_top: "Disable topic_list_top ad"
adsense_topic_list_top_code: "Show leaderboard ad above topic lists." adsense_topic_list_top_code: "Show leaderboard ad above topic lists."

View File

@ -113,11 +113,13 @@ ad_plugin:
- 200*200 - small square - 200*200 - small square
- 250*250 - square - 250*250 - square
dfp_target_topic_list_top_key_code: dfp_target_topic_list_top_key_code:
client: true
default: '' default: ''
type: url_list
client: true
dfp_target_topic_list_top_value_code: dfp_target_topic_list_top_value_code:
client: true
default: '' default: ''
type: url_list
client: true
dfp_show_topic_list_top: dfp_show_topic_list_top:
client: true client: true
default: false default: false
@ -142,9 +144,14 @@ ad_plugin:
dfp_show_topic_above_post_stream: dfp_show_topic_above_post_stream:
client: true client: true
default: false default: false
dfp_topic_above_post_stream_custom_targeting_code: dfp_target_topic_above_post_stream_key_code:
client: true
default: '' 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: dfp_topic_above_suggested_code:
client: true client: true
default: '' default: ''
@ -166,9 +173,14 @@ ad_plugin:
dfp_show_topic_above_suggested: dfp_show_topic_above_suggested:
client: true client: true
default: false default: false
dfp_topic_above_suggested_custom_targeting_code: dfp_target_topic_above_suggested_key_code:
client: true
default: '' default: ''
type: url_list
client: true
dfp_target_topic_above_suggested_value_code:
default: ''
type: url_list
client: true
dfp_post_bottom_code: dfp_post_bottom_code:
client: true client: true
default: '' default: ''
@ -193,6 +205,11 @@ ad_plugin:
dfp_show_post_bottom: dfp_show_post_bottom:
client: true client: true
default: false default: false
dfp_post_bottom_custom_targeting_code: dfp_target_post_bottom_key_code:
client: true
default: '' default: ''
type: url_list
client: true
dfp_target_post_bottom_value_code:
default: ''
type: url_list
client: true