A monetization meta tag manager.
import { monetize } from 'monetizer'
Extracted from the Bemuse monorepo into a standalone repository.
- Simple API to integrate with any frontend library or framework.
- No dependencies.
- Support single page apps.
- Support probabilistic revenue sharing.
- Has TypeScript type definitions bundled.
// Starts monetizing
const stopMonetizing = monetize('$dt.in.th')
// Stops monetizing
stopMonetizing()
function App() {
useEffect(() => monetize('$dt.in.th'), [])
return <Layout><Main /></Layout>
}
If multiple monetization calls are active, it uses probabilistic revenue sharing to divide the revenue.
// 50% chance
monetize('$dt.in.th')
// 50% chance
monetize('$twitter.xrptipbot.com/bemusegame')
You can specify a weight (default weight is 1).
// 33% chance
monetize({ content: '$dt.in.th', weight: 1 })
// 67% chance
monetize({ content: '$twitter.xrptipbot.com/bemusegame', weight: 2 })
You can also specify priority. Higher priority wins.
function App() {
// Default priority is 0
useEffect(() => monetize('$dt.in.th'), [])
return <Layout><Main /></Layout>
}
function Article(props) {
const paymentPointer = props.author.paymentPointer
// Send micropayment to article’s author while viewing author’s article
useEffect(() => monetize({ content: paymentPointer, priority: 1 }), [])
}
Priority ties are probabilistic-revenue-shared.
function Article(props) {
const paymentPointer = props.author.paymentPointer
// 50-50 revenue sharing between article author and site developer
useEffect(() => monetize({ content: '$dt.in.th', priority: 1 }), [])
useEffect(() => monetize({ content: paymentPointer, priority: 1 }), [])
}
Registers a candidate for monetization.
options
can be a string that specifies the payment pointer, or an object with these properties:content: string
Payment pointerweight?: number
Weight for probabilistic revenue sharing (default=1)priority?: number
Priority (default=0)
Returns a function
that, when called, removes the candidate from the registry.
When there are multiple monetization candidates in the registry, the library will choose a winner using these criteria:
- A candidate with the highest priority wins.
- If there are multiple candidates with the highest priority, a winner will be chosen using weighted random to achieve probabilistic revenue sharing.
This project was bootstrapped with TSDX.
Below is a list of commands you will probably find useful.
Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.
Your library will be rebuilt if you make edits.
Bundles the package to the dist
folder.
The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).
Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.