Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Add exclude groups for each ad platforms #197

Merged
merged 8 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions assets/javascripts/discourse/components/adbutler-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default AdComponent.extend({
},

@discourseComputed
showToDisplayGroups() {
showAdbutlerAds() {
if (!this.currentUser) {
return true;
}
Expand All @@ -122,21 +122,21 @@ export default AdComponent.extend({

@discourseComputed(
"publisherId",
"showToDisplayGroups",
"showAdbutlerAds",
"showToGroups",
"showAfterPost",
"showOnCurrentPage"
)
showAd(
publisherId,
showToDisplayGroups,
showAdbutlerAds,
showToGroups,
showAfterPost,
showOnCurrentPage
) {
return (
publisherId &&
showToDisplayGroups &&
showAdbutlerAds &&
showToGroups &&
showAfterPost &&
showOnCurrentPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default AdComponent.extend({
classNames: ["amazon-product-links"],

showAd: and(
"showToDisplayGroups",
"showAmazonAds",
"showToGroups",
"showAfterPost",
"showOnCurrentPage"
Expand Down Expand Up @@ -174,7 +174,7 @@ export default AdComponent.extend({
},

@discourseComputed
showToDisplayGroups() {
showAmazonAds() {
if (!this.currentUser) {
return true;
}
Expand Down
18 changes: 4 additions & 14 deletions assets/javascripts/discourse/components/carbonads-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default AdComponent.extend({
},

@discourseComputed
showToDisplayGroups() {
showCarbonAds() {
if (!this.currentUser) {
return true;
}
Expand All @@ -31,23 +31,13 @@ export default AdComponent.extend({
@discourseComputed(
"placement",
"serve_id",
"showToDisplayGroups",
"showCarbonAds",
"showToGroups",
"showOnCurrentPage"
)
showAd(
placement,
serveId,
showToDisplayGroups,
showToGroups,
showOnCurrentPage
) {
showAd(placement, serveId, showCarbonAds, showToGroups, showOnCurrentPage) {
return (
placement &&
serveId &&
showToDisplayGroups &&
showToGroups &&
showOnCurrentPage
placement && serveId && showCarbonAds && showToGroups && showOnCurrentPage
);
},
});
8 changes: 4 additions & 4 deletions assets/javascripts/discourse/components/google-adsense.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default AdComponent.extend({
},

@discourseComputed
showToDisplayGroups() {
showAdsenseAds() {
if (!this.currentUser) {
return true;
}
Expand All @@ -217,21 +217,21 @@ export default AdComponent.extend({

@discourseComputed(
"publisher_id",
"showToDisplayGroups",
"showAdsenseAds",
"showToGroups",
"showAfterPost",
"showOnCurrentPage"
)
showAd(
publisherId,
showToDisplayGroups,
showAdsenseAds,
showToGroups,
showAfterPost,
showOnCurrentPage
) {
return (
publisherId &&
showToDisplayGroups &&
showAdsenseAds &&
showToGroups &&
showAfterPost &&
showOnCurrentPage
Expand Down
8 changes: 4 additions & 4 deletions assets/javascripts/discourse/components/google-dfp-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,23 @@ export default AdComponent.extend({

@discourseComputed(
"publisherId",
"showToDisplayGroups",
"showDfpAds",
"showToGroups",
"showAfterPost",
"showOnCurrentPage",
"size"
)
showAd(
publisherId,
showToDisplayGroups,
showDfpAds,
showToGroups,
showAfterPost,
showOnCurrentPage,
size
) {
return (
publisherId &&
showToDisplayGroups &&
showDfpAds &&
showToGroups &&
showAfterPost &&
showOnCurrentPage &&
Expand All @@ -324,7 +324,7 @@ export default AdComponent.extend({
},

@discourseComputed
showToDisplayGroups() {
showDfpAds() {
if (!this.currentUser) {
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ en:
dfp_publisher_id: "Input your Google Ad Manager (formerly called DFP) network code, which is found in your network settings. NOTE: You will need to update the 'content security policy script src' setting. See <a href='https://meta.discourse.org/t/33734' target='_blank'>this topic</a> for the latest instructions."
dfp_publisher_id_mobile: "(Optional) If you want to use a different Ad Manager publisher id for the mobile version of the site, enter it here. Leave blank to use dfp_publisher_id on mobile."
dfp_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads."
dfp_exclude_groups: "Ads will not be shown to members of these groups"

dfp_topic_list_top_code: "Enter the unique Code of the ad unit to display above topic lists. This is the short code (max 100 chars) given to the ad unit when it was created, not the JavaScript code."
dfp_topic_list_top_ad_sizes: "Choose your ad size for the ad unit above topic lists."
Expand Down Expand Up @@ -47,6 +48,7 @@ en:

adsense_publisher_code: "Your publisher ID. Enter only the number, excluding 'pub-'. NOTE: You will need to update the 'content security policy script src' setting. See <a href='https://meta.discourse.org/t/33734' target='_blank'>this topic</a> for the latest instructions."
adsense_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads."
adsense_exclude_groups: "Ads will not be shown to members of these groups"
adsense_topic_list_top_code: "Enter code of the ad unit to display at topic list top location. This is the number assigned to the ad unit, not the JavaScript code."
adsense_mobile_topic_list_top_code: "Enter code of the ad unit to display mobile ads at topic list top location. This is the number assigned to the ad unit, not the JavaScript code."
adsense_topic_list_top_ad_sizes: "Choose your ad size"
Expand All @@ -66,6 +68,7 @@ en:
adsense_nth_post_code: "Show an ad after every N posts, where N is this value."

amazon_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads."
amazon_exclude_groups: "Ads will not be shown to members of these groups"
amazon_topic_list_top_src_code: "Enter src code to display at topic list top location"
amazon_topic_list_top_ad_width_code: "Input your ad width"
amazon_topic_list_top_ad_height_code: "Input your ad height"
Expand Down Expand Up @@ -95,6 +98,7 @@ en:
carbonads_serve_id: "Your Carbon Ads Serve ID"
carbonads_placement: "Your Carbon Ads Placement"
carbonads_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads."
carbonads_exclude_groups: "Ads will not be shown to members of these groups"
carbonads_topic_list_top_enabled: "Show an ad above the topic list"
carbonads_above_post_stream_enabled: "Show an ad above the post stream"

Expand All @@ -109,4 +113,5 @@ en:
adbutler_topic_above_suggested_zone_id: "Zone ID for topic above suggested location"
adbutler_nth_post: "Show an ad after every N posts, where N is this value"
adbutler_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads"
adbutler_exclude_groups: "Ads will not be shown to members of these groups"
adbutler_adserver_hostname: "The hostname that AdButler is serving your ads from"
35 changes: 35 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ adsense_plugin:
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
hidden: true
adsense_exclude_groups:
default: "3|13|14"
type: group_list
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
adsense_topic_list_top_code:
client: true
default: ""
Expand Down Expand Up @@ -177,6 +184,13 @@ dfp_plugin:
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
hidden: true
dfp_exclude_groups:
default: "3|13|14"
type: group_list
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
dfp_topic_list_top_code:
client: true
default: ""
Expand Down Expand Up @@ -334,6 +348,13 @@ amazon_plugin:
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
hidden: true
amazon_exclude_groups:
default: "3|13|14"
type: group_list
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
amazon_topic_list_top_src_code:
client: true
default: ""
Expand Down Expand Up @@ -430,6 +451,13 @@ carbonads_plugin:
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
hidden: true
carbonads_exclude_groups:
default: "3|13|14"
type: group_list
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
carbonads_topic_list_top_enabled:
client: true
default: false
Expand All @@ -453,6 +481,13 @@ adbutler_plugin:
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
hidden: true
adbutler_exclude_groups:
default: "3|13|14"
type: group_list
allow_any: false
refresh: true
validator: "AtLeastOneGroupValidator"
adbutler_topic_list_top_zone_id:
client: true
default: ""
Expand Down
33 changes: 33 additions & 0 deletions db/migrate/20240208195100_migrate_adsense_to_exclude_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

class MigrateAdsenseToExcludeGroups < ActiveRecord::Migration[7.0]
def up
adsense_display_groups_raw =
DB.query_single("SELECT value FROM site_settings WHERE name = 'adsense_display_groups'").first

if adsense_display_groups_raw.present?
adsense_exclude_groups =
case adsense_display_groups_raw
when "10"
"3|11|12|13|14"
when "10|11"
"3|12|13|14"
when "10|11|12"
"3|13|14"
when "10|11|12|13"
"3|14"
when "10|11|12|14"
"3"
end

DB.exec(<<~SQL, setting: adsense_exclude_groups)
INSERT INTO site_settings(name, value, data_type, created_at, updated_at)
VALUES('adsense_exclude_groups', :setting, '20', NOW(), NOW())
SQL
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
33 changes: 33 additions & 0 deletions db/migrate/20240208195101_migrate_amazon_to_exclude_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

class MigrateAmazonToExcludeGroups < ActiveRecord::Migration[7.0]
def up
amazon_display_groups_raw =
DB.query_single("SELECT value FROM site_settings WHERE name = 'amazon_display_groups'").first

if amazon_display_groups_raw.present?
amazon_exclude_groups =
case amazon_display_groups_raw
when "10"
"3|11|12|13|14"
when "10|11"
"3|12|13|14"
when "10|11|12"
"3|13|14"
when "10|11|12|13"
"3|14"
when "10|11|12|14"
"3"
end

DB.exec(<<~SQL, setting: amazon_exclude_groups)
INSERT INTO site_settings(name, value, data_type, created_at, updated_at)
VALUES('amazon_exclude_groups', :setting, '20', NOW(), NOW())
SQL
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
33 changes: 33 additions & 0 deletions db/migrate/20240208195102_migrate_dfp_to_exclude_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

class MigrateDfpToExcludeGroups < ActiveRecord::Migration[7.0]
def up
dfp_display_groups_raw =
DB.query_single("SELECT value FROM site_settings WHERE name = 'dfp_display_groups'").first

if dfp_display_groups_raw.present?
dfp_exclude_groups =
case dfp_display_groups_raw
when "10"
"3|11|12|13|14"
when "10|11"
"3|12|13|14"
when "10|11|12"
"3|13|14"
when "10|11|12|13"
"3|14"
when "10|11|12|14"
"3"
end

DB.exec(<<~SQL, setting: dfp_exclude_groups)
INSERT INTO site_settings(name, value, data_type, created_at, updated_at)
VALUES('dfp_exclude_groups', :setting, '20', NOW(), NOW())
SQL
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
Loading
Loading