diff --git a/assets/javascripts/discourse/components/google-adsense.js.es6 b/assets/javascripts/discourse/components/google-adsense.js.es6
new file mode 100644
index 0000000..7a79fe8
--- /dev/null
+++ b/assets/javascripts/discourse/components/google-adsense.js.es6
@@ -0,0 +1,87 @@
+import PageTracker from 'discourse/lib/page-tracker';
+
+var ad_width = '';
+var ad_height = '';
+var ad_code = '';
+var publisher_id = Discourse.SiteSettings.adsense_publisher_code;
+
+function splitWidthInt(value) {
+ var str = value.substring(0, 3);
+ return str.trim();
+}
+
+function splitHeightInt(value) {
+ var str = value.substring(4, 7);
+ return str.trim();
+}
+
+
+PageTracker.current().on('change', function(url) {
+
+ var ads = document.getElementById("adsense_loader");
+ if (ads) {
+ // clear the old element and its state
+ //ads.remove();
+ ads.parentNode.removeChild(ads);
+ for (var key in window) {
+ if (key.indexOf("google") !== -1){
+ window[key] = undefined;
+ }
+ }
+ }
+
+ 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';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+
+});
+
+
+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));
+ }
+ 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));
+ }
+ 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));
+ }
+ 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));
+ }
+}
+
+
+export default Ember.Component.extend({
+ classNames: ['google-adsense'],
+ loadedGoogletag: false,
+
+ publisher_id: publisher_id,
+ ad_width: ad_width,
+ ad_height: ad_height,
+
+ adWrapperStyle: function() {
+ return `width: ${this.get('ad_width')}px; height: ${this.get('ad_height')}px; margin:0 auto;`.htmlSafe();
+ }.property('ad_width', 'ad_height'),
+
+ adInsStyle: function() {
+ return `display: inline-block; ${this.get('adWrapperStyle')}`.htmlSafe();
+ }.property('adWrapperStyle'),
+
+ adWrapperStyleMobile: function() {
+ return `width: 320px; height: 50px; margin:0 auto;`.htmlSafe();
+ },
+
+ adInsStyleMobile: function() {
+ return `display: inline-block; ${this.get('adWrapperStyleMobile')}`.htmlSafe();
+ }.property('adWrapperStyleMobile'),
+});
\ No newline at end of file
diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6
index 93f652a..10832ed 100755
--- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6
+++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6
@@ -43,11 +43,9 @@ 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')
- // Inventory or slot level custom targeting goes here for each of the defined ad units - needs input and injection.
- // The ad runs with .setTargeting('gender', ['female'])
- .addService(googletag.pubads());
+ 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').addService(googletag.pubads());
}
+ console.log('working');
}
if (settings.dfp_topic_above_post_stream_code && !settings.dfp_show_topic_above_post_stream && settings.topic_above_post_stream_ad_sizes) {
const_width = parseInt(splitWidthInt(settings.topic_above_post_stream_ad_sizes));
diff --git a/assets/javascripts/discourse/templates/components/google-adsense.hbs b/assets/javascripts/discourse/templates/components/google-adsense.hbs
new file mode 100644
index 0000000..ca671d9
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/google-adsense.hbs
@@ -0,0 +1,30 @@
+{{#if site.mobileView}}
+
+
+
+
+
+
+
+{{else}}
+Google Adsense
+
+
+
+
+
+
+
+{{/if}}
+
+
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-google-adsense.hbs
new file mode 100644
index 0000000..6ea3613
--- /dev/null
+++ b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-adsense.hbs
@@ -0,0 +1,3 @@
+{{#if siteSettings.adsense_topic_list_top_code}}
+ {{google-adsense 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
index cc027b1..b20898e 100755
--- 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
@@ -1,3 +1,4 @@
{{#if siteSettings.dfp_topic_list_top_code}}
{{google-dfp-ad placement="topic-list-top"}}
-{{/if}}
\ No newline at end of file
+{{/if}}
+
diff --git a/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-adsense.hbs b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-adsense.hbs
new file mode 100644
index 0000000..32e47ed
--- /dev/null
+++ b/assets/javascripts/discourse/templates/connectors/post-bottom/discourse-google-adsense.hbs
@@ -0,0 +1,3 @@
+{{#if postSpecificCountAdsense}}
+ {{google-adsense 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
index bde0ec1..1cdb5c9 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,4 @@
-{{#if postSpecificCount}}
+{{#if postSpecificCountDFP}}
{{google-dfp-ad placement="post-bottom"}}
{{/if}}
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-google-adsense.hbs
new file mode 100644
index 0000000..5349f0e
--- /dev/null
+++ b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-adsense.hbs
@@ -0,0 +1,3 @@
+{{#if siteSettings.adsense_topic_above_post_stream_code}}
+ {{google-adsense 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-google-adsense.hbs
new file mode 100644
index 0000000..8f281a9
--- /dev/null
+++ b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-adsense.hbs
@@ -0,0 +1,3 @@
+{{#if siteSettings.adsense_topic_above_suggested_code}}
+ {{google-adsense placement="topic-above-suggested"}}
+{{/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 a6e33cd..dbb6aa4 100644
--- a/assets/javascripts/initializers/extend-post-model.js.es6
+++ b/assets/javascripts/initializers/extend-post-model.js.es6
@@ -4,8 +4,12 @@ export default {
name: 'extend-post-model',
initialize() {
PostModel.reopen({
- postSpecificCount: function() {
+ postSpecificCountDFP: function() {
return this.get('post_number') === parseInt(Discourse.SiteSettings.dfp_nth_post_code);
+ }.property('post_number'),
+
+ postSpecificCountAdsense: function() {
+ return this.get('post_number') === parseInt(Discourse.SiteSettings.adsense_nth_post_code);
}.property('post_number')
});
}
diff --git a/auto_generated/plugin_127092dde054de529d47b09811d7a5143048eac1.css b/auto_generated/plugin_127092dde054de529d47b09811d7a5143048eac1.css
new file mode 100644
index 0000000..cb0a5cb
--- /dev/null
+++ b/auto_generated/plugin_127092dde054de529d47b09811d7a5143048eac1.css
@@ -0,0 +1,49 @@
+
+.google-dfp-ad {
+ padding: 3px;
+ margin-bottom: 10px;
+ clear: both;
+}
+
+.google-dfp-ad .dfp-ad-unit {
+ margin: 0 auto;
+}
+
+.google-dfp-ad .google-dfp-ad-label {
+ width: 728px;
+ margin: 0 auto;
+}
+
+.google-dfp-ad .google-dfp-ad-label h2 {
+ margin: 4px 0 !important;
+ color: #858a8c;
+ text-transform: uppercase;
+ font-size: 12px;
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
+ font-weight: normal;
+}
+
+.google-adsense {
+ padding: 3px;
+ margin-bottom: 10px;
+ clear: both;
+}
+
+.google-adsense .adsense-unit {
+ margin: 0 auto;
+}
+
+.google-adsense .google-adsense-label {
+ width: 728px;
+ margin: 0 auto;
+}
+
+.google-adsense .google-adsense-label h2 {
+ margin: 4px 0 !important;
+ color: #858a8c;
+ text-transform: uppercase;
+ font-size: 12px;
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
+ font-weight: normal;
+}
+
diff --git a/auto_generated/plugin_5e03562e98e357709eaba07c3a0e9054afdd7697.css b/auto_generated/plugin_5e03562e98e357709eaba07c3a0e9054afdd7697.css
deleted file mode 100644
index 677144a..0000000
--- a/auto_generated/plugin_5e03562e98e357709eaba07c3a0e9054afdd7697.css
+++ /dev/null
@@ -1,25 +0,0 @@
-
-.google-dfp-ad {
- padding: 3px;
- margin-bottom: 10px;
- clear: both;
-}
-
-.google-dfp-ad .dfp-ad-unit {
- margin: 0 auto;
-}
-
-.google-dfp-ad .google-dfp-ad-label {
- width: 728px;
- margin: 0 auto;
-}
-
-.google-dfp-ad .google-dfp-ad-label h2 {
- margin: 4px 0 !important;
- color: #858a8c;
- text-transform: uppercase;
- font-size: 12px;
- font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
- font-weight: normal;
-}
-
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 320707d..e437608 100755
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3,4 +3,5 @@ en:
admin:
site_settings:
categories:
- ad_plugin: 'Ad Plugin'
\ No newline at end of file
+ ad_plugin: 'Ad Plugin'
+ adsense_plugin: 'Adsense Plugin'
\ No newline at end of file
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 2a609f3..d4e2143 100755
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1,20 +1,34 @@
en:
site_settings:
- dfp_publisher_id: "Put in your publisher id here"
- dfp_show_topic_list_top: "Disable topic_list_top ad"
- dfp_topic_list_top_code: "Show leaderboard ad above topic lists."
- topic_list_top_ad_sizes: "Choose your ad size"
- dfp_topic_list_top_custom_targeting_code: "Add your custom targeting code - see instructions"
- 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_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_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"
\ No newline at end of file
+ dfp_publisher_id: "Put in your publisher id here"
+ dfp_show_topic_list_top: "Disable topic_list_top ad"
+ dfp_topic_list_top_code: "Show leaderboard ad above topic lists."
+ topic_list_top_ad_sizes: "Choose your ad size"
+ dfp_topic_list_top_custom_targeting_code: "Add your custom targeting code - see instructions"
+ 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_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_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"
+ 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."
+ adsense_topic_list_top_ad_sizes: "Choose your ad sizes"
+ adsense_show_topic_above_post_stream: "Disable topic_above_post_stream ad"
+ adsense_topic_above_post_stream_code: "Show leaderboard ad above post stream"
+ adsense_topic_above_post_stream_ad_sizes: "Choose your ad sizes"
+ adsense_show_topic_above_suggested: "Disable topic_above_suggested ad"
+ adsense_topic_above_suggested_code: "Show leaderboard ad above suggested topics"
+ adsense_topic_above_suggested_ad_sizes: "Choose your ad sizes"
+ adsense_post_bottom_code: "Show leaderboard ad post_bottom topics"
+ adsense_show_post_bottom: "Disable post_bottom ad"
+ adsense_post_bottom_ad_sizes: "Choose your ad sizes"
+ adsense_nth_post_code: "Choose the Nth position for your ad to show"
\ No newline at end of file
diff --git a/config/settings.yml b/config/settings.yml
index 0d13762..acf3f3a 100755
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -1,3 +1,95 @@
+adsense_plugin:
+ adsense_publisher_code:
+ client: true
+ default: ''
+ adsense_topic_list_top_code:
+ client: true
+ default: ''
+ adsense_show_topic_list_top:
+ client: true
+ default: false
+ adsense_topic_list_top_ad_sizes:
+ client: true
+ default: '728*90 - leaderboard'
+ type: enum
+ choices:
+ - 728*90 - leaderboard
+ - 336*280 - large rectangle
+ - 300*250 - medium rectangle
+ - 970*90 - large leaderboard
+ - 468*60 - banner
+ - 234*60 - half banner
+ - 125*125 - button
+ - 180*150 - small rectangle
+ - 200*200 - small square
+ - 250*250 - square
+ adsense_topic_above_post_stream_code:
+ client: true
+ default: ''
+ adsense_show_topic_above_post_stream:
+ client: true
+ default: false
+ adsense_topic_above_post_stream_ad_sizes:
+ client: true
+ default: '728*90 - leaderboard'
+ type: enum
+ choices:
+ - 728*90 - leaderboard
+ - 336*280 - large rectangle
+ - 300*250 - medium rectangle
+ - 970*90 - large leaderboard
+ - 468*60 - banner
+ - 234*60 - half banner
+ - 125*125 - button
+ - 180*150 - small rectangle
+ - 200*200 - small square
+ - 250*250 - square
+ adsense_topic_above_suggested_code:
+ client: true
+ default: ''
+ adsense_show_topic_above_suggested:
+ client: true
+ default: false
+ adsense_topic_above_suggested_ad_sizes:
+ client: true
+ default: '728*90 - leaderboard'
+ type: enum
+ choices:
+ - 728*90 - leaderboard
+ - 336*280 - large rectangle
+ - 300*250 - medium rectangle
+ - 970*90 - large leaderboard
+ - 468*60 - banner
+ - 234*60 - half banner
+ - 125*125 - button
+ - 180*150 - small rectangle
+ - 200*200 - small square
+ - 250*250 - square
+ adsense_post_bottom_code:
+ client: true
+ default: ''
+ adsense_show_post_bottom:
+ client: true
+ default: false
+ adsense_post_bottom_ad_sizes:
+ client: true
+ default: '728*90 - leaderboard'
+ type: enum
+ choices:
+ - 728*90 - leaderboard
+ - 336*280 - large rectangle
+ - 300*250 - medium rectangle
+ - 970*90 - large leaderboard
+ - 468*60 - banner
+ - 234*60 - half banner
+ - 125*125 - button
+ - 180*150 - small rectangle
+ - 200*200 - small square
+ - 250*250 - square
+ adsense_nth_post_code:
+ client: true
+ default: ''
+
ad_plugin:
dfp_publisher_id:
client: true
diff --git a/plugin.rb b/plugin.rb
index 94c8feb..165d963 100755
--- a/plugin.rb
+++ b/plugin.rb
@@ -29,4 +29,28 @@ register_css <