## Overview

Ad pacing - or goals - refers to the automatic balancing of impressions for a Flight or Ad so that the campaign hits a desired metric over the course of its lifetime.

For instance, if you've negotiated a 30M impression deal with an advertiser over the month of June, Kevel's Ad Decision Engine will show the ad for 30M impressions over 30 days and throttle the campaign so that it shows the ads evenly each day, or ~1M impressions a day.

This is an automated, constantly-updating feature that helps ensure your advertisers hit their goals.

### Notes

Kevel's pacing algorithm will attempt to deliver 100% of goal over the desired time period. The actual goal achieved can vary by +-5%, due to varying amounts of request traffic. Also, please bear in mind that very small goals, eg, $10 Revenue or 100 clicks can exceed goal by a large percentage during high traffic scenarios.

Ad Goals are different from Ad Caps. You use Ad Goals to pace ads evenly over time. It involves complex logic and intra-day adjustments. Ad Caps, on the other hand, don't use logic. They'll just turn off an ad if it hits the cap.

## What You Can Pace Against

You set Goals at the Flight level. For more information on how to set them, click [here](https://dev.kevel.co/docs/flights#section-goals).

For Goal Type, you can choose between **Impressions**, **Clicks**, **Conversions**, **Percentage**, **Revenue**, and **Daily Revenue**.

Flights set to auction bidding can also pace by **Daily Revenue** and **Lifetime Revenue**.

## Auto-Balancing

Auto-balancing is the process of dynamically reallocating a flight's goal among the ads within a flight. Ads in a flight will use the overall flight goal to determine whether or not they should continue serving. For example, given a flight with 3 ads and an impression goal of 1000 impressions, all 3 ads have an opportunity to serve throughout the lifetime of the flight. If for example 2 out of the 3 ads included additional targeting that limited their eligibility for selection, the 3rd ad without additional ad level targeting could pick up the slack to avoid potential under delivery that would occur due to the additional eligibility restrictions caused by ad level targets.

By default, every new ad you create in a flight uses auto-balancing. You can also [change the ad distribution settings](https://dev.kevel.co/docs/ads#general-settings-of-an-ad).

### Important

Auto-balance is **only** applicable if utilizing legacy ad weights. Reach out to the Kevel Customer Success team for more details about your network's pacing setup.

## Percentage Goal Behavior

Percentage goals allow you to directly set the **weight** of the ads in a flight. The weight in a lottery priority is "how many lottery balls" in the lottery a given ad has. The more lottery balls the ad has, the more likely it will be served in a decision. Each lottery priority contains its own set of lottery balls.

Other goal types like Impressions, Clicks, Daily Revenue, etc. use adjustments in the engine to set and reset the weight of ads. These adjustments happen behind the scenes to keep the ads on target to meet their performance goals (like a certain amount of clicks) by their end date.

Percentage goals use no such adjustments. The percentage goal directly translates to the weight of the ad. This is useful if you have no performance targets, if you want to regulate the pacing of flights manually, or if you want an even distribution of flights in the lottery priority.

For example:

- Setting three flights in a priority with a goal of Percentage:100 will give these flights an equal number of lottery balls in the lottery.
- Setting a single flight in a priority with a goal of Percentage:50 will give the flight 50% of the lottery balls it needs to be eligible for every decision. This means that in 50% of lotteries the decision will fall through to the next priority.
- Setting two flights in a priority with Percentage:100 and one flight with Percentage:200 will cause the latter flight to serve twice as often as the former flights since it has double the weight (lottery balls). This translates to the latter flight eligible for 50% of decisions in the priority and the former two eligible for 25% each.

Bear in mind that targeting, capping, etc. influence selections in a lottery priority beyond percentage goals. Therefore, percentage goals will not necessarily translate into the percentage of flights served in a priority.

Percentage goals behave somewhat differently depending on priority type:

| Priority Type | Percentage Goal Behavior |
| --- | --- |
| Lottery | The goal translates directly to weight (number of lottery balls) |
| Auction | The goal is the probability the ad will bid in the auction |

## Revenue Goals

Revenue goals are a goal type that balances the impressions a flight or ad serves so that it earns a specific amount of revenue either by its End Date (lifetime) or per day.

There are two types of revenue goals:

- **Lifetime Revenue goals:** Sets the amount of revenue a flight or ad should earn before its End Date. (Note that an End Date is required to use lifetime goals.)
- **Daily Revenue goals:** Sets the amount of revenue a flight or ad should earn per one day in the time zone of the flight (or UTC if no time zone is set). A daily budget goal resets at midnight.

## When To Use Revenue Goals vs. Daily Revenue

If your flight has a fixed budget over a fixed period, we recommend using a Revenue Goal with an End Date. (You can additionally limit how much revenue that flight should generate per day by applying a daily Budget Cap.)

You should use a Daily Revenue goal if your flight needs to serve indefinitely and you expect it to generate roughly the same amount of revenue per day. We recommend using the Daily Revenue goal type _without_ an End Date. If you need to limit the total budget of the flight, we recommend applying a lifetime Budget Cap instead.

| Condition | Recommended Goal |
| --- | --- |
| Fixed budget | Revenue |
| Fixed time period (has an End Date) | Revenue |
| No fixed time period | Daily Revenue |
| No fixed budget | Daily Revenue |

## How Daily Revenue Goals Work

Unlike other goal types, Daily Revenue goals are _day-based_ - instead of balancing ads in order to achieve a lifetime goal, we balance them to achieve a daily goal. We do this by calculating the total revenue the daily goal will generate per _calendar month_ and then pacing the ad to hit the daily goal on each day of that month.

### Note

Months are used because End Dates are optional, Daily Revenue goals use months to prevent daily over-serving or under-serving. Months have varying numbers of days, so not every month's total revenue will be the same.

The Daily Revenue goal amount is calculated by determining the accrued revenue to date and adding this to the days remaining in the month multiplied by the current daily revenue goal.

Max revenue calculation

```text
(the accrued revenue to date) + (days remaining in the month * current daily revenue goal)
```

### Caution

Daily Budget Caps do not work properly with Daily Revenue Goals because the flight is already effectively capped per day. Instead, consider using a Revenue Goal with Daily Budget Caps if you need a hard cutoff of revenue per day.

## Setting Up Budget Goals - API

## On the Flight Level

When [Creating a Flight](https://dev.kevel.co/docs/flights) with the [Create Flight](https://dev.kevel.co/v1.0/reference/flight#create-flight) endpoint, make sure to:

1. Set `GoalType` to 8 or 9. `8 = Lifetime Revenue` and `9 = Daily Revenue`
2. Set `Impressions` to the target budget

### Caution

While the field is referred to `impressions`, this is the correct field to use for any budget goal amounts.

## On the Ad Level

When [Creating/Editing an Ad](https://dev.kevel.co/docs/ads) with the [Create Ads](https://dev.kevel.co/v1.0/reference/creative-flight-map#create-ads) endpoint, make sure to:

1. Set `GoalType` to 8 or 9. `8 = Lifetime Revenue` and `9 = Daily Revenue`
2. Set `Goal` to the target budget

## Setting Up Budget Goals - UI

## On the Flight Level:

1. Create a new [Flight](https://dev.kevel.co/docs/flights)
2. In the Goal Type dropdown, choose either "Revenue" or "Daily Revenue"
3. In the Goal field, enter the budget goal (in dollars)
4. Save

## On the Ad Level:

1. Add a New [Creative/Ad](https://dev.kevel.co/docs/ads)
2. In the Distribution dropdown under "Delivery Settings", select "Override"
3. In the Goal Type dropdown, choose either "Revenue" or "Daily Revenue"
4. In the Goal field, enter the budget goal (in dollars)
5. Save

## Budget Goal Behavior Explained In-Depth

### Note

This is a detailed description of how budget goal weights are calculated in Kevel. As a deep dive into the ad selection process, this page is useful for understanding the design of budget goals and for troubleshooting delivery issues at an advanced level.

Budget goals add capabilities to the ad server engines to support optimal allocation of inventory in auction priorities. Optimal allocation includes the following:

1. **Ads can have goals** — inventory is allocated to the ad over time between its start and end dates such that revenue is generated as smoothly and evenly as possible with the ad reaching its goal amount just as it reaches its end date.
2. **When supply exceeds demand, all demand is filled** — ads will not compete for impressions (and consequently will be priced at the floor price) when there are more than enough impressions available to fill the demand.
3. **Competition between ads in auctions ramps up smoothly when demand exceeds supply** — competition only occurs when multiple ads want the same impression _at the same time_ to meet their goal. This generally means that the pacing needs of the ads will determine how often they compete against each other in auctions.

## Balancing and Pacing

Goals provide a mechanism by which the rate at which ads serve is continually regulated and adjusted in order to achieve some set number of impressions, clicks, conversions, or ad spend over the lifetime of the ad. The optimal rate is such that the ad serves as evenly as possible over time, taking into account variations in inventory, CTR, effective CPM, and other considerations.

Two concepts work together to regulate the rate at which an ad will serve:

- **pacing** — Engines employ probabilistic methods to regulate the rate at which ads will serve relative to each other within the constraints of the targeting rules and available inventory. The system is designed such that each ad is associated with a weighting parameter and the probability that an ad will serve for any individual request is proportional to its weight.
- **balancing** — Both real-time and historical performance of ads is continuously monitored. This information is used to adjust the ad weightings while the ads are serving so they maintain the optimal rates to achieve their goals.

Note that pacing is essentially a rate-limiting function. Since engines can not serve more impressions than the available inventory allows, the only way it can regulate the pace is by limiting how fast ads serve. Dynamic behavior is the result of feedback in the balancing/pacing loop.

For example:

- Consider a priority with three ads, _A_, _B_, and _C_.
- Suppose _A_ starts to fall behind — it needs to serve impressions faster to achieve its goal.
- The balancer is monitoring _A_'s (and all the other ads) performance, and it decides to increase _A_'s weighting so it can serve at a faster rate to catch up.
- The engines need to allocate inventory to _A_, _B_, and _C_, in ratios proportional to their weights. Since _A_'s weight was bumped up it will serve faster (and _B_ and _C_ will serve more slowly).
- After a while one of two things usually happens: either _A_ begins to overshoot its goal or one (or both) of the other ads will begin to fall behind. In the first case _A_'s weight is reduced and in the second case the other ad's weight is increased.
- This, in turn, causes _A_ to serve more slowly, and the cycle repeats.

## Lotteries

Lotteries are an important part of the probabilistic model the engines use to set the rate at which ads serve. In combination with the balancing weights they are an effective tool for portioning out available inventory to multiple ads in a priority such that each ad gets a fair proportion of the available impressions.

The simplest case is the "Lottery Priority", where each ad in the priority gets some percentage of the total available inventory, proportional to its weight.

In this type of lottery only a single ad "wins"; ads do not compete in auctions against each other.

The lottery priority is conceptually simple: each ad is assigned a number of lottery balls, according to its weighting. When all ads have been assigned the correct number of balls the balls are thrown into a sack, and a random ball is selected. Whichever ad was assigned that ball wins the lottery.

```undefined
A: weight = 3
B: weight = 4
C: weight = 5

Total number of balls: 3 + 4 + 5 = 12

Lottery:   1   2   3   4   5   6   7   8   9  10  11  12
         +---+---+---+---+---+---+---+---+---+---+---+---+
         | A | A | A | B | B | B | B | C | C | C | C | C |
         +---+---+---+---+---+---+---+---+---+---+---+---+
                                       |
+--------------------------------------+
|
X = a random number between 1 and 12 (say 8). C is the winner!
```

It is easy to see that the probability that a given ad will serve is proportional to its weight, and since the winner is chosen randomly all ads in the lottery will get their share of inventory over time.

However, the above example is slightly misleading, because it would imply that a lottery priority will _always_ select a winner, which would be problematic in situations where inventory exceeds demand — ads would overshoot their goals. To address this issue there is a maximum or reference weighting against which individual ad weightings are scaled.

So in the situation where supply is greater than demand:

```undefined
A: weight = 1
B: weight = 2
C: weight = 3

Max Wt. = total number of balls = 12

Lottery:   1   2   3   4   5   6   7   8   9  10  11  12
         +---+---+---+---+---+---+---+---+---+---+---+---+
         | A | B | B | C | C | C |   |   |   |   |   |   |
         +---+---+---+---+---+---+---+---+---+---+---+---+
                                       |
+--------------------------------------+
|
X = a random number between 1 and 12 (say 8). There is no winner!
```

And, conversely, when demand is greater than supply:

```undefined
A: weight =  4
B: weight =  8
C: weight = 12

Max Wt. = total number of balls = 12

Scaling factor = number of balls / sum of weights = 12 / 24 = 1/2

A: scaled weight =  4 / 2 = 2
B: scaled weight =  8 / 2 = 4
C: scaled weight = 12 / 2 = 6

Lottery:   1   2   3   4   5   6   7   8   9  10  11  12
         +---+---+---+---+---+---+---+---+---+---+---+---+
         | A | A | B | B | B | B | C | C | C | C | C | C |
         +---+---+---+---+---+---+---+---+---+---+---+---+
                                       |
+--------------------------------------+
|
X = a random number between 1 and 12 (say 8). C is the winner!
```

This scaling behavior suggests an interpretation of the ad weightings: weights are between zero and max weight, and `weight / max weight` is the proportional to the probability that the ad will serve for a given impression.

In the previous example _A_'s weight of 4 implies that it wants 1/3 of all available inventory, _B_'s weight is 8 corresponds to 2/3, and _C_'s weight of 12 corresponds to all available inventory. Since there is a maximum of 100% to distribute among the three ads in the priority we scale them down proportionally, so they each get their fair share of the limited number of available impressions.

## Paced and Balanced Auctions

In the example above only a single ad may win a given lottery drawing, even if demand exceeds supply. Paced auctions require multiple ads to compete for inventory in this case, but still retain the ability to accurately pace ads so they achieve their goals optimally.

This is accomplished by adding a modified lottery drawing before the auction takes place. The objective of this pre-auction lottery is to select the ads that will be allowed to bid in the auction. Then the auction determines which ad wins the impression.

The concepts of _weighting_ and _max weight_ are carried over to this new type of lottery, but when demand is greater than the available inventory the weights are not scaled down as they were in the above example. Instead, a series of lotteries are conducted, with a possible winner for each one. The rules of the lottery are designed such that there is at least one winner across all of the lotteries whenever demand meets or exceeds supply.

Since the mechanics of the modified lottery are the same as the simple lottery when supply meets or exceeds demand, consider the last example above, where the demand is 2x supply (that is to say, the ads require twice as many impressions per second to reach their pacing goals than are currently available in their priority):

```undefined
A: weight =  4
B: weight =  8
C: weight = 12
```

First, the ads are shuffled to obtain a random ordering, say _B_, _C_, _A_, and each ad is assigned lottery balls according to its weight. So _A_ gets 4 balls, _B_ gets 8, and so on. The first lottery is constructed by loading balls from each ad into available slots in order, and a winner is selected:

```undefined
Lottery:   1   2   3   4   5   6   7   8   9  10  11  12
         +---+---+---+---+---+---+---+---+---+---+---+---+
         | B | B | B | B | B | B | B | B | C | C | C | C | All of C's balls
         +---+---+---+---+---+---+---+---+---+---+---+---+ don't fit!
         +------------------+
|
X = a random number between 1 and 12 (say 3). B is the winner!
```

So _B_ won the first lottery, and _C_ lost. But _C_ only got to play 4 of the 12 balls it was assigned! In this case we allow _C_ to play its remaining balls in the next lottery.

However, allowing _C_ to play in two lotteries changes the odds. It turns out that splitting _C_'s balls between two lotteries yields a slightly lower probability that _C_ will win _a_ lottery than if it were able to play all of its balls in a single lottery. To correct this we add an adjustment — the number of balls _C_ can play in the next lottery is prorated such that the total probability is preserved.

The prorated probability for the second lottery is given by:

```undefined
y = (p - x) / (1 - x)
```

where _y_ is the prorated probability, _x_ was the probability of winning the first lottery, and _p_ is the original probability corresponding to the ad's weight.

A second lottery is now constructed, with _C_'s remaining balls (plus the adjustment which works out to 4 extra balls, for a total of 12), and as many of _A_'s balls as there are available slots:

```undefined
Lottery:   1   2   3   4   5   6   7   8   9  10  11  12
         +---+---+---+---+---+---+---+---+---+---+---+---+
         | C | C | C | C | C | C | C | C | C | C | C | C | No slots left for A!
         +---+---+---+---+---+---+---+---+---+---+---+---+
                                           |
+------------------------------------------+
|
X = a random number between 1 and 12 (say 9). C is the winner!
```

So _C_ won this lottery, but again, _A_ didn't get to play, so a third lottery is constructed. In this lottery _A_ plays its 4 balls:

```undefined
Lottery:   1   2   3   4   5   6   7   8   9  10  11  12
         +---+---+---+---+---+---+---+---+---+---+---+---+
         | A | A | A | A |   |   |   |   |   |   |   |   |
         +---+---+---+---+---+---+---+---+---+---+---+---+
                           |
+--------------------------+
|
X = a random number between 1 and 12 (say 5). There is no winner!
```

Now there are no more balls to play, so the lottery series is complete. The winners, _B_ and _C_, move on to the auction phase, where they must bid against each other to win the impression, and the winner will pay the second-price amount.

## What to Expect

First of all, keep in mind that balancing is a continuous process, so ad weights will be updating frequently to ensure that ads continue to serve at their optimal rates through the ebb and flow of inventory and demand levels.

To get a feel for how paced and balanced auctions will behave, consider the range of possible outcomes in the previous example. In the example, _B_ and _C_ were ultimately chosen, but it could have been _A_ and _C_, or _A_, _B_, and _C_ if the lotteries had gone a different way.

- **Why is _C_ a winner in every outcome?** _C_ always makes it through the lottery selection process because it has the maximum weight; it wants every available impression. Thus, it is sure to win one of the lotteries in the series, and consequently always places a bid in every auction.
- **How likely is it for _C_ to bid against _A_, and/or _B_?** Since _A_'s weight is 4, we expect it to win one lottery in the series about 4/12, or 33% of the time. Likewise, since _B_'s weight is 8, we expect it to win a lottery about 8/12 or 66% of the time. Whenever _A_ and/or _B_ can win one of the lotteries in the series they may place a bid in the auction.
- **Why does _C_ sometimes bid against _A_, sometimes against _B_ and sometimes both _A_ and _B_?** It works out this way because both _A_ and _B_ want _some_ inventory, and since _C_ wants it all they must bid against _C_ in the auction to get their share. You can expect auctions with two ads to occur more often than auctions with all three ads.
- **What range of effective CPM do we expect?** The different ads in the auctions determine the eCPM of the winner if the priority uses second-pricing rules. So if _C_ bids $1.00 CPM, _B_ bids $0.75, and _A_ bids $0.50, for example, _C_ might end up with an effective CPM in the neighborhood of $0.68 or so, because it will win every auction at either $0.76 or $0.51 CPM, depending on whether it's bidding against _A_ or _B_.
