Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

monetizer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

monetizer

A monetization meta tag manager.

  • 48.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by66.67%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 03 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc