-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes users should not receive ads for a category if the user opted-o…
…ut or from a creative set if a user disliked
- Loading branch information
Showing
14 changed files
with
195 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ative-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h" | ||
|
||
#include "base/strings/stringprintf.h" | ||
#include "bat/ads/internal/bundle/creative_ad_info.h" | ||
#include "bat/ads/internal/client/client.h" | ||
#include "bat/ads/internal/client/preferences/filtered_ad_info.h" | ||
|
||
namespace ads { | ||
|
||
DislikeFrequencyCap::DislikeFrequencyCap() = default; | ||
|
||
DislikeFrequencyCap::~DislikeFrequencyCap() = default; | ||
|
||
bool DislikeFrequencyCap::ShouldExclude(const CreativeAdInfo& ad) { | ||
if (!DoesRespectCap(ad)) { | ||
last_message_ = | ||
base::StringPrintf("creativeSetId %s excluded due to being disliked", | ||
ad.creative_set_id.c_str()); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
std::string DislikeFrequencyCap::get_last_message() const { | ||
return last_message_; | ||
} | ||
|
||
bool DislikeFrequencyCap::DoesRespectCap(const CreativeAdInfo& ad) { | ||
const FilteredAdList filtered_ads = Client::Get()->get_filtered_ads(); | ||
if (filtered_ads.empty()) { | ||
return true; | ||
} | ||
|
||
const auto iter = | ||
std::find_if(filtered_ads.begin(), filtered_ads.end(), | ||
[&ad](const FilteredAdInfo& filtered_ad) { | ||
return filtered_ad.creative_set_id == ad.creative_set_id; | ||
}); | ||
|
||
if (iter == filtered_ads.end()) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace ads |
38 changes: 38 additions & 0 deletions
38
...native-ads/src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_FREQUENCY_CAPPING_EXCLUSION_RULES_DISLIKE_FREQUENCY_CAP_H_ | ||
#define BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_FREQUENCY_CAPPING_EXCLUSION_RULES_DISLIKE_FREQUENCY_CAP_H_ | ||
|
||
#include <string> | ||
|
||
#include "bat/ads/internal/frequency_capping/exclusion_rules/exclusion_rule.h" | ||
|
||
namespace ads { | ||
|
||
struct CreativeAdInfo; | ||
|
||
class DislikeFrequencyCap : public ExclusionRule<CreativeAdInfo> { | ||
public: | ||
DislikeFrequencyCap(); | ||
|
||
~DislikeFrequencyCap() override; | ||
|
||
DislikeFrequencyCap(const DislikeFrequencyCap&) = delete; | ||
DislikeFrequencyCap& operator=(const DislikeFrequencyCap&) = delete; | ||
|
||
bool ShouldExclude(const CreativeAdInfo& ad) override; | ||
|
||
std::string get_last_message() const override; | ||
|
||
private: | ||
std::string last_message_; | ||
|
||
bool DoesRespectCap(const CreativeAdInfo& ad); | ||
}; | ||
|
||
} // namespace ads | ||
|
||
#endif // BRAVE_VENDOR_BAT_NATIVE_ADS_SRC_BAT_ADS_INTERNAL_FREQUENCY_CAPPING_EXCLUSION_RULES_DISLIKE_FREQUENCY_CAP_H_ |
55 changes: 55 additions & 0 deletions
55
.../src/bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ads/internal/frequency_capping/exclusion_rules/dislike_frequency_cap.h" | ||
|
||
#include "bat/ads/internal/unittest_base.h" | ||
#include "bat/ads/internal/unittest_util.h" | ||
|
||
// npm run test -- brave_unit_tests --filter=BatAds* | ||
|
||
namespace ads { | ||
|
||
namespace { | ||
const char kCreativeSetId[] = "654f10df-fbc4-4a92-8d43-2edf73734a60"; | ||
} // namespace | ||
|
||
class BatAdsDislikeFrequencyCapTest : public UnitTestBase { | ||
protected: | ||
BatAdsDislikeFrequencyCapTest() = default; | ||
|
||
~BatAdsDislikeFrequencyCapTest() override = default; | ||
}; | ||
|
||
TEST_F(BatAdsDislikeFrequencyCapTest, AllowAd) { | ||
// Arrange | ||
CreativeAdInfo ad; | ||
ad.creative_set_id = kCreativeSetId; | ||
|
||
// Act | ||
DislikeFrequencyCap frequency_cap; | ||
const bool should_exclude = frequency_cap.ShouldExclude(ad); | ||
|
||
// Assert | ||
EXPECT_FALSE(should_exclude); | ||
} | ||
|
||
TEST_F(BatAdsDislikeFrequencyCapTest, DoNotAllowAd) { | ||
// Arrange | ||
CreativeAdInfo ad; | ||
ad.creative_set_id = kCreativeSetId; | ||
|
||
Client::Get()->ToggleAdThumbDown(ad.creative_instance_id, ad.creative_set_id, | ||
AdContentInfo::LikeAction::kNeutral); | ||
|
||
// Act | ||
DislikeFrequencyCap frequency_cap; | ||
const bool should_exclude = frequency_cap.ShouldExclude(ad); | ||
|
||
// Assert | ||
EXPECT_TRUE(should_exclude); | ||
} | ||
|
||
} // namespace ads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters