Embed a video recorder

As demonstrated in the video above, a quick and easy way to get started with embed codes is in your Capsule Dashboard, by clicking the ··· menu on a Collection, and selecting Embed

Basic Usage

The embed code will render a button on the page, and clicking on that button launches a modal with the Capsule Recorder component, using the configuration from your Capsule.

<div>
  <script>
    (function(c,a,p,s,u,l,e,h){c["_capsuleRecorderIdent"]=p;c[p]=c[p]||function(){
    (c[p].q=c[p].q||[]).push(arguments);e=a.querySelector("script[data-capsule='"+p+"']");
    l=a.currentScript?.parentElement||a.body;if(!e){if(typeof Hls=="undefined"){
    h=a.createElement("script");h.src="https://cdn.jsdelivr.net/npm/hls.js@latest";l.appendChild(h);}
    u=a.createElement("script");u.async=1;u.src=s;u.dataset["capsule"]=p;l.appendChild(u);}}})
    (window,document,"capsuleRecorder","https://embed.capsule.video/recorder.js");
    capsuleRecorder({
        slug: "your-capsule-slug",
        el: document.currentScript.parentElement
    })
</script>
</div>

The slug is your subdomain (e.g. your-capsule-slug.capsule.video) or, in the case of a custom domain, the domain replacing "." with "-" (e.g. www-yourdomain-com). Feel free to use demo-pro for integration testing.

Additional Parameters

Parameters can be added to the Capsule Recorder embed code to control how it behaves. Here's an example with the optional parameters set:

<div>
  <script>
    (function(c,a,p,s,u,l,e,h){c["_capsuleRecorderIdent"]=p;c[p]=c[p]||function(){
    (c[p].q=c[p].q||[]).push(arguments);e=a.querySelector("script[data-capsule='"+p+"']");
    l=a.currentScript?.parentElement||a.body;if(!e){if(typeof Hls=="undefined"){
    h=a.createElement("script");h.src="https://cdn.jsdelivr.net/npm/hls.js@latest";l.appendChild(h);}
    u=a.createElement("script");u.async=1;u.src=s;u.dataset["capsule"]=p;l.appendChild(u);}}})
    (window,document,"capsuleRecorder","https://embed.capsule.video/recorder.js");
    capsuleRecorder({
        slug: "your-capsule-slug",
        el: document.currentScript.parentElement,
        buttonLabel: "Record your response",
        buttonColor: "blue",
        form: {"Name": "John", "Location": "NYC", "Email": "john@example.com"},
        digestCheckbox: "hidden",
        doneHeader: "Thank You",
        doneMessage: "We appreciate you input",
        doneCtaLabel: "Learn More",
        doneCtaUrl: "htts://capsule.video",
        onRecorded: (e) => { console.log(e); },
        onCompleted: (e) => { console.log(e); }
    })
  </script>
</div>

Javascript Callbacks

The Capsule Recorder embed supports deeper page integrations via javascript callbacks. For example, you could use the onRecorded callback after a user submits a video to get the video ID to then render the video player directly on your page Callback functions can be specified as parameters in the embed code and will fire when specific events take place:

onRecorded

As soon as a user records of uploads a video, a javascript Object with a single property (video) is passed to the callback function.

When a video is recorded using the embed, the video property contains a Blob with the encoded video data. If, instead, a video was uploaded by the user, the video property contains a File object. In both cases, these are the "unprocessed" video, just as the user recorded with, without being edited via a Capsule video template.

onCompleted

Below is an JSON representation of the object passed to the callback function at the end of the flow, once the video is processed. Note that if the browser window/tab is closed before the video is processed, the callback will not happen. The duration of video processing depends on the length of the video, but usually completes within handful of seconds of displaying the "Done" step. The callback will still happen even of the modal is closed.

{
    "email":"jane@test.com",
    "formData":["Jane","NYC"],
    "id":"1cyMUT743et2",
    "jobId":"6213eecc8fb44800c360ef97",
    "url":"https://url.to/video.mp4"
}

Advanced Button Styling

If you want to change the style of the standard button beyond the color and the label, this can be done with CSS using Shadow Parts. See example below.

Note that an alternate way to control the style of the button is to use the buttonEl parameter described above. This will use any element on your page as the button, rather than having the embed code render a button for you.

In this example, we set the text color to black, remove the rounded corners, and hide the record icon that normally appears before the label:

<style>
    ::part(capsule-recorder-button) {
        color: black;
        border-radius: 0px;
    }

    ::part(capsule-recorder-button):before {
        display: none;
    }
</style>

Last updated