Try new placement area for display ads, post_sidebar (#18686)

* Try new placement area for display ads, post_sidebar

* Update cache key for sidebar display ad

* Sidebar display ad should observe permit_adjacent_sponsors

* Change sidebar stickiness to make ad more sticky

* Hide post_sidebar ad when <large

* Remove empty id
This commit is contained in:
Joshua Wehner 2022-11-22 09:55:43 +01:00 committed by GitHub
parent 888c6b93bf
commit 331499e8e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 3 deletions

View file

@ -323,7 +323,7 @@
}
}
.crayons-article-sticky {
.crayons-article-sticky:last-child {
position: -webkit-sticky;
position: sticky;
top: calc(var(--header-height) + var(--layout-padding));
@ -332,6 +332,12 @@
}
}
.crayons-post_sidebar_display_ad {
@media screen and (max-width: $breakpoint-l) {
display: none;
}
}
.user-metadata-details {
li + li {
margin-top: var(--su-3);

View file

@ -112,6 +112,11 @@ class ArticleDecorator < ApplicationDecorator
cached_tag_list_array.include?("discuss") && published_at.to_i > 35.hours.ago.to_i
end
def permit_adjacent_sponsors?
author_ids = [user_id] + co_author_ids
Users::Setting.where(user_id: author_ids).all?(&:permit_adjacent_sponsors)
end
def pinned?
return false unless persisted?

View file

@ -3,10 +3,11 @@ class DisplayAd < ApplicationRecord
acts_as_taggable_on :tags
resourcify
ALLOWED_PLACEMENT_AREAS = %w[sidebar_left sidebar_left_2 sidebar_right post_comments].freeze
ALLOWED_PLACEMENT_AREAS = %w[sidebar_left sidebar_left_2 sidebar_right post_sidebar post_comments].freeze
ALLOWED_PLACEMENT_AREAS_HUMAN_READABLE = ["Sidebar Left (First Position)",
"Sidebar Left (Second Position)",
"Sidebar Right",
"Sidebar Right (Home)",
"Sidebar Right (Individual Post)",
"Below the comment section"].freeze
MAX_TAG_LIST_SIZE = 10

View file

@ -54,3 +54,18 @@
<% end %>
<% end %>
</div>
<%# cache("article-sidebar-content-#{rand(5)}-#{@article.id}-#{user_signed_in?}-#{(@organization || @user).latest_article_updated_at}", expires_in: 15.minutes) do %>
<% sidebar_ad = DisplayAd.for_display("post_sidebar", user_signed_in?, @article.decorate.cached_tag_list_array) %>
<% if @article.permit_adjacent_sponsors? && sidebar_ad %>
<div class="crayons-article-sticky grid gap-4 break-word pt-3">
<div class="crayons-card crayons-card--secondary p-4 crayons-sponsorship-widget crayons-post_sidebar_display_ad text-styles"
data-display-unit data-id="<%= sidebar_ad.id %>"
data-category-click="<%= DisplayAdEvent::CATEGORY_CLICK %>"
data-category-impression="<%= DisplayAdEvent::CATEGORY_IMPRESSION %>"
data-context-type="<%= DisplayAdEvent::CONTEXT_TYPE_HOME %>">
<%= sidebar_ad.processed_html.html_safe %>
</div>
</div>
<% end %>
<%# end %>