1. Introduction
This section is non-normative
The Protected Audience API facilitates selecting an advertisement to display to a user based on a previous interaction with the advertiser or advertising network.
When
a
user’s
interactions
with
an
advertiser
indicate
an
interest
in
something,
the
advertiser
can
ask
the
browser
to
record
this
interest
on-device
by
calling
navigator
.
joinAdInterestGroup()
.
Later,
when
a
website
wants
to
select
an
advertisement
to
show
to
the
user,
the
website
can
call
navigator
.
runAdAuction()
to
ask
the
browser
to
conduct
an
auction
where
each
of
these
on-device
recorded
interests
are
given
the
chance
to
calculate
a
bid
to
display
their
advertisement.
2. Joining Interest Groups
When
a
user’s
interactions
with
a
website
indicate
that
the
user
may
have
a
particular
interest,
an
advertiser
or
someone
working
on
behalf
of
the
advertiser
(e.g.
a
demand
side
platform,
DSP)
can
ask
the
user’s
browser
to
record
this
interest
on-device
by
calling
navigator
.
joinAdInterestGroup()
.
This
indicates
an
intent
to
display
an
advertisement
relevant
to
this
interest
to
this
user
in
the
future.
The
user
agent
has
an
interest
group
set
,
a
list
of
interest
groups
in
which
owner
/
name
pairs
are
unique.
[SecureContext ]partial interface Navigator {Promise <undefined >joinAdInterestGroup (AuctionAdInterestGroup ,group double ); };durationSeconds dictionary {AuctionAd required USVString ;renderURL any ; };metadata dictionary {AuctionAdInterestGroup required USVString ;owner required USVString ;name double = 0.0;priority boolean =enableBiddingSignalsPrioritization false ;record <DOMString ,double >;priorityVector record <DOMString ,double >;prioritySignalsOverrides DOMString = "compatibility";executionMode USVString ;biddingLogicURL USVString ;biddingWasmHelperURL USVString ;updateURL USVString ;trustedBiddingSignalsURL sequence <USVString >;trustedBiddingSignalsKeys any ;userBiddingSignals sequence <AuctionAd >;ads sequence <AuctionAd >; };adComponents
The
joinAdInterestGroup(
group
,
durationSeconds
)
method
steps
are:
-
If this 's relevant global object 's associated Document is not allowed to use the " join-ad-interest-group " policy-controlled feature , then throw a "
NotAllowedError"DOMException. -
Let frameOrigin be the relevant settings object 's origin .
-
Assert that frameOrigin is not an opaque origin and its scheme is "https".
-
Let interestGroup be a new interest group .
-
Validate the given group and set interestGroup ’s fields accordingly.
-
Set interestGroup ’s expiry to now plus durationSeconds .
-
Set interestGroup ’s next update after to now plus 24 hours.
-
Set interestGroup ’s owner to the result of parsing an origin on group ["
owner"]. -
If interestGroup ’s owner is an error, or its scheme is not "
https", throw aTypeError. -
Set interestGroup ’s enable bidding signals prioritization to group ["
enableBiddingSignalsPrioritization"]. -
If group ["
priorityVector"] exists , then set interestGroup ’s priority vector to group ["priorityVector"]. -
If group ["
prioritySignalsOverrides"] exists , then set interestGroup ’s priority signals overrides to group ["prioritySignalsOverrides"]. -
Set interestGroup ’s execution mode to group ["
executionMode"]. -
For each groupMember and interestGroupField in the following table
Group member Interest group field " biddingLogicURL"bidding url " biddingWasmHelperURL"bidding wasm helper url " updateURL"update url " trustedBiddingSignalsURL"trusted bidding signals url -
If group contains groupMember :
-
Let parsedUrl be the result of running the URL parser on group [ groupMember ].
-
Throw a
TypeErrorif any of the following conditions hold:-
parsedUrl is an error;
-
parsedUrl is not same origin with interestGroup ’s owner ;
-
parsedUrl includes credentials ;
-
parsedUrl fragment is not null.
-
-
Set interestGroup ’s interestGroupField to parsedUrl .
-
-
-
If interestGroup ’s trusted bidding signals url 's query is not null, then throw a
TypeError. -
If group ["
trustedBiddingSignalsKeys"] exists , then set interestGroup ’s trusted bidding signals keys to group ["trustedBiddingSignalsKeys"]. -
If group ["
userBiddingSignals"] exists :-
Let interestGroup ’s user bidding signals be the result of serializing a JavaScript value to a JSON string , given group ["
userBiddingSignals"]. This can throw aTypeError.
-
-
For each groupMember and interestGroupField in the following table
Group member Interest group field " ads"ads " adComponents"ad components -
For each ad of group [ groupMember ]:
-
Let igAd be a new interest group ad .
-
Let renderURL be the result of running the URL parser on ad ["
renderURL"]. -
Throw a
TypeErrorif any of the following conditions hold:-
renderURL is an error;
-
renderURL scheme is not "
https"; -
renderURL includes credentials .
-
-
Set igAd ’s render url to renderURL .
-
If ad ["
metadata"] exists , then let igAd ’s metadata be the result of serializing a JavaScript value to a JSON string , given ad ["metadata"]. This can throw aTypeError. -
Append igAd to interestGroup ’s interestGroupField .
-
-
-
-
If interestGroup ’s estimated size is greater than 50 KB, then throw a
TypeError. -
Let p be a new promise .
-
Let queue be the result of starting a new parallel queue .
-
Enqueue the following steps to queue :
-
Let permission be the result of checking interest group permissions with interestGroup ’s owner , frameOrigin , and true.
-
If permission is false, then queue a task to reject p with a "
NotAllowedError"DOMExceptionand do not run the remaining steps. -
Queue a task to resolve p with
undefined. -
If the browser is currently storing an interest group with
ownerandnamethat matches interestGroup , then set the bid counts , join counts , and previous wins of interestGroup to the values of the currently stored one and remove the currently stored one from the browser. -
Set interestGroup ’s joining origin to this 's relevant settings object 's top-level origin .
-
If the most recent entry in join counts corresponds to the current local day, increment its count. If not, insert a new entry with the time set to the current local day and a count of 1.
-
Store interestGroup in the browser’s interest group set .
-
-
Return p .
The estimated size of an interest group ig is the sum of:
-
The length of the serialization of ig ’s owner .
-
8 bytes, which is the size of ig ’s priority .
-
The length of ig ’s execution mode .
-
2 bytes, which is the size of ig ’s enable bidding signals prioritization .
-
If ig ’s priority vector is not null, for each key → value of priority vector :
-
The length of key .
-
8 bytes, which is the size of value .
-
-
If ig ’s priority signals overrides is not null, for each key → value of priority signals overrides :
-
The length of key .
-
8 bytes, which is the size of value .
-
-
The size of execution mode .
-
The length of the serialization of ig ’s bidding url , if the field is not null.
-
The length of the serialization of ig ’s bidding wasm helper url , if the field is not null.
-
The length of the serialization of ig ’s update url , if the field is not null.
-
The length of the serialization of ig ’s trusted bidding signals url , if the field is not null.
-
For each key of ig ’s trusted bidding signals keys :
-
The length of key .
-
-
The length of ig ’s user bidding signals .
-
If ig ’s ads is not null, for each ad of it:
-
The length of the serialization of ad ’s render url .
-
-
If ig ’s ad components is not null, for each ad of it:
-
The length of the serialization of ad ’s render url .
-
To check interest group permissions given an origin ownerOrigin , an origin frameOrigin , and a boolean isJoin :
-
If ownerOrigin is same origin to frameOrigin , then return true.
-
Let permissionsUrl be the result of building an interest group permissions url with ownerOrigin and frameOrigin .
-
Let request be the result of creating a request with permissionsUrl , "
application/json", and null. -
Let resource be null.
-
Fetch request with processResponseConsumeBody set to the following steps given a response response and responseBody :
-
If responseBody is null or failure, set resource to failure and return.
-
Let headers be response ’s header list .
-
If getting a structured field value "X-Allow-Protected-Audience" from headers does not return true, set resource to failure and return.
-
Let mimeType be the result of extracting a MIME type from headers .
-
If mimeType is failure or is not a JSON MIME Type , throw, set resource to failure and return.
-
Set resource to responseBody .
-
-
Wait for resource to be set.
-
If resource is failure, then return false.
-
Let permissions be the result of parsing a JSON string to an Infra value , returning false on failure.
-
If permissions is not an ordered map , then return false.
-
If isJoin is true and permissions ["
joinAdInterestGroup"] exists , then return permissions ["joinAdInterestGroup"]. -
If isJoin is false and permissions ["
leaveAdInterestGroup"] exists , then return permissions ["leaveAdInterestGroup"]. -
Return false.
The browser may cache requests for permissionsUrl within a network partition.
In order to prevent leaking data, the browser must request permissionsUrl regardless of whether the user is a member of the ad interest group. This prevents a leak of the user’s ad interest group membership to the server.
To build an interest group permissions url given a origin ownerOrigin and a origin frameOrigin :
-
Let serializedFrameOrigin be the result of serializing frameOrigin .
-
Return the string formed by concatenating
-
The serialization of ownerOrigin ,
-
The string "
/.well-known/interest-group/permissions/?origin=", and -
The result of UTF-8 percent-encoding serializedFrameOrigin using component percent-encode set .
-
3. Leaving Interest Groups
In order to remove a user from a particular interest group,
navigator
.
leaveAdInterestGroup()
can
be
called.
TODO: Edit the following from the explainer. As a special case to support in-ad UIs, invoking navigator.leaveAdInterestGroup() from inside an ad that is being targeted at a particular interest group will cause the browser to leave that group, irrespective of permission policies. Note that calling navigator.leaveAdInterestGroup() without arguments isn’t supported inside a component ad frame.
[SecureContext ]partial interface Navigator {Promise <undefined >leaveAdInterestGroup (AuctionAdInterestGroupKey ); };group dictionary {AuctionAdInterestGroupKey required USVString ;owner required USVString ; };name
The
leaveAdInterestGroup(group)
method
steps
are:
-
If this 's relevant global object 's associated Document is not allowed to use the " join-ad-interest-group " policy-controlled feature , then throw a "
NotAllowedError"DOMException. -
Let owner be the result of parsing an origin with group ["
owner"]. -
Let name be group ["
name"]. -
Let p be a new promise .
-
Run these steps in parallel :
-
TODO: document .well-known fetches for cross-origin leaves.
-
Queue a task to resolve p with
undefined. -
Remove interest groups from the user agent’s interest group set whose owner is owner and name is name .
-
-
Return p .
4. Running Ad Auctions
When
a
website
or
someone
working
on
behalf
of
the
website
(e.g.
a
supply
side
platform,
SSP)
wants
to
conduct
an
auction
to
select
an
advertisement
to
display
to
the
user,
they
can
call
the
navigator
.
runAdAuction()
function,
providing
an
auction
configuration
that
tells
the
browser
how
to
conduct
the
auction
and
which
on-device
recorded
interests
are
allowed
to
bid
in
the
auction
for
the
chance
to
display
their
advertisement.
4.1. runAdAuction()
[SecureContext ]partial interface Navigator {Promise <USVString ?>runAdAuction (AuctionAdConfig ); };config dictionary {AuctionAdConfig required USVString ;seller required USVString ;decisionLogicURL USVString ;trustedScoringSignalsURL sequence <USVString >;interestGroupBuyers any ;auctionSignals any ;sellerSignals USVString ;directFromSellerSignals unsigned long long ;sellerTimeout unsigned short ;sellerExperimentGroupId record <USVString ,any >;perBuyerSignals record <USVString ,unsigned long long >;perBuyerTimeouts record <USVString ,unsigned short >;perBuyerGroupLimits record <USVString ,unsigned short >;perBuyerExperimentGroupIds record <USVString ,record <USVString ,double >>;perBuyerPrioritySignals sequence <AuctionAdConfig >= [];componentAuctions AbortSignal ?; };signal
The
runAdAuction(
config
)
method
steps
are:
-
Let global be this 's relevant global object .
-
If global ’s associated Document is not allowed to use the " run-ad-auction " policy-controlled feature , then throw a "
NotAllowedError"DOMException. -
Let auctionConfig be the result of running validate and convert auction ad config with config and isTopLevel set to true.
-
Let p be a new promise .
-
If config ["
signal"] exists , then:-
Let signal be config ["
signal"]. -
If signal is aborted , then reject p with signal ’s abort reason and return p .
-
Add the following abort steps to signal :
-
Reject p with signal ’s abort reason .
-
TODO: Update bidCount for interest groups that participated in the auction.
-
Run interest group update with auctionConfig ’s interest group buyers .
-
-
-
Let queue be the result of starting a new parallel queue .
-
Enqueue the following steps to queue :
-
Let winner be the result of running generate and score bids with auctionConfig , null, and global .
-
If winner is null:
-
Queue a global task on DOM manipulation task source , given global , to resolve p with null.
-
-
Otherwise:
-
Queue a global task on the DOM manipulation task source , given global , to resolve p
with winner ’s ad descriptor . TODO: resolve p with urn-uuid, instead of a URL.
-
-
Run interest group update with auctionConfig ’s interest group buyers .
-
TODO: Update bidCount and prevWins for interest groups that participated in the auction.
-
-
Return p .
To
validate
and
convert
auction
ad
config
given
an
AuctionAdConfig
config
and
a
boolean
isTopLevel
:
-
Let auctionConfig be a new auction config .
-
Let auctionConfig ’s seller be the result of parsing an origin with config ["
seller"]. -
Throw a
TypeErrorif auctionConfig ’s seller is an error, or its scheme is not "https". -
Let decisionLogicURL be the result of running the URL parser on config ["
decisionLogicURL"].-
Throw a
TypeErrorif decisionLogicURL is an error, or it is not same origin with auctionConfig ’s seller . -
Set auctionConfig ’s decision logic url to decisionLogicURL .
-
-
If config ["
trustedScoringSignalsURL"] exists :-
Let trustedScoringSignalsURL be the result of running the URL parser on config ["
trustedScoringSignalsURL"]. -
Throw a
TypeErrorif trustedScoringSignalsURL is an error, or it is not same origin with auctionConfig ’s seller . -
Set auctionConfig ’s trusted scoring signals url to trustedScoringSignalsURL .
-
-
If config ["
interestGroupBuyers"] exists , let buyers be a new empty list .-
For each buyerString in config ["
interestGroupBuyers"]:-
Let buyer be the result of parsing an origin with buyerString . If buyer is an error, or buyer ’s scheme is not "
https", then throw aTypeError. Otherwise, append buyer to buyers .
-
-
Set auctionConfig ’s interest group buyers to buyers .
-
-
If config ["
auctionSignals"] exists , let auctionConfig ’s auction signals be the result of serializing a JavaScript value to a JSON string , given config ["auctionSignals"]. -
If config ["
sellerSignals"] exists , let auctionConfig ’s seller signals of be the result of serializing a JavaScript value to a JSON string , given config ["sellerSignals"]. -
If config ["
directFromSellerSignals"] exists , let directFromSellerSignalsPrefix be the result of running the URL parser on config ["directFromSellerSignals"]. -
If config ["
sellerTimeout"] exists , set auctionConfig ’s seller timeout to min( config ["sellerTimeout"], 500) milliseconds. -
If config ["
sellerExperimentGroupId"] exists :-
Set auctionConfig ’s seller experiment group id to config ["
sellerExperimentGroupId"].
-
-
If config ["
perBuyerSignals"] exists , for each key → value of config ["perBuyerSignals"]:-
Let buyer be the result of parsing an origin with key . If buyer is an error, throw a
TypeError. -
Let signalsString be the result of serializing a JavaScript value to a JSON string , given value .
-
Set auctionConfig ’s per buyer signals [ buyer ] to signalsString .
-
-
If config ["
perBuyerTimeouts"] exists , for each key → value of config ["perBuyerTimeouts"]:-
If key equals to "*", then set auctionConfig ’s all buyers timeout to min( value , 500) milliseconds, and continue .
-
Let buyer the result of parsing an origin with key . If buyer is an error, throw a
TypeError. -
Set auctionConfig ’s per buyer timeouts [ buyer ] to min( value , 500) milliseconds.
-
-
If config ["
perBuyerGroupLimits"] exists , for each key → value of config ["perBuyerGroupLimits"]:-
If key equals to "*", then set auctionConfig ’s all buyers group limit to value , and continue .
-
Let buyer be the result of parsing an origin with key . If buyer is an error, throw a
TypeError. -
Set auctionConfig ’s per buyer group limits [ buyer ] to value .
-
If config ["
perBuyerExperimentGroupIds"] exists , for each key → value of config ["perBuyerExperimentGroupIds"]:-
If key equals to "*", then set auctionConfig ’s all buyer experiment group id to value , and continue .
-
Let buyer the result of parsing an origin with key . If buyer is an error, throw a
TypeError. -
Set auctionConfig ’s per buyer experiment group ids [ buyer ] to value .
-
-
If config ["
perBuyerPrioritySignals"] exists , for each key → value of config ["perBuyerPrioritySignals"]:-
Let signals be an ordered map whose keys are strings and whose values are
double. -
for each k → v of value :
-
If k starts with "browserSignals.", throw a
TypeError. -
Set signals [ k ] to v .
-
-
If key equals to "*", then set auctionConfig ’s all buyers priority signals to value , and continue .
-
Let buyer be the result of parsing an origin with key . If it fails, throw a
TypeError. -
Set auctionConfig ’s per buyer priority signals [ buyer ] to signals .
-
-
For each component in config ["
componentAuctions"]:-
Let componentAuction be the result of running validate and convert auction ad config with component and isTopLevel set to false.
-
Append componentAuction to auctionConfig ’s component auctions .
-
Return auctionConfig .
To parse an origin given a string input :
-
Let url be the result of running the URL parser on input .
-
If url is an error, then return failure.
-
Return url ’s origin .
To build bid generators map given an auction config auctionConfig :
-
Let bidGenerators be a new ordered map whose keys are origins and whose values are per buyer bid generators .
-
For each buyer in auctionConfig ’s interest group buyers :
-
For each ig of the user agent’s interest group set whose owner is buyer :
-
Let signalsUrl be ig ’s trusted bidding signals url .
-
Let joiningOrigin be ig ’s joining origin .
-
If bidGenerators does not contain buyer :
-
Let perBuyerGenerator be a new per buyer bid generator .
-
Let perSignalsUrlGenerator be a new per signals url bid generator .
-
Set perSignalsUrlGenerator [ joiningOrigin ] to « ig ».
-
Set perBuyerGenerator [ signalsUrl ] to perSignalsUrlGenerator .
-
Set bidGenerators [ buyer ] to perBuyerGenerator .
-
TODO: add a perBiddingScriptUrlGenerator layer that replaces the list of IGs with a map from biddingScriptUrl to a list of IGs.
-
-
Otherwise:
-
Let perBuyerGenerator be bidGenerators [ buyer ].
-
If perBuyerGenerator does not contain signalsUrl :
-
Let perSignalsUrlGenerator be a new per signals url bid generator .
-
Set perSignalsUrlGenerator [ joiningOrigin ] to « ig ».
-
Set perBuyerGenerator [ signalsUrl ] to perSignalsUrlGenerator .
-
-
Otherwise:
-
-
-
-
Return bidGenerators .
To generate and score bids given an auction config auctionConfig , an auction config -or-null topLevelAuctionConfig , and a global object global :
-
Assert that these steps are running in parallel .
-
Let decisionLogicScript be the result of fetching script with auctionConfig ’s decision logic url .
-
If decisionLogicScript is failure, return null.
-
Let bidGenerators be the result of running build bid generators map with auctionConfig .
-
Let leadingBidInfo be a new leading bid info .
-
Let queue be the result of starting a new parallel queue .
-
If auctionConfig ’s component auctions are not empty :
-
Assert topLevelAuctionConfig is null.
-
Let pendingComponentAuctions be the size of auctionConfig ’s component auctions .
-
For each component in auctionConfig ’s component auctions , enqueue the following steps to queue :
-
Let compWinner be the result of generate and score bids with component , auctionConfig , and global .
-
If compWinner is not null:
-
Run score and rank a bid with auctionConfig , compWinner , leadingBidInfo , decisionLogicScript , null, and true.
-
-
Decrement pendingComponentAuctions by 1.
-
-
Wait until pendingComponentAuctions is 0.
-
If leadingBidInfo ’s leading bid is null, return null.
-
Let winningComponentConfig be leadingBidInfo ’s auction config .
-
Set leadingBidInfo ’s auction config to auctionConfig .
-
Set leadingBidInfo ’s component seller to winningComponentConfig ’s seller .
-
Let « topLevelSellerSignals , unusedTopLevelReportResultBrowserSignals » be the result of running report result with leadingBidInfo .
-
Set leadingBidInfo ’s auction config to winningComponentConfig .
-
Set leadingBidInfo ’s component seller to null.
-
Set leadingBidInfo ’s top level seller to auctionConfig ’s seller .
-
Set leadingBidInfo ’s top level seller signals to topLevelSellerSignals .
-
Let « sellerSignals , reportResultBrowserSignals » be the result of running report result with leadingBidInfo .
-
Run report win with leadingBidInfo , sellerSignals , and reportResultBrowserSignals .
-
Return leadingBidInfo ’s leading bid .
-
-
Let allBuyersExperimentGroupId be auctionConfig ’s all buyer experiment group id .
-
Let auctionSignals be auctionConfig ’s auction signals .
-
Let browserSignals be an ordered map whose keys are strings and whose values are
any. -
Set browserSignals ["
topWindowHostname"] to this 's relevant settings object 's top-level origin 's host . -
If topLevelAuctionConfig is not null:
-
Set browserSignals ["topLevelSeller"] to the serialization of topLevelAuctionConfig ’s seller .
-
-
Let pendingBuyers be the size of bidGenerators .
-
For each buyer → perBuyerGenerator of bidGenerators , enqueue the following steps to queue :
-
Let buyerExperimentGroupId be allBuyersExperimentGroupId .
-
Let perBuyerExperimentGroupIds be auctionConfig ’s per buyer experiment group ids .
-
If perBuyerExperimentGroupIds is not null and perBuyerExperimentGroupIds [ buyer ] exists:
-
Set buyerExperimentGroupId to perBuyerExperimentGroupIds [ buyer ].
-
-
Let perBuyerSignals be null.
-
If auctionConfig ’s per buyer signals is not null and per buyer signals [ buyer ] exists :
-
Set perBuyerSignals to auctionConfig ’s per buyer signals [ buyer ].
-
-
For each signalsUrl -> perSignalsUrlGenerator of perBuyerGenerator :
-
Let keys be a new ordered set .
-
Let igNames be a new ordered set .
-
For each joiningOrigin -> groups of perSignalsUrlGenerator :
-
For each ig of groups :
-
Append ig ’s trusted bidding signals keys to keys .
-
-
-
Let biddingSignalsUrl be the result of building trusted bidding signals url with signalsUrl , keys , igNames , buyerExperimentGroupId .
-
Let « allTrustedBiddingSignals , dataVersion » be the result of fetching trusted signals with biddingSignalsUrl and true.
-
For each joiningOrigin -> groups of perSignalsUrlGenerator :
-
For each ig of groups :
-
TODO: Let interestGroup be ... from ig ... minus priority and prioritySignalsOverrides and any browser-defined pieces
-
Set browserSignals ["
joinCount"] to the sum of ig ’s join counts for all days within the last 30 days. -
Set browserSignals ["
bidCount"] to the sum of ig ’s bid counts for all days within the last 30 days. -
Set browserSignals ["
prevWins"] to a list containing tuple s of the time and the corresponding winning interest group ad from ig ’s previous wins field with a data within the last 30 days. The time field is specified in seconds relative to the start of the auction. -
TODO: Set browserSignals ’s "wasmHelper" ...need to fetch and prepare WebAssembly.Module object based on ig ’s bidding wasm helper url
-
If dataVersion is not null:
-
Set browserSignals ["
dataVersion"] to dataVersion .
-
-
Let biddingScript be the result of fetching script with ig ’s bidding url . If biddingScript is failure, continue .
-
Let trustedBiddingSignals be an ordered map whose keys are strings and whose values are
any. -
For each key of ig ’s trusted bidding signals keys :
-
Let generatedBidResult be the result of evaluating a bidding script with biddingScript and « interestGroup , auctionSignals , perBuyerSignals , trustedBiddingSignals , browserSignals ».
-
If generatedBidResult is an abrupt completion , continue .
-
Let generatedBidIDL be the result of converting generatedBidResult to a
GenerateBidOutput. -
If an exception was caught in the previous step, continue .
-
Let generatedBid be the result of converting GenerateBidOutput to generated bid with generatedBidIDL .
-
If generatedBid is failure, continue .
-
Set generatedBid ’s interest group to ig .
-
Let isComponentAuction be a boolean set to true when topLevelAuctionConfig is not null, otherwise false.
-
Score and rank a bid with auctionConfig , generatedBid , leadingBidInfo , decisionLogicScript , dataVersion and isComponentAuction .
-
-
-
-
Decrement pendingBuyers by 1.
-
-
Wait until pendingBuyers is 0.
-
If leadingBidInfo ’s leading bid is null, return null.
-
If topLevelAuctionConfig is null:
-
Let « sellerSignals , reportResultBrowserSignals » be the result of running report result with leadingBidInfo .
-
Run report win with leadingBidInfo , sellerSignals , and reportResultBrowserSignals .
-
-
Return leadingBidInfo ’s leading bid .
To
score
and
rank
a
bid
given
an
auction
config
auctionConfig
,
a
generated
bid
generatedBid
,
a
leading
bid
info
leadingBidInfo
,
a
string
decisionLogicScript
,
a
unsigned
long
-or-null
biddingDataVersion
,
and
a
boolean
isComponentAuction
:
-
TODO: Assemble and fetch trusted scoring signals
-
TODO: Let adMetadata be ... maybe include in generated bid
-
Let bidValue be generatedBid ’s bid .
-
If generatedBid ’s modified bid is not null:
-
Set bidValue to generatedBid ’s modified bid .
-
-
TODO: Let trustedScoringSignals ... need to assemble and fetch these
-
Let browserSignals be an ordered map whose keys are strings and whose values are
any. -
Set browserSignals ["
topWindowHostname"] to this 's relevant settings object 's top-level origin 's host . -
Set browserSignals ["interestGroupOwner"] to generatedBid ’s interest group 's owner .
-
Set browserSignals ["renderURL"] to generatedBid ’s ad descriptor 's url .
-
Set browserSignals ["adComponents"] to generatedBid ’s ad component descriptors .
-
Set browserSignals ["biddingDurationMsec"] to generatedBid ’s bid duration .
-
TODO: Set browserSignals ’s "dataVersion" ...to Data-Version value from the trusted scoring signals server’s response.
-
TODO: Remove fields of auctionConfig that don’t pass through.
-
Let scoreAdOutput be the result of evaluating a scoring script with decisionLogicScript and « adMetadata , bidValue , auctionConfig , trustedScoringSignals , browserSignals ».
-
If isComponentAuction is true, and scoreAdOutput ’s allow component auction is false, return.
-
Let score be scoreAdOutput ’s desirability .
-
If score is negative or 0, return.
-
If isComponentAuction is true and scoreAdOutput ’s bid is not null:
-
Set generatedBid ’s modified bid to scoreAdOutput ’s bid .
-
-
Let updateLeadingBid be false.
-
If leadingBidInfo ’s leading bid is null:
-
Set updateLeadingBid to true.
-
-
Otherwise if score is greater than leadingBidInfo ’s top score :
-
Set leadingBidInfo ’s top bids count to 1.
-
Set updateLeadingBid to true.
-
-
Otherwise if score equals leadingBidInfo ’s top score :
-
Increment leadingBidInfo ’s top bids count by 1.
-
Set updateLeadingBid to true with 1 in leadingBidInfo ’s top bids count chance.
-
If updateLeadingBid is false:
-
Update highest scoring other bid with score , leadingBidInfo ’s leading bid , and leadingBidInfo .
-
-
-
Otherwise if score is greater than or equal to leadingBidInfo ’s second highest score :
-
Update highest scoring other bid with score , bidValue , and leadingBidInfo .
-
-
If updateLeadingBid is true:
-
Update highest scoring other bid with leadingBidInfo ’s top score , leadingBidInfo ’s leading bid , and leadingBidInfo .
-
Set leadingBidInfo ’s top score to score .
-
Set leadingBidInfo ’s leading bid to generatedBid .
-
Set leadingBidInfo ’s auction config to auctionConfig .
-
Set leadingBidInfo ’s bidding data version to biddingDataVersion .
-
TODO: Set leadingBidInfo ’s scoring data version .
-
double
score
,
a
generated
bid
-or-null
bid
,
and
a
leading
bid
info
leadingBidInfo
:
-
If bid is null, return.
-
If score is greater than leadingBidInfo ’s second highest score :
-
Set leadingBidInfo ’s highest scoring other bid to bid .
-
Set leadingBidInfo ’s highest scoring other bids count to 1.
-
Set leadingBidInfo ’s second highest score to score .
-
-
Otherwise if score is equal to leadingBidInfo ’s second highest score :
-
Increment leadingBidInfo ’s highest scoring other bids count by 1.
-
Set leadingBidInfo ’s highest scoring other bid to bid with 1 in leadingBidInfo ’s highest scoring other bids count chance.
-
-
Let request be a new request with the following properties:
- URL
-
url
- header list
-
A new header list containing a header named "
Accept" whose value is accept - client
-
null - window
-
"
no-window" TODO: verify - service-workers mode
-
"
none" - origin
-
If origin is null, then opaque origin , otherwise origin .
- referrer
-
"
no-referrer" - credentials mode
-
"
omit" - cache mode
-
"
no-store" - redirect mode
-
"
error"
-
Return request .
-
If responseBody is null or failure, return false.
-
Let headers be response ’s header list .
-
If getting a structured field value "X-Allow-Protected-Audience" from headers does not return true, return false.
-
Let headerMimeType be the result of extracting a MIME type from headers .
-
Return false if any of the following conditions hold:
-
headerMimeType is failure;
-
mimeType is "
text/javascript" and headerMimeType is not a JavaScript MIME type ; -
mimeType is "
application/json" and headerMimeType is not a JSON MIME type .
-
-
Let mimeTypeCharset be headerMimeType ’s parameters ["
charset"]. -
Return false if any of the following conditions hold:
-
If mimeTypeCharset does not exist , or mimeTypeCharset is "utf-8", and responseBody is not UTF-8 encoded;
-
If mimeTypeCharset is "us-ascii", and responseBody is not ascii string .
-
-
Return true.
-
Let request be the result of creating a request with url , "
text/javascript", and null. -
Let script be null.
-
Fetch request with processResponseConsumeBody set to the following steps given a response response and responseBody :
-
If validate fetching response with response , responseBody and "
text/javascript" returns false, set script to failure and return. -
Set script to responseBody .
-
-
Wait for script to be set.
-
Return script .
The
Data-Version
HTTP
response
header
is
a
structured
header
whose
value
must
be
an
integer
.
The
X-protected-audience-bidding-signals-format-version
HTTP
response
header
is
a
structured
header
whose
value
must
be
an
integer
.
-
Let request be the result of creating a request with url , "
application/json", and null. -
Let signals be null.
-
Let dataVersion be null.
-
Let formatVersion be null.
-
Fetch request with processResponseConsumeBody set to the following steps given a response response and responseBody :
-
If validate fetching response with response , responseBody and "
application/json" returns false, set signals to failure and return. -
Let headers be response ’s header list .
-
Set dataVersion to the result of getting a structured field value given `
Data-Version` and "item" from headers . -
If dataVersion is not null:
-
If dataVersion is not an integer, or is less than 0 or more than 4294967295, set signals to failure and return.
-
TODO: Check whether version is consistent for all keys requested by this interest group.
-
-
If isBiddingSignal is true:
-
Set formatVersion to the result of getting a structured field value given `
X-protected-audience-bidding-signals-format-version` and "item" from headers .
-
-
Set signals to the result of parsing JSON bytes to an Infra value responseBody .
-
-
Wait for signals to be set.
-
If signals is a parsing exception, or if signals is not an ordered map , return « null, null ».
-
If formatVersion is not null, is an integer, and is 2:
-
If signals ["
keys"] exists , then set signals to signals ["keys"]. -
Otherwise, return « null, null ».
-
If signals is not an ordered map , return « null, null ».
-
-
Return « signals , dataVersion ».
To
build
trusted
bidding
signals
url
given
a
URL
signalsUrl
,
an
ordered
set
of
strings
keys
,
an
ordered
set
of
strings
igNames
,
and
a
unsigned
short
experimentGroupId
:
-
Append "hostname=" to queryParamsList .
-
Append the result of UTF-8 percent-encoding this 's relevant settings object 's top-level origin using component percent-encode set to queryParamsList .
-
If keys is not empty :
-
Append "&keys=" to queryParamsList .
-
Let keysStr be the result of concatenating keys with separator set to ",".
-
Append the result of UTF-8 percent-encoding keysStr using component percent-encode set to queryParamsList .
-
-
If igNames is not empty :
-
Append "&interestGroupNames=" to queryParamsList .
-
Let igNamesStr be the result of concatenating igNames with separator set to ",".
-
Append the result of UTF-8 percent-encoding igNamesStr using component percent-encode set to queryParamsList .
-
-
If experimentGroupId is not null:
-
Append "&experimentGroupId=" to queryParamsList .
-
Append serialized experimentGroupId to queryParamsList .
-
-
Set signalsUrl ’s query to the result of concatenating queryParamsList .
-
return signalsUrl .
To serialize an integer , represent it as a string of the shortest possible decimal number.
This would ideally be replaced by a more descriptive algorithm in Infra. See infra/201
-
Let browserSignals be an ordered map whose keys are strings and whose values are
any. -
Set browserSignals ["
topWindowHostname"] to this 's relevant settings object 's top-level origin 's host . -
Let winner be leadingBidInfo ’s leading bid .
-
Set browserSignals ["
interestGroupOwner"] to winner ’s interest group 's owner . -
Set browserSignals ["
renderUrl"] to winner ’s ad descriptor 's url . -
Set browserSignals ["
desirability"] to leadingBidInfo ’s top score . -
Set browserSignals ["
highestScoringOtherBid"] to leadingBidInfo ’s highest scoring other bid 's bid . -
TODO: if trusted scoring signals response data version is not null, set browserSignals ["
dataVersion"]. -
If leadingBidInfo ’s top level seller is not null, set browserSignals ["
topLevelSeller"] to it. -
If leadingBidInfo ’s top level seller signals is not null, set browserSignals ["
topLevelSellerSignals"] to it. -
If leadingBidInfo ’s component seller is not null:
-
Set browserSignals ["
componentSeller"] to leadingBidInfo ’s component seller . -
If winner ’s modified bid is not null, set browserSignals ["
bid"] to it.
-
-
Otherwise, if winner ’s modified bid is not null, set browserSignals ["
modifiedBid"] to it. -
Set config to leadingBidInfo ’s auction config .
-
Let sellerReportingScript be the result of fetching script with config ’s decision logic url .
-
Let sellerSignals be the result of evaluating a reporting script with sellerReportingScript , "
reportResult", and « config ’s auction signals , browserSignals ». -
TODO: Set URLs passed to sendReportTo() into the FencedFrameConfig so they can be fetched when ad renders.
-
Remove browserSignals ["
dataVersion"]. -
Remove browserSignals ["
modifiedBid"]. -
Remove browserSignals ["
topLevelSellerSignals"]. -
Return « sellerSignals , browserSignals ».
any
:
-
Let config be leadingBidInfo ’s auction config .
-
Let winner be leadingBidInfo ’s leading bid .
-
Let perBuyerSignals be config ’s per buyer signals .
-
Let buyer be winner ’s interest group 's owner .
-
Let perBuyerSignalsForBuyer be perBuyerSignals [ buyer ] if that member exists , and null otherwise.
-
Remove browserSignals ["
desirability"]. -
TODO: Set browserSignals ["
interestGroupName"] to winner ’s name if the tuple of interest group owner, name, bidding script URL and ad creative URL were jointly k-anonymous. -
TODO: Set browserSignals ["
madeHighestScoringOtherBid"] are based on the auction the interest group was directly part of. If that was a component auction, they’re from the component auction. If that was the top-level auction, then they’re from the top-level auction. Component bidders do not get these signals from top-level auctions since it is the auction seller joining the top-level auction, instead of winning component bidders joining the top-level auction directly. -
If leadingBidInfo ’s bidding data version is not null:
-
Set browserSignals ["dataVersion"] to leadingBidInfo ’s bidding data version .
-
-
If leadingBidInfo ’s top level seller is not null:
-
Set browserSignals ["
topLevelSeller"] to leadingBidInfo ’s top level seller .
-
-
If winner ’s modeling signals is not null:
-
Set browserSignals ["
modelingSignals"] to winner ’s modeling signals .
-
-
Let buyerReportingScript be the result of fetching script with winner ’s interest group 's bidding url .
-
Run evaluating a reporting script with buyerReportingScript , "
reportWin", and « leadingBidInfo ’s auction config 's auction signals , perBuyerSignalsForBuyer , sellerSignals , browserSignals ». -
TODO: Set URLs passed to sendReportTo() into the FencedFrameConfig so they can be fetched when ad renders.
5. Script Runners
This introduction sub-section is non-normative .
This specification defines a new type of script execution environment called a script runner . On the surface, these are similar to Worklets in that they too are used for running scripts independent of the main execution environment with a flexible implementation model.
However, some key differences from traditional Worklets motivate us to create a new kind of script execution environment. In particular, they:
-
Are not scoped to a particular
Document, but are rather scoped to a user agent, as they are spun up by interest groups in the user agent’s interest group set . -
Consequently have a different, more flexible agent cluster allocation model —
specifically, they need not execute in the same agent cluster as anyDocument, and for privacy reasons implementations may be motivated to enjoy this flexibility. -
Do not have any other WebIDL interfaces exposed to their global besides the ones defined in this specification, unlike other Worklet types.
-
Have a restricted set of ECMAScript APIs exposed to them; for example
Dateis not exposed in these environments. -
Are not module scripts , and are instead evaluated as if they were classic scripts .
-
Are not scripts in the [HTML] sense, and as such:
-
Their agent does not have an event loop
-
Their realm does not have a settings object , and therefore functions inside them are not run with the familiar [WebIDL] invocation mechanism.
-
They do not perform a microtask checkpoints .
-
5.1. Script evaluation
Concretely, a script runner is a JavaScript execution environment instantiated with one of the following global objects:
Each
InterestGroupBiddingScriptRunnerGlobalScope
has
a
bid
,
which
is
a
generated
bid
,
a
priority
,
which
is
a
double
or
null,
and
a
priority
signals
,
which
is
an
ordered
map
whose
keys
are
strings
and
whose
values
are
double
.
-
Return the result of evaluating a script with
InterestGroupBiddingScriptRunnerGlobalScope, script , "generateBid", and arguments .
-
Return the result of evaluating a script with
InterestGroupScoringScriptRunnerGlobalScope, script , "scoreAd", and arguments .
-
Return the result of evaluating a script with
InterestGroupReportingScriptRunnerGlobalScope, script , functionName , and arguments .
-
Let signifier be a new unique internal value.
-
Let candidateExecution be a new candidate execution .
-
Return a new agent whose [[CanBlock]] is false, [[Signifier]] is signifier , [[CandidateExecution]] is candidateExecution , and [[IsLockFree1]], [[IsLockFree2]], and [[LittleEndian]] are set at the implementation’s discretion.
Note: This algorithm is almost identical to [HTML] 's create an agent algorithm, with the exception that we do not give the returned agent a new event loop , since it does not process tasks within task sources in the usual way.
-
Let agentCluster be a new agent cluster .
-
Let agent be the result of creating a new script runner agent .
-
Add agent to agentCluster .
-
Return agent .
-
Assert that these steps are running in parallel .
-
Let agent be the result of obtaining a script runner agent given null, true, and false. Run the rest of these steps in agent .
This exclusively creates a new agent cluster for the given script to run in, but we should make this work with execution mode somehow.
-
Let realmExecutionContext be the result of creating a new realm given agent and the following customizations:
-
For the global object, create a new object of type globalType .
-
-
Let realm be realmExecutionContext ’s Realm component.
-
Let global be realm ’s global object , and run these steps:
-
Perform ! global .[[Delete]]("
Date"). -
If ! global .[[HasProperty]]("
Temporal") is true, then perform ! global .[[Delete]]("Temporal").
This is not the best way to perform such API neutering (see tc39/ecma262#1357 ), but at the moment it’s the way that host environments do this.
Note: Removing time-referencing APIs from the global object is imperative for privacy, as script might otherwise be able to more easily exfiltrate data by using more accurate time measurements.
-
-
Let result be ParseScript ( script , realm ,
empty).Note: The resulting Script Record will have no [[HostDefined]] component, unlike traditional scripts on the web platform.
-
If result is a list of errors, return Completion { [[Type]]:
throw, [[Value]]: result , [[Target]]:empty}. -
Assert : result is a Script Record .
-
Prepare to run script : Push realmExecutionContext onto the JavaScript execution context stack ; it is now the running JavaScript execution context .
-
Let evaluationStatus be the result of ScriptEvaluation (result).
-
If evaluationStatus is an abrupt completion , jump to the step labeled return .
-
Let F be Get ( global , functionName ). If that returns a throw completion , set finalCompletion to F and jump to the step labeled return .
-
Set finalCompletion be Completion ( Call (F,
undefined, arguments )). -
Return : at this point finalCompletion will be set to a Completion Record .
-
Clean up after script : Assert realmExecutionContext is the running JavaScript execution context , and remove it from the JavaScript execution context stack .
-
Return finalCompletion .
-
5.2. Global scopes
An additional requirement to the interest group script runner globals defined in this specification is that they must not expose any interfaces from other specifications whose own exposure set is the special value "*". The only interfaces that can be exposed inside of the globals defined in this specification are those that explicitly list the global names provided here.
[Exposed =InterestGroupScriptRunnerGlobalScope ]interface { }; [InterestGroupScriptRunnerGlobalScope Exposed =InterestGroupBiddingScriptRunnerGlobalScope ,Global =(InterestGroupScriptRunnerGlobalScope ,InterestGroupBiddingScriptRunnerGlobalScope )]interface :InterestGroupBiddingScriptRunnerGlobalScope InterestGroupScriptRunnerGlobalScope {boolean setBid ();boolean setBid (GenerateBidOutput );generateBidOutput undefined setPriority (double );priority undefined setPrioritySignalsOverride (DOMString ,key double ); }; [priority Exposed =InterestGroupScoringScriptRunnerGlobalScope ,Global =(InterestGroupScriptRunnerGlobalScope ,InterestGroupScoringScriptRunnerGlobalScope )]interface :InterestGroupScoringScriptRunnerGlobalScope InterestGroupScriptRunnerGlobalScope { }; [Exposed =InterestGroupReportingScriptRunnerGlobalScope ,Global =(InterestGroupScriptRunnerGlobalScope ,InterestGroupReportingScriptRunnerGlobalScope )]interface :InterestGroupReportingScriptRunnerGlobalScope InterestGroupScriptRunnerGlobalScope {undefined sendReportTo (DOMString ); };url dictionary {AdRender required DOMString ;url required DOMString ;width required DOMString ; };height dictionary {GenerateBidOutput required double ;bid required (DOMString or AdRender );adRender any ;ad sequence <(DOMString or AdRender )>;adComponents double ;adCost double ;modelingSignals boolean =allowComponentAuction false ; };
setBid()
method
steps
are:
-
Set this 's relevant global object 's bid to null.
-
Return true.
To
convert
GenerateBidOutput
to
generated
bid
given
a
GenerateBidOutput
generateBidOutput
:
-
If generateBidOutput ["
bid"] is less than or equal to 0, return failure. -
If it’s a component auction (TODO: how to integrate with runAdAuction), but generateBidOutput ["
allowComponentAuction"] is false, return failure. -
Let bid be a new generated bid .
-
If generateBidOutput ["
ad"] exists :-
Let adJSON be the result of serializing a JavaScript value to a JSON string , given generateBidOutput ["
ad"]. -
If adJSON is failure, return failure.
-
Set bid ’s ad to adJSON .
-
-
Let adDescriptor be a new ad descriptor .
-
If generateBidOutput ["
adRender"] is aDOMString:-
Let adUrl be the result of running the URL parser on generateBidOutput ["
adRender"]. -
If adUrl is an error, return failure.
-
If validating an ad url given adUrl returns false, return failure.
-
Set adDescriptor ’s url to adUrl .
-
-
Otherwise:
-
Set adDescriptor to the result of converting an ad render given generateBidOutput ["
adRender"]. -
If adDescriptor is failure, return failure.
-
-
Set bid ’s ad descriptor to adDescriptor .
-
If generateBidOutput ["
adComponents"] exists :-
Let adComponents be generateBidOutput ["
adComponents"]. -
Return failure if any of the following conditions hold:
-
biddingScriptRunner’s adComponents parameter does not exist; TODO: rewrite.
-
adComponents is not an array;
-
adComponents ’s size is greater than 20.
-
-
Let adComponentDescriptors be a new list of ad descriptors .
-
For component in adComponents :
-
Let componentDescriptor be a new ad descriptor .
-
If component is
DOMString:-
Let componentUrl be the result of running the URL parser on component .
-
If componentUrl is an error, return failure.
-
If validating an ad url given componentUrl returns false, return failure.
-
Set componentDescriptor ’s url to componentUrl .
-
-
Otherwise:
-
Set componentDescriptor to the result of converting an ad render given component .
-
If componentDescriptor is failure, return failure.
-
-
Append componentDescriptor to adComponentDescriptors .
-
-
Set bid ’s ad component descriptors to adComponentDescriptors .
-
-
If generateBidOutput ["
modelingSignals"] exists :-
Let modelingSignals be generateBidOutput ["
modelingSignals"]. -
If modelingSignals is greater than or equal to 0 and less than 4096:
-
Set bid ’s modeling signals to modelingSignals .
-
-
-
TODO: calculate bid duration and set bid ’s bid duration .
-
Return bid .
-
Let position be a position variable , initially pointing at the start of input .
-
Strip leading and trailing ASCII whitespace from input .
-
If input starts with "
0" but is not "0" and does not start with "0.", then return null as the dimension and the empty string as the dimension unit. -
Collect a sequence of code points that are ASCII digits or U+002E (.), given position . Let that be dimensionString .
-
If dimensionString is the empty string, then return null as the dimension and the empty string as the dimension unit.
-
Let dimension be the result of parsing dimensionString using the rules for parsing floating-point number values .
-
If dimension is an error, then return null as the dimension and the empty string as the dimension unit.
-
Collect a sequence of code points that are ASCII lower alpha , given position . Let that be dimensionUnit .
-
If position is not past the end of input , then return null as the dimension and the empty string as the dimension unit.
-
If dimensionUnit is the empty string, then set dimensionUnit to "px".
-
If dimensionUnit is not "px", "sh", or "sw", then return null as the dimension and the empty string as the dimension unit.
-
Return dimension as the dimension and dimensionUnit as the dimension unit.
AdRender
adRender
:
-
Let adUrl be the result of running the URL parser on adRender ["
url"]. -
If adUrl is an error, return failure.
-
If validating an ad url given adUrl returns false, return failure.
-
Let adDescriptor be a new ad descriptor .
-
Set adDescriptor ’s url to adUrl .
-
If adRender ["
width"] exists :-
Let width and widthUnit be the dimension and dimension unit that results from running parse an AdRender dimension value with adRender ["
width"], respectively. -
If width is null, return failure.
-
Let height and heightUnit be the dimension and dimension unit that results from running parse an AdRender dimension value with adRender ["
height"], respectively. -
If height is null, return failure.
-
Let adSize be a new ad size .
-
Set adSize ’s width to width , width units to widthUnit , height to height , height units to heightUnit .
-
Set adDescriptor ’s size to adSize .
-
Return adDescriptor .
-
If adUrl ’s scheme is not "
https", return false. -
TODO: If it’s not in the related interest group’s ads, or is excluded, return false.
-
Return true.
setBid(
generateBidOutput
)
method
steps
are:
-
Set this 's relevant global object 's bid to null.
-
Let bidToSet be the result of converting GenerateBidOutput to generated bid with generateBidOutput .
-
If bidToSet is failure, return false.
-
Set this 's relevant global object 's bid to bidToSet .
-
Return true.
setPriority(
priority
)
method
steps
are:
-
If this 's relevant global object 's priority is not null:
-
Set this 's relevant global object 's priority to null.
-
Return.
-
-
Set this 's relevant global object 's priority to priority .
setPrioritySignalsOverride(
key
,
priority
)
method
steps
are:
-
Set this 's relevant global object 's priority signals [ key ] to priority .
sendReportTo(
url
)
method
steps
are:
6. Interest Group Updates
Interest
groups
have
a
update
url
field
that
allows
updating
the
interest
group
definition
stored
on
disk
with
information
periodically
retrieved
from
the
update
url
.
The
interest
group
update
steps
are
triggered
during
runAdAuction()
and
by
calls
to
updateAdInterestGroups()
API:
[SecureContext ]partial interface Navigator {undefined updateAdInterestGroups (); };
The
updateAdInterestGroups()
method
steps
are:
-
In parallel , run interest group update with « relevant settings object 's top-level origin »
-
For each owner of owners :
-
For each originalInterestGroup of the user agent’s interest group set whose owner is owner and next update after is before now:
Note: Implementations can consider loading only a portion of these interest groups at a time to avoid issuing too many requests at once.
-
Let ig be a deep copy of originalInterestGroup .
-
Let request be the result of creating a request with ig ’s update url , "
application/json", and owner . -
Let update be null.
-
Fetch request with processResponseConsumeBody set to the following steps given a response response and responseBody :
-
If validate fetching response with response , responseBody and "
application/json" returns false, set update to failure and return. -
Set update to responseBody .
-
-
Wait for update to be set.
-
If update is failure, continue .
-
Let parsedUpdate be the result of parsing JSON bytes to an Infra value , given update .
-
If parsedUpdate is failure, continue .
-
If parsedUpdate is not an ordered map , continue .
-
If parsedUpdate ["
name"] exists and doesn’t match ig ’s name , continue . -
If parsedUpdate ["
owner"] exists and doesn’t match ig ’s owner , continue . -
For each key → value of parsedUpdate :
-
Switch on key :
-
"
priority" -
-
Otherwise, jump to the step labeled Abort update .
-
"
enableBiddingSignalsPrioritization" -
-
If value is a
boolean, set ig ’s enable bidding signals prioritization to value . -
Otherwise, jump to the step labeled Abort update .
-
-
"
priorityVector" -
-
If value is null or an ordered map whose keys are strings and whose values are
double, set ig ’s priority vector to value . -
Otherwise, jump to the step labeled Abort update .
-
-
"
prioritySignalsOverrides" -
-
If value is an ordered map whose keys are strings and whose values are
doubleor null:-
For each pvKey → pvValue of value :
-
If pvValue is null, remove ig ’s priority signals overrides [ pvKey ].
-
Otherwise, set ig ’s priority signals overrides [ pvKey ] to pvValue .
-
-
-
Otherwise, jump to the step labeled Abort update .
-
-
"
executionMode" -
-
If value is "
compatibility" or "group-by-origin", set ig ’s execution mode to value . -
Otherwise, jump to the step labeled Abort update .
-
-
"
biddingLogicURL"- "
biddingWasmHelperURL"- "
updateURL"- "
trustedBiddingSignalsURL" - "
-
-
For each groupMember and interestGroupField in the following table
Group member Interest group field " biddingLogicURL"bidding url " biddingWasmHelperURL"bidding wasm helper url " updateURL"update url " trustedBiddingSignalsURL"trusted bidding signals url -
Let parsedURL be the result of running the URL parser on value .
-
If key is not groupMember , continue .
-
Jump to the step labeled Abort update if any of the following conditions hold:
-
parsedURL is failure;
-
parsedURL is not same origin with ig ’s owner ;
-
parsedURL includes credentials ;
-
parsedURL fragment is not null.
-
-
Set ig ’s interestGroupField to parsedURL .
-
-
-
"
trustedBiddingSignalsKeys" -
-
If value is a list of strings , set ig ’s trusted bidding signals keys to value .
-
Otherwise, jump to the step labeled Abort update .
-
-
"
ads"- "
adComponents" - "
-
-
For each groupMember and interestGroupField in the following table
Group member Interest group field " ads"ads " adComponents"ad components -
If key is not groupMember , continue .
-
If value is not a list of
AuctionAd, jump to the step labeled Abort update . -
For each ad of value :
-
Let igAd be a new interest group ad .
-
Let renderURL be the result of running the URL parser on ad ["
renderURL"]. -
Jump to the step labeled Abort update if any of the following conditions hold:
-
renderURL is failure;
-
renderURL scheme is not "
https"; -
renderURL includes credentials .
-
-
Set igAd ’s render url to renderURL .
-
If ad ["
metadata"] exists , then let igAd ’s metadata be the result of serializing a JavaScript value to a JSON string , given ad ["metadata"]. If this throws , jump to the step labeled Abort update . -
Append igAd to ig ’s interestGroupField .
-
-
-
-
"
-
-
Set ig ’s next update after to the current time plus 24 hours.
-
Replace originalInterestGroup with ig in the browser’s interest group set .
-
Abort update : We jump here if some part of the interest group update failed. Continue to the next interest group update.
-
-
7. Permissions Policy integration
This
specification
defines
two
policy-controlled
features
identified
by
the
strings
"
join-ad-interest-group
",
and
"
run-ad-auction
".
Their
default
allowlists
are
"
*
".
Currently
they're
*
.
8. Structures
8.1. Interest group
An interest group is a struct with the following items:
- expiry
-
A point in time at which the browser will forget about this interest group.
- owner
-
An origin . Frames that join interest groups owned by
ownermust either be served from originowner, or another origin delegated byowner(TODO: update to link to delegation section when done).(See checking interest group permissions for details). The scheme must be "https". - name
-
A string . The ( owner , name ) tuple is a key that uniquely defines each interest group.
- priority
-
A
double. Defaulting to 0.0. Used to select which interest groups participate in an auction when the number of interest groups are limited byperBuyerGroupLimits. - enable bidding signals prioritization
-
A boolean . Defaulting to false. Being true if the interest group’s priority should be calculated using vectors from bidding signals fetch.
- priority vector
-
Null or an ordered map whose keys are strings and whose values are
double. Its dot product with theperBuyerPrioritySignalswill be used in place of priority , if set. - priority signals overrides
-
Null or an ordered map whose keys are strings and whose values are
double. Overrides theAuctionAdConfig's corresponding priority signals. - execution mode
-
A string , defaulting to "
compatibility". Acceptable values are "compatibility" and "group-by-origin". - bidding url
-
Null or a URL . The URL to fetch the buyer’s JavaScript from.
The bidding url origin will always be same origin with owner .
- bidding wasm helper url
-
Null or a URL . Lets the bidder provide computationally-expensive subroutines in WebAssembly, in addition to JavaScript, to be driven from the JavaScript function provided by bidding url .
The bidding wasm helper url origin will always be same origin with owner .
- update url
-
Null or a URL . Provides a mechanism for the group’s owner to periodically update the attributes of the interest group. See interest group updates .
The update url origin will always be same origin with owner .
- trusted bidding signals url
-
Null or a URL . Provide a mechanism for making real-time data available for use at bidding time. See building trusted bidding signals url .
Note: The trusted bidding signals url origin will always be same origin with owner .
- trusted bidding signals keys
-
Null or a list of string . See building trusted bidding signals url .
- user bidding signals
-
Null or a string . Additional metadata that the owner can use during on-device bidding.
- ads
-
Null or a list of interest group ad . Contains various ads that the interest group might show.
- ad components
-
Null or a list of interest group ad . Contains various ad components (or "products") that can be used to construct ads composed of multiple pieces — a top-level ad template "container" which includes some slots that can be filled in with specific "products".
- joining origin
-
An origin . The top level page origin from where the interest group was joined.
- join counts
-
A list containing tuple s of the day and per day join count. The day is calculated based on local time. The join count is a count of the number of times
joinAdInterestGroup()was called for this interest group on the corresponding day. - bid counts
-
A list containing tuple s of the day and per day bid count. The day is calculated based on local time. The bid count is a count of the number of times the bid calculated during
runAdAuction()was greater than 0. - previous wins
-
A list containing tuple s of the time and the corresponding interest group ad for each instance that this interest group won an auction.
- next update after
-
A point in time at which the browser will permit updating this interest group.
TODO: Specify the short descriptions of some fields above and below, and add links when runAdAuction() section is ready.
8.2. Interest group ad
An interest group ad is a struct with the following items:
- render url
-
A URL . If this ad wins the auction, this URL (or a urn uuid that maps to this URL) will be returned by
runAdAuction(). This URL is intended to be loaded into an ad iframe (or a fenced frame). - metadata
-
Null or a string . Extra arbitary information about this ad, passed to
generateBid().
8.3. Auction config
An auction config is a struct with the following items:
- seller
-
An origin . The origin of the seller running the ad auction. The scheme must be "
https". - decision logic url
-
A URL . The URL to fetch the seller’s JavaScript from.
The decision logic url origin will always be same origin with seller .
- trusted scoring signals url
-
Null or a URL . Provide a mechanism for making real-time data (information about a specific creative) available for use at scoring time, e.g. the results of some ad scanning system.
The trusted scoring signals url origin will always be same origin with seller .
- interest group buyers
-
Null or a list of origin . Owners of interest groups allowed to participate in the auction. Each origin’s scheme must be "
https". - auction signals
-
Null or a string . Opaque JSON data passed to both sellers' and buyers' script runners.
- seller signals
-
Null or a string . Opaque JSON data passed to the seller’s script runner.
- seller timeout
-
A duration in milliseconds. Defaulting to 50 milliseconds. Restricts the runtime of the seller’s
scoreAd()script. - per buyer signals
-
Null or an ordered map whose keys are origins and whose values are strings . Keys are buyers and must be valid HTTPS origins. Values are opaque JSON data passed to corresponding buyer’s script runner.
- per buyer timeouts
-
Null or an ordered map whose keys are origins and whose values are durations in milliseconds. Keys are buyers and must be valid HTTPS origins. Values restrict the runtime of corresponding buyer’s
generateBid()script. - all buyers timeout
-
A duration in milliseconds. Defaulting to 50 milliseconds. Restricts the
generateBid()script’s runtime for all buyers without a timeout specified in per buyer timeouts . - per buyer group limits
-
Null or an ordered map whose keys are origins and whose values are
unsigned shorts. Keys are buyers and must be valid HTTPS origins. Values restrict the number of bidding interest groups for a particular buyer that can participate in an auction. - all buyers group limit
-
A
unsigned short. Limit on the number of bidding interest groups for all buyers without a limit specified in per buyer group limits . - per buyer priority signals
-
Null or an ordered map whose keys are origins and whose values are ordered maps , whose keys are strings and whose values are
double. Per-buyer sparse vector whose dot product with priority vector is used to calculate interest group priorities. No signal’s key starts with "browserSignals.", which is reserved for values coming from the browser. - all buyers priority signals
-
Null or an ordered map whose keys are strings and whose values are
double. Merged with per buyer priority signals before calculating per-interest group priorities. In the case both have entries with the same key, the entry inper_buyer_priority_signalstakes precedence. No signals key start with "browserSignals.", which is reserved for values coming from the browser. - component auctions
-
A list of auction config s. Nested auctions whose results will also participate in a top level auction. Only the top level auction config can have component auctions.
- seller experiment group id
-
A
unsigned short. Optional identifier for an experiment group to support coordinated experiments with the seller’s trusted server. - per buyer experiment group ids
-
An ordered map whose keys are origins and whose values are
unsigned shorts. Keys are buyers and must be valid HTTPS origins. Values are identifiers for experiment groups, to support coordinated experiments with buyers' trusted servers. - all buyer experiment group id
-
A
unsigned short. Optional identifier for an experiment group to support coordinated experiments with buyers' trusted servers for buyers without a specified experiment group.
8.4. Per buyer bid generator
A per buyer bid generator is an ordered map whose keys are URLs representing trusted bidding signals urls , and whose values are per signals url bid generators .
8.5. Per signals url bid generator
A per signals url bid generator is an ordered map whose keys are origins representing joining origins , and whose values are lists of interest groups .
8.6. Generated bid
The output of running a Protected Audience generateBid() script, which needs to be scored by the seller.
- bid
-
A
double. If the bid is zero or negative, then this interest group will not participate in the auction. - ad
-
A string . JSON string to be passed to the scoring function.
- ad descriptor
-
An ad descriptor . Render URL and size of the bid’s ad.
- ad component descriptors
-
Null or a list of ad descriptors . Ad components associated with bid, if any. May have at most 20 URLs. Must be null if the interest group making this bid has a null ad components field.
- ad cost
-
Null or a
double. Advertiser click or conversion cost passed fromgenerateBid()to reportWin(). Invalid values, such as negative, infinite, and NaN values, will be ignored and not passed. Only the lowest 12 bits will be passed. - modeling signals
-
Null or a
unsigned short. A 0-4095 integer (12-bits) passed toreportWin(), with noising. - interest group
-
An interest group , whose
generateBid()invocation generated this bid. - modified bid
-
Null or a
double. Being null for top level auction. The bid value a component auction’sscoreAd()script returns. - bid duration
-
A duration in milliseconds. How long it took to run the generateBid() script.
8.7. Ad descriptor
The render URL and size of an ad.
- url
-
A URL , which will be rendered to display the creative if this bid wins the auction.
- size
-
Null or an ad size . Defaulting to null.
8.8. Ad size
Width and height of an ad.
- width
-
A
double. - width units
-
A string . Can only be one of "px" (pixel), "sh" (screen height), and "sw" (screen width).
- height
-
A
double. - height units
-
A string . Can only be one of "px" (pixel), "sh" (screen height), and "sw" (screen width).
8.9. Score ad output
The output of running a Protected Audience scoreAd() script.
- desirability
-
A
double. Numeric score of the bid. Must be positive or the ad will be rejected. The winner of the auction is the bid which was given the highest score. - allow component auction
-
A boolean . If the bid being scored is from a component auction and this value is not true, the bid is ignored. This field must be present and true both when the component seller scores a bid, and when that bid is being scored by the top-level auction.
- bid
-
Null or a
double. Is null if the auction has no component auction, or if the auction is a top-level auction. Modified bid value to provide to the top-level seller script. If present, this will be passed to the top-level seller’s scoreAd() and reportResult() methods instead of the original bid, if the ad wins the component auction and top-level auction, respectively.
8.10. Leading bid info
Information of the auction’s leading bid so far when ranking scored bids.
- top score
-
A
double. Defaulting to 0.0. The highest score so far. - top bids count
-
An integer. Defaulting to 0. The number of bids with the same
top score. - leading bid
-
Null or a generated bid . The leading bid of the auction so far.
- auction config
-
An auction config . The auction config of the auction which generated this leading bid .
- second highest score
-
A
double. Defaulting to 0.0. The second highest score so far. - highest scoring other bids count
-
An integer. Defaulting to 0. The number of bids with the same
second highest score. - highest scoring other bid
-
Null or a generated bid . The second highest scoring other bid.
- top level seller
-
Null or a string . The seller in the top level auction. Only set for component auctions, null otherwise.
- top level seller signals
-
Null or a string . Signals from the seller in the top level auction, produced as the output of the top-level seller’s
reportResult()method. Only set for component auctions, null otherwise. - component seller
-
Null or a string . Seller in component auction which generated this leading bid . Only set the top level auction when component auctions are present, null otherwise.
- bidding data version
-
Null or a
unsigned long. Data-Version value from the trusted bidding signals server’s response(s). Will only be not null if the Data-Version header was provided and had a consistent value for all of the trusted bidding signals server responses used to construct the trustedBiddingSignals. - scoring data version
-
Null or a
unsigned long. Data-Version value from the trusted scoring signals server’s response. Will only be not null if the Data-Version header was provided in the response headers from the trusted scoring signals server.
9. Privacy Considerations
Protected Audience aims to advance the privacy of remarketing and custom audience advertising on the web, so naturally privacy considerations are paramount to Protected Audience’s design. Partitioning data by site is the central mechanism to prevent joining a user’s identity across sites:
-
Interest group definitions come from just one site, the site that called
joinAdInterestGroup(). -
Bidding (
generateBid()) and scoring (scoreAd()) scripts are exposed to interest group data from the joining site, and data from the site that will display the ad, but these scripts are run in strict isolation to prevent leaking this cross-site information. -
The browser can enforce that trusted bidding and scoring signals are fetched from servers complying with certain privacy requirements, e.g. not performing event-level logging.
-
Ads are rendered in
fencedframes that isolate them from the surrounding page to prevent cross-site leakage. -
Reporting is strictly controlled by the browser to prevent cross-site leaks: Inputs to event-level reporting functions,
reportWin()andreportResult(), only contain limited cross-site information, e.g. the k-anonymous ad URL. Event-level reporting is meant to be a temporary stepping stone to more private mechanisms like Private Aggregation API .
10. Security Considerations
Protected Audience involves the browser running untrusted JavaScript downloaded from multiple parties, so security concerns are top of mind. Fortunately Protected Audience is a highly constrained API not attempting to be a general purpose execution environment. Execution of this JavaScript is controlled and limited as follows:
-
Protected Audience requires the origin of the scripts’ URLs to match that of the origin of the interest group owner, which is in turn required to match the origin of the context calling the
joinAdInterestGroup(). -
URL schemes are required to be HTTPS.
-
Redirects are disallowed.
-
Responses are required to contain the
X-Allow-Protected-Audience: trueheader. -
Fetches are uncredentialed.
Protected Audience has the browser pass in several “browserSignals” to the bidding script that give the script unforgeable information about the context that the script is being executed in. This way bidders and sellers have the choice to only participate in auctions where they are comfortable working with the involved parties.
The execution environment available to these scripts is the absolute minimum necessary to calculate
a bid. It supports only ECMAScript. It does not support network, storage, timer, date, DOM, Workers, postMessage, Navigator or Window APIs.
Protected Audience adds Permission-Policies to control access to the Protected Audience APIs to give sites and embedders the ability to clamp down on use of the APIs as they see fit.