Skip to content

Commit

Permalink
[ads] Conversions should match up to the set cap, not one less
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Sep 6, 2024
1 parent 5388ecf commit cf07fb9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void FilterCreativeSetConversionBucketsThatExceedTheCap(

for (const auto& [creative_set_id, creative_set_conversion_count] :
creative_set_conversion_counts) {
if (creative_set_conversion_count >= creative_set_conversion_cap) {
if (creative_set_conversion_count > creative_set_conversion_cap) {
creative_set_conversion_buckets.erase(creative_set_id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest,
/*url_pattern=*/"https://foo.com/*",
/*observation_window=*/base::Days(3)); // Bucket #1
creative_set_conversions.push_back(creative_set_conversion_1);
creative_set_conversions.push_back(creative_set_conversion_1);

const CreativeSetConversionInfo creative_set_conversion_2 =
test::BuildCreativeSetConversion(
Expand All @@ -178,9 +179,10 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest,
/*observation_window=*/base::Days(30)); // Bucket #1
creative_set_conversions.push_back(creative_set_conversion_2);
creative_set_conversions.push_back(creative_set_conversion_2);
creative_set_conversions.push_back(creative_set_conversion_2);

const CreativeSetConversionCountMap creative_set_conversion_counts = {
{creative_set_conversion_1.id, 1}, {creative_set_conversion_2.id, 2}};
{creative_set_conversion_1.id, 2}, {creative_set_conversion_2.id, 3}};

CreativeSetConversionBucketMap creative_set_conversion_buckets =
SortCreativeSetConversionsIntoBuckets(creative_set_conversions);
Expand All @@ -193,7 +195,8 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest,
// Assert
const CreativeSetConversionBucketMap
expected_creative_set_conversion_buckets = {
{creative_set_conversion_1.id, {creative_set_conversion_1}}};
{creative_set_conversion_1.id,
{creative_set_conversion_1, creative_set_conversion_1}}};
EXPECT_EQ(expected_creative_set_conversion_buckets,
creative_set_conversion_buckets);
}
Expand All @@ -209,17 +212,19 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest,
/*url_pattern=*/"https://foo.com/*",
/*observation_window=*/base::Days(3)); // Bucket #1
creative_set_conversions.push_back(creative_set_conversion_1);
creative_set_conversions.push_back(creative_set_conversion_1);

const CreativeSetConversionInfo creative_set_conversion_2 =
test::BuildCreativeSetConversion(
/*creative_set_id=*/"4e83a23c-1194-40f8-8fdc-2f38d7ed75c8",
/*url_pattern=*/"https://baz.com/",
/*observation_window=*/base::Days(30)); // Bucket #1
/*observation_window=*/base::Days(30)); // Bucket #2
creative_set_conversions.push_back(creative_set_conversion_2);
creative_set_conversions.push_back(creative_set_conversion_2);
creative_set_conversions.push_back(creative_set_conversion_2);

const CreativeSetConversionCountMap creative_set_conversion_counts = {
{creative_set_conversion_1.id, 1}, {creative_set_conversion_2.id, 2}};
{creative_set_conversion_1.id, 2}, {creative_set_conversion_2.id, 3}};

CreativeSetConversionBucketMap creative_set_conversion_buckets =
SortCreativeSetConversionsIntoBuckets(creative_set_conversions);
Expand All @@ -232,9 +237,11 @@ TEST_F(BraveAdsCreativeSetConversionUtilTest,
// Assert
const CreativeSetConversionBucketMap
expected_creative_set_conversion_buckets = {
{creative_set_conversion_1.id, {creative_set_conversion_1}},
{creative_set_conversion_1.id,
{creative_set_conversion_1, creative_set_conversion_1}},
{creative_set_conversion_2.id,
{creative_set_conversion_2, creative_set_conversion_2}}};
{creative_set_conversion_2, creative_set_conversion_2,
creative_set_conversion_2}}};
EXPECT_EQ(expected_creative_set_conversion_buckets,
creative_set_conversion_buckets);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ void Conversions::CheckForConversions(
}
const auto& [creative_set_id, creative_set_conversion_bucket] = *iter;

// Have we exceeded the limit for creative set conversions?
if (creative_set_conversion_cap > 0 &&
creative_set_conversion_counts[creative_set_id] ==
creative_set_conversion_cap) {
continue;
}

// Yes, so are we allowed to convert this ad event?
if (!IsAllowedToConvertAdEvent(ad_event)) {
// No, so skip this ad event.
Expand All @@ -178,13 +185,8 @@ void Conversions::CheckForConversions(
did_convert = true;

// Have we exceeded the limit for creative set conversions?
if (creative_set_conversion_cap == 0) {
// There is no limit, so continue converting.
continue;
}

++creative_set_conversion_counts[creative_set_id];
if (creative_set_conversion_counts[creative_set_id] >=
if (creative_set_conversion_counts[creative_set_id] ==
creative_set_conversion_cap) {
// Yes, so stop converting.
break;
Expand Down

0 comments on commit cf07fb9

Please sign in to comment.