Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not show the same ad more than once every hour #3296

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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