Skip to content

Commit

Permalink
Do not show the same ad more than once every hour
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Sep 3, 2019
1 parent d225260 commit 5e7b4fa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
44 changes: 38 additions & 6 deletions vendor/bat-native-ads/src/bat/ads/internal/ads_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -959,34 +959,43 @@ std::vector<AdInfo> AdsImpl::GetEligibleAds(
for (const auto& ad : ads) {
if (!AdRespectsTotalMaxFrequencyCapping(ad)) {
BLOG(WARNING) << "creativeSetId " << ad.creative_set_id
<< " has exceeded the totalMax";
<< " has exceeded the frequency capping for totalMax";

continue;
}

if (!AdRespectsPerHourFrequencyCapping(ad)) {
BLOG(WARNING) << "adUUID " << ad.uuid
<< " has exceeded the frequency capping for perHour";

continue;
}

if (!AdRespectsPerDayFrequencyCapping(ad)) {
BLOG(WARNING) << "creativeSetId " << ad.creative_set_id
<< " has exceeded the perDay";
<< " has exceeded the frequency capping for perDay";

continue;
}

if (!AdRespectsDailyCapFrequencyCapping(ad)) {
BLOG(WARNING) << "creativeSetId " << ad.creative_set_id
<< " has exceeded the dailyCap";
BLOG(WARNING) << "campaignId " << ad.campaign_id
<< " has exceeded the frequency capping for dailyCap";

continue;
}

if (client_->IsFilteredAd(ad.creative_set_id)) {
BLOG(WARNING) << "creativeSetId " << ad.creative_set_id
<< " appears in filtered ads list";
<< " appears in the filtered ads list";

continue;
}

if (client_->IsFlaggedAd(ad.creative_set_id)) {
BLOG(WARNING) << "creativeSetId " << ad.creative_set_id
<< " appears in flagged ads list";
<< " appears in the flagged ads list";

continue;
}

Expand All @@ -1006,6 +1015,15 @@ bool AdsImpl::AdRespectsTotalMaxFrequencyCapping(
return true;
}

bool AdsImpl::AdRespectsPerHourFrequencyCapping(
const AdInfo& ad) {
auto ads_shown = GetAdsShownForId(ad.uuid);
auto hour_window = base::Time::kSecondsPerHour;

return HistoryRespectsRollingTimeConstraint(
ads_shown, hour_window, 1);
}

bool AdsImpl::AdRespectsPerDayFrequencyCapping(
const AdInfo& ad) {
auto creative_set = GetCreativeSetForId(ad.creative_set_id);
Expand All @@ -1024,6 +1042,20 @@ bool AdsImpl::AdRespectsDailyCapFrequencyCapping(
campaign, day_window, ad.daily_cap);
}

std::deque<uint64_t> AdsImpl::GetAdsShownForId(
const std::string& id) {
std::deque<uint64_t> ads_shown = {};

auto ads_shown_history = client_->GetAdsShownHistory();
for (const auto& ad_shown : ads_shown_history) {
if (ad_shown.ad_content.uuid == id) {
ads_shown.push_back(ad_shown.timestamp_in_seconds);
}
}

return ads_shown;
}

std::deque<uint64_t> AdsImpl::GetCreativeSetForId(
const std::string& id) {
std::deque<uint64_t> creative_set = {};
Expand Down
6 changes: 6 additions & 0 deletions vendor/bat-native-ads/src/bat/ads/internal/ads_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,20 @@ class AdsImpl : public Ads {

bool AdRespectsTotalMaxFrequencyCapping(
const AdInfo& ad);
bool AdRespectsPerHourFrequencyCapping(
const AdInfo& ad);
bool AdRespectsPerDayFrequencyCapping(
const AdInfo& ad);
bool AdRespectsDailyCapFrequencyCapping(
const AdInfo& ad);

std::deque<uint64_t> GetAdsShownForId(
const std::string& id);
std::deque<uint64_t> GetCreativeSetForId(
const std::string& id);
std::deque<uint64_t> GetCampaignForId(
const std::string& id);

bool IsAdValid(
const AdInfo& ad_info);
NotificationInfo last_shown_notification_info_;
Expand Down

0 comments on commit 5e7b4fa

Please sign in to comment.