Code Monkey home page Code Monkey logo

monetizer's Introduction

monetizer

A monetization meta tag manager.

import { monetize } from 'monetizer'

Extracted from the Bemuse monorepo into a standalone repository.

Project goals

  • 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.

Vanilla JS usage

// Starts monetizing
const stopMonetizing = monetize('$dt.in.th')

// Stops monetizing
stopMonetizing()

React usage

function App() {
  useEffect(() => monetize('$dt.in.th'), [])
  return <Layout><Main /></Layout>
}

Probabilistic revenue sharing

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 })

Prioritization

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 }), [])
}

API

monetize(options: MonetizationOptions | string): function

Registers a candidate for monetization.

  • options can be a string that specifies the payment pointer, or an object with these properties:
    • content: string Payment pointer
    • weight?: 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.

Local Development

This project was bootstrapped with TSDX.

Below is a list of commands you will probably find useful.

yarn start

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.

yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.

monetizer's People

Contributors

dtinth avatar

Stargazers

Hammed Babatunde avatar Muescha avatar Brian Faust avatar John Dave Manuel avatar Willy N avatar Resi Respati avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.