Skip to content

Allow customizing Carbon Ads format #249

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions assets/javascripts/discourse/components/ad-slot.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const adConfig = EmberObject.create({
enabledSetting: "carbonads_serve_id",
desktop: {
"topic-list-top": "carbonads_topic_list_top_enabled",
"post-bottom": false,
"post-bottom": "carbonads_post_bottom_enabled",
"topic-above-post-stream": "carbonads_above_post_stream_enabled",
"topic-above-suggested": false,
"topic-above-suggested": "carbonads_above_suggested_enabled",
},
},
"adbutler-ad": {
Expand Down
15 changes: 10 additions & 5 deletions assets/javascripts/discourse/components/carbonads-ad.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ import AdComponent from "./ad-component";
export default class CarbonadsAd extends AdComponent {
serve_id = null;
placement = null;
format = null;

init() {
this.set("serve_id", this.siteSettings.carbonads_serve_id);
this.set("placement", this.siteSettings.carbonads_placement);
this.set("format", this.siteSettings.carbonads_format);
super.init();
}

@discourseComputed("serve_id", "placement")
url(serveId, placement) {
return htmlSafe(
`//cdn.carbonads.com/carbon.js?serve=${serveId}&placement=${placement}`
);
@discourseComputed("serve_id", "placement", "format")
url(serveId, placement, format) {
let baseUrl = `//cdn.carbonads.com/carbon.js?serve=${serveId}&placement=${placement}`;
if (format) {
baseUrl += `&format=${format}`;
}

return htmlSafe(baseUrl);
}

@discourseComputed
Expand Down
12 changes: 6 additions & 6 deletions assets/stylesheets/adplugin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
}
}

#carbonads {
#carbonads:not(#carbon-cover *) {
display: block;
overflow: hidden;
padding: 1em;
Expand All @@ -150,31 +150,31 @@
margin-bottom: 15px;
}

#carbonads span {
#carbonads:not(#carbon-cover *) span {
position: relative;
display: block;
overflow: hidden;
}

.carbon-img {
.carbon-img:not(#carbon-cover *) {
float: left;
margin-right: 1em;
}

.carbon-img img {
.carbon-img:not(#carbon-cover *) img {
display: block;
line-height: 1;
}

.carbon-text {
.carbon-text:not(#carbon-cover *) {
display: block;
float: left;
max-width: calc(100% - 130px - 1em);
text-align: left;
color: var(--primary-med-or-secondary-med);
}

.carbon-poweredby {
.carbon-poweredby:not(#carbon-cover *) {
position: absolute;
right: 0; // You can also set the position to the "left" with the value of calc(130px + carbon-text’s font size). If the font-size is 12px, you’ll want to set the left value as 142px. It’ll align the .carbon-text with .carbon-poweredby
bottom: 0;
Expand Down
3 changes: 3 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ en:

carbonads_serve_id: "Your Carbon Ads Serve ID"
carbonads_placement: "Your Carbon Ads Placement"
carbonads_format: "Your Carbon Ads Format"
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"
carbonads_post_bottom_enabled: "Show an ad above at post bottom"
carbonads_above_suggested_enabled: "Show an ad above the above suggested topics"

adbutler_publisher_id: "AdButler Publisher ID. NOTE: You may 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."
adbutler_mobile_topic_list_top_zone_id: "Zone ID for mobile topic list top location"
Expand Down
14 changes: 14 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ carbonads_plugin:
carbonads_placement:
client: true
default: ""
carbonads_format:
client: true
type: enum
default: "responsive"
allow_any: false
choices:
- responsive
- cover
carbonads_through_trust_level:
client: true
default: 2
Expand All @@ -463,6 +471,12 @@ carbonads_plugin:
carbonads_above_post_stream_enabled:
client: true
default: false
carbonads_post_bottom_enabled:
client: true
default: false
carbonads_above_suggested_enabled:
client: true
default: false

adbutler_plugin:
adbutler_publisher_id:
Expand Down