Allow customizing Carbon Ads format

Carbon Ads now supports a new Cover format, which can be forced using an extra query parameter.
This commit is contained in:
Diego Barreiro Perez 2025-07-03 00:44:15 +01:00
parent fcd734079b
commit 9c6c880b1d
No known key found for this signature in database
GPG Key ID: F5A0D63FF3B48BF9
3 changed files with 17 additions and 5 deletions

View File

@ -5,18 +5,23 @@ import AdComponent from "./ad-component";
export default class CarbonadsAd extends AdComponent { export default class CarbonadsAd extends AdComponent {
serve_id = null; serve_id = null;
placement = null; placement = null;
format = null;
init() { init() {
this.set("serve_id", this.siteSettings.carbonads_serve_id); this.set("serve_id", this.siteSettings.carbonads_serve_id);
this.set("placement", this.siteSettings.carbonads_placement); this.set("placement", this.siteSettings.carbonads_placement);
this.set("format", this.siteSettings.carbonads_format);
super.init(); super.init();
} }
@discourseComputed("serve_id", "placement") @discourseComputed("serve_id", "placement", "format")
url(serveId, placement) { url(serveId, placement, format) {
return htmlSafe( let baseUrl = `//cdn.carbonads.com/carbon.js?serve=${serveId}&placement=${placement}`;
`//cdn.carbonads.com/carbon.js?serve=${serveId}&placement=${placement}` if (format) {
); baseUrl += `&format=${format}`;
}
return htmlSafe(baseUrl);
} }
@discourseComputed @discourseComputed

View File

@ -97,6 +97,7 @@ en:
carbonads_serve_id: "Your Carbon Ads Serve ID" carbonads_serve_id: "Your Carbon Ads Serve ID"
carbonads_placement: "Your Carbon Ads Placement" 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_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_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_topic_list_top_enabled: "Show an ad above the topic list"

View File

@ -438,6 +438,12 @@ carbonads_plugin:
carbonads_placement: carbonads_placement:
client: true client: true
default: "" default: ""
carbonads_format:
client: true
default: "responsive"
choices:
- responsive
- cover
carbonads_through_trust_level: carbonads_through_trust_level:
client: true client: true
default: 2 default: 2