You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 1, 2023. It is now read-only.
You can easily use the approach detailed above to create an ad-free experience on your own site.
113
+
114
+
Once you have [deployed a lock](https://unlock-protocol.com/guides/how-to-create-a-lock/), add the Unlock paywall application JavaScript to your page (see above) and configure it.
115
+
116
+
Finally, add an event handler to capture the change of state between `locked` and `unlocked`; rendering ad components when relevant.
While some tailoring may be required for your specific use case, this should provide a starting point towards utilizing the Unlock Protocol to provide your members with an Ad Free experience.
131
+
132
+
### Locking Media Content
133
+
134
+
We use the same approach again to lock media content (images, videos... etc). Here is an example of how to achieve this. We want to lock up access to [this video](https://ia801602.us.archive.org/11/items/Rick_Astley_Never_Gonna_Give_You_Up/Rick_Astley_Never_Gonna_Give_You_Up.mp4).
135
+
136
+
HTML5 actually makes it very easy to embed any video in a document. Here's what it takes:
For any web page which includes a lock, we use the same approach. First, we load the Paywall script, and then, we set the configuration for it (see above).
145
+
146
+
JavaScript provides us with an API to control the video. We can use that to lock its access. The following sample provides details of how this can work. Note there are multiple ways of doing this; feel free to tinker around!
// Optional: call video.play() to resume the video!
159
+
})
160
+
161
+
162
+
// This assumes there is a single video on the page. Otherwise use class selectors.
163
+
const video = document.querySelector('video');
164
+
video.addEventListener('timeupdate', (event) => {
165
+
// This event gets triggered every time there is an update in the current time.
166
+
// If the video is locked and the time is above previewTime seconds
167
+
if (!isUnlocked && video.currentTime > previewTime) {
168
+
// We stop the video go back to previewTime and pause the video
169
+
video.currentTime = previewTime
170
+
video.pause()
171
+
// We ask the user to get a membership by loading the checkout UI
172
+
unlockProtocol.loadCheckoutModal()
173
+
}
174
+
})
175
+
})();
176
+
</script>
177
+
178
+
```
179
+
180
+
After this, you are all done!
181
+
182
+
_**Note:** This tutorial implements a front-end locking approach, which is possible to circumvent; a determined actor could tinker with the JavaScript console of their web browser and inspect the code to find a workaround. It is absolutely possible to address this using an approach that is more difficult to circumvent, but that requires a back-end integration, which is more advanced and is outside the scope of this tutorial._
0 commit comments