Skip to content

Commit

Permalink
Try new placement area for display ads, post_sidebar (forem#18686)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jaw6 authored Nov 22, 2022
1 parent 888c6b9 commit 331499e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/assets/stylesheets/views/article.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions app/decorators/article_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def discussion?
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?

Expand Down
5 changes: 3 additions & 2 deletions app/models/display_ad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions app/views/articles/_sticky_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

0 comments on commit 331499e

Please sign in to comment.