Provide exclusive content
Give your paying visitors access to exclusive content when the monetization
event fires. Since the monetization
event only fires when an outgoing payment request is successfully created, your exclusive content only appears to web monetized visitors.
Example 1 - Simple
The example below illustrates a simple way to show exclusive content to web monetized visitors.
How it works
First, we want to check whether Web Monetization is supported. We do this by calling supports()
on a link element’s relList
and passing "monetization"
as a parameter. If this check doesn’t exist, we can’t listen for the monetization
event to tell us when Web Monetization initializes.
Next, we add an event listener to the link
element. The monetization
event is emitted when Web Monetization initializes.
Finally, we select the exclusive content element we want to make available to web monetized visitors. Since we defined a CSS class to hide the content, removing the class will make the content appear.
Interactive example
This example simulates hiding and showing exclusive content based on a visitor’s Web Monetization state.
The example doesn’t require you to have Web Monetization enabled in your browser and no real payments are occurring.
Click View as Web Monetized/non-Web Monetized visitor to toggle your monetization state. If source files appear instead of the example, click View App in the bottom-right corner.
Example 2 - Complex
In reality, you’ll probably want your site to do more than simply show and hide content. In this example, we illustrate how to:
- Show web monetized visitors an indicator while they wait for Web Monetization to initialize
- Tell non-web monetized visitors that there’s exclusive content they’re missing out on
The example below covers three states for showing:
- A call-to-action to non-web monetized visitors
- A loading message to web monetized visitors
- Exclusive content to web monetized visitors
How it works
There are three functions to activate the three states:
showLoading
displays the loadershowCTA
displays the call-to-action to non-web monetized usersshowExclusiveContent
displays the exclusive content to web monetized users
These functions work just like the simple example where we turn the hidden
class on/off for our div
s.
When the page loads, we’ll check whether the visitor is web monetized.
The loader will appear to web monetized visitors and the CTA will appear to everyone else.
If the visitor is web monetized, we’ll listen for the monetization
event that occurs when an outgoing payment request is successfully created. When this event fires, the exclusive content will appear and the other div
s will be hidden.
Interactive example
This example simulates hiding and showing exclusive content based on a visitor’s Web Monetization state. Web monetized visitors will see exclusive content while non-web monetized users will not. Conversely, non-web monetized users will see the message, “Please install a Web Monetization extension to support me!“.
The example doesn’t require you to have Web Monetization enabled in your browser and no real payments are occurring.
Click View as Web Monetized/non-Web Monetized visitor to toggle your monetization state. If source files appear instead of the example, click View App in the bottom-right corner.