Skip to content

Instantly share code, notes, and snippets.

@sharafian
Last active February 14, 2020 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharafian/727af729cb96cf52778a6fef54243573 to your computer and use it in GitHub Desktop.
Save sharafian/727af729cb96cf52778a6fef54243573 to your computer and use it in GitHub Desktop.
Probabilistic Revshare Example
// Define your revenue share here.
// If these weights add to 100 then they represent the percent each pointer gets.
const pointers = {
'$alice.example': 50,
'$bob.example': 40,
'$connie.example': 9.5,
'$dave.example': 0.5
}
function pickPointer () {
const sum = Object.values(pointers).reduce((sum, weight) => sum + weight, 0)
let choice = Math.random() * sum
for (const pointer in pointers) {
const weight = pointers[pointer]
if ((choice -= weight) <= 0) {
return pointer
}
}
}
window.addEventListener('load', () => {
const monetizationTag = document.createElement('meta')
monetizationTag.name = 'monetization'
monetizationTag.content = pickPointer()
document.head.appendChild(monetizationTag)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment