A Fledge JavaScript polyfill.
npm install --save @magnite/fledge.polyfill
As of this moment, the polyfill is intended to work within the Chrome browser at a version greater than 91. There are several ways to invoke the polyfill, but given the modern capabilities of support required, the following is the recommended way to invoke the API.
Even though the examples below point to a node_modules
directory, you should probably have a build process in place that compiles it to your preferred sites location.
<script type="module">
import Fledge from "./node_modules/@magnite/fledge.polyfill/dist/api/esm/index.js";
const fledge = new Fledge();
const options = {
owner: "www.buyer.com",
name: "an-interest-group",
biddingLogicUrl: "https://dsp.com/bidding",
};
// join an interest group
await fledge.joinAdInterestGroup(options, 864000000);
// leave an interest group
await fledge.leaveAdInterestGroup(options);
</script>
<script type="module">
import Fledge from "./node_modules/@magnite/fledge.polyfill/dist/api/esm/index.js";
const fledge = new Fledge();
const options = {
seller: "www.seller.com",
decisionLogicUrl: "https://ssp.com/auction",
interestGroupBuyers: [
"www.buyer1.com",
"www.buyer2.com",
],
};
const auctionResults = await fledge.runAdAuction(options);
</script>
In the future, rendering an ad will be handled by the Fledge API and would be passed to a Fenced Frame (which hasn't be established yet). In the polyfill world, we don't have access to a Fenced Frame and so its required for the consumer of this library to create their own iframe
and pass the results from the auction to it. Thankfully, we've created a temporary feature for you to handle this in a way that respects the intention of the proposal by keeping the results opaque in the form of a token that represents the winning ad renderingUrl
.
<script type="module">
import Fledge from "./node_modules/@magnite/fledge.polyfill/dist/api/esm/index.js";
const fledge = new Fledge();
// ...run the auction; see above for full example
const auctionResults = await fledge.runAdAuction(options);
// create an iframe within the Fledge auction iframe, render the winning ad
const ad = document.createElement('iframe');
ad.src = auctionResults;
document.getElementById('ad-slot-1').appendChild(ad);
</script>
The best way to find out what's available is to dig through source code, but the following is the API documentation.
Returns null
if no winning bid is found. Returns a Promise
with a token representation of the winning bids rendering URL.
If an invalid option is passed, then an Error
will be thrown with a reason to help debug.
Type: <Object>
The following is the data structure with types for the options:
interface AuctionOptions {
seller: typeof string;
decisionLogicUrl: typeof url;
interestGroupBuyers: typeof array;
trustedScoringSignalsUrl?; typeof url;
additionalBids?: typeof array;
auctionSignals?: typeof object;
sellerSignals?: typeof object;
perBuyerSignals?: typeof object;
}
Returns true
and creates an entry in a cross-domain Indexed dB store.
If an invalid option is passed, then an Error
will be thrown with a reason to help debug.
Type: <Object>
The following is the data structure with types for the options:
interface InterestGroup {
owner: typeof string;
name: typeof string;
biddingLogicUrl: typeof url;
dailyUpdateUrl?: typeof url;
trustedBiddingSignalsUrl?; typeof url;
trustedBiddingSignalsKeys?: typeof array;
userBiddingSignals?: typeof object;
ads?: typeof array;
}
Type: <Number>
A number of days (set in milliseconds) that the Interest Group will stay active, with a maximum of 30 days (or 2592000000).
Returns true
and removes an entry in a cross-domain Indexed dB store.
If an invalid option is passed, then an Error
will be thrown with a reason to help debug.
Type: <Object>
The following is the data structure with types for the options:
interface InterestGroup {
owner: typeof string;
name: typeof string;
biddingLogicUrl?: typeof url;
dailyUpdateUrl?: typeof url;
trustedBiddingSignalsUrl?; typeof url;
trustedBiddingSignalsKeys?: typeof array;
userBiddingSignals?: typeof object;
ads?: typeof array;
}
This project uses a CHANGELOG and GitHub releases which contains a curated, chronologically ordered list of notable changes for each version of a project. Read more about changelogs.
We use SemVer for its versioning providing us an opt-in approach to releases. This means we add a version number according to the spec, as you see below. So rather than force developers to consume the latest and greatest, they can choose which version to consume and test any newer ones before upgrading. Please the read the spec as it goes into further detail.
Given a version number MAJOR.MINOR.PATCH, increment the:
- MAJOR version when you make incompatible API changes.
- MINOR version when you add functionality in a backward-compatible manner.
- PATCH version when you make backward-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
Have a bug or a feature request? Looking to contribute to advance the project? Read our contribution guide or maintenance guide first in order to understand how we do things around here. Or you could look at some of our other guides below:
How do I… (click to expand)
Looking to talk to someone or need some help? Please read our support guidelines.
- CommitLint - Used to ensure our commits follow our standards
- Conventional Changelog - Used to generate our CHANGELOG
- ESLint - Used to lint our JavaScript
- Husky - Used for auto-fixing linting errors on each commit
- Jest - Used for testing our JavaScript and (S)CSS
- Semantic Release - Used for automating and releasing our library
- Conventional Commits - For how we format commit messages
- Contributor Convenant
- Keep a Changelog - For building out a quality CHANGELOG
- Make a README - For building out this README
- SemVer - For versioning this library
©2021 Magnite, Inc. See LICENSE for specifics.