Skip to content

Commit 0accdb6

Browse files
committed
fix(shared): enhance ad placement accuracy in mixed content feeds
- Improve documentation for better understanding of ad placement logic - Include decorators in content item count for accurate ad spacing - Exclude ad placeholders from content item count to prevent double counting - Update content item types to include CallToActionItem and ContentCollectionItem
1 parent fd1cefe commit 0accdb6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/shared/services/feed_decorator_service.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ class FeedDecoratorService {
392392
/// This method ensures that ad placeholders for *inline* ads (native and banner)
393393
/// are placed according to the `adPlacementInterval` (initial buffer before
394394
/// the first ad) and `adFrequency` (subsequent ad spacing). It correctly
395-
/// accounts for content items only, ignoring previously injected decorators
396-
/// when calculating placement. Interstitial ads are not handled here.
395+
/// accounts for content items and decorators, ignoring previously injected
396+
/// ad placeholders when calculating placement.
397397
///
398398
/// [feedItems]: The list of feed items (headlines, other decorators)
399399
/// to inject ad placeholders into.
@@ -452,8 +452,8 @@ class FeedDecoratorService {
452452

453453
final result = <FeedItem>[];
454454
// This counter tracks the absolute number of *content items* (headlines,
455-
// topics, sources, countries) processed so far, including those from
456-
// previous pages. This is key for accurate ad placement.
455+
// topics, sources, countries, and decorators) processed so far, including
456+
// those from previous pages. This is key for accurate ad placement.
457457
var currentContentItemCount = processedContentItemCount;
458458

459459
// Get the primary ad platform and its identifiers
@@ -475,12 +475,15 @@ class FeedDecoratorService {
475475
result.add(item);
476476

477477
// Only increment the content item counter if the current item is
478-
// a primary content type (not an ad or a decorator).
479-
// This ensures ad placement is based purely on content density.
478+
// a primary content type or a decorator (not an ad placeholder).
479+
// This ensures ad placement is based purely on content/decorator density.
480480
if (item is Headline ||
481481
item is Topic ||
482482
item is Source ||
483-
item is Country) {
483+
item is Country ||
484+
item is CallToActionItem ||
485+
item is ContentCollectionItem
486+
) {
484487
currentContentItemCount++;
485488
}
486489

0 commit comments

Comments
 (0)