Minimal sample, in plain HTML and vanilla JavaScript (no framework, no bundler), showing how to integrate the ClickWrap consent widget into a web page and how to send the user's consent on form submit.
It reproduces the pattern used internally in ClickWrap.Web.Sample, simplified and commented
to serve as a reference for anyone integrating ClickWrap into a third-party site.
index.html sample form + widget container
css/style.css styling
js/configFetcher.js reads config.json
js/app.js ClickWrap integration logic
config.json integration parameters (library URL, guid, environment)
-
Configuration.
config.jsonholds three values provided by the ClickWrap backoffice for your agreement:clickwrapLibraryUrl: URL of thenamirial_wrap.jsscript to load at runtime.cwGuid: identifier of the agreement/consent version configured in ClickWrap.environment: which ClickWrap environment to query (e.g.staging,production).
-
Loading the library. The ClickWrap library isn't installed via npm: it's imported as an ES module at runtime from the URL in the configuration:
const { clickWrap } = await import(config.clickwrapLibraryUrl);
-
Rendering the widget.
clickWrap.render(options, selector)mounts the consent text and the required checkboxes inside the element given byselector(in the sample,#namirial__click-wrap). -
Waiting for the render. ClickWrap fires a global
CustomEventnamednamirial-renderAgreementonce the widget is ready. Use it to hide a loading placeholder and avoid showing the user an empty container before the text arrives. -
Validating on submit. Before submitting the form,
clickWrap.isValidCheck(selector)checks that all required checkboxes are ticked. If not, ClickWrap shows its own message (configured viamessageValidation) and the submit is aborted. -
Sending the consent.
clickWrap.sendingConsents(email, true)records the user's consent on the ClickWrap side, associated with the email provided in the form. It's asynchronous (it makes a real network call), so it must beawaited before treating the submission as successful.
All of these steps are commented directly in js/app.js.
npm startOpens the page at http://localhost:8080. config.json already points to a real test
agreement on the demo environment (test-agreement-01, cwGuid
dc79a8ce-606d-44bf-978b-0fcc34e2f7f8), so the sample works right away with no changes.
In the ClickWrap backoffice, open the agreement and go to the Code tab: it shows a
ready-made snippet with clickwrapLibraryUrl (the URL in the import) and cwGuid for that
specific agreement/environment. It's the same snippet reproduced in js/app.js, just using a
dynamic import() instead of a static <script type="module">.
To integrate your own real agreement, replace clickwrapLibraryUrl and cwGuid with the ones
for your environment:
| Environment | clickwrapLibraryUrl |
|---|---|
| demo | https://clickwrap-demo.namirial.app/namirial_library/namirial_wrap.js |
| test | https://clickwrap-test.namirial.app/namirial_library/namirial_wrap.js |
| production | https://clickwrap.namirial.app/namirial_library/namirial_wrap.js |
cwGuid is specific to the agreement configured in the ClickWrap backoffice and differs per
environment/agreement: the ClickWrap team provides it together with the URL above.
- The widget requires
cwGuidto match an agreement actually configured in the given ClickWrap environment: with a non-existent guid, the render never emitsnamirial-renderAgreement. sendingConsentsmakes a network call to the ClickWrap backend: every submission is a real consent record, not a simulated one.- The form fields'
id/namematter. The agreement's Forms Elements tab (in the ClickWrap backoffice) lists the fields the library expects to read from the hosting form (in our test agreement:name,surname,email). The inputs inindex.htmluse these samenameattributes — otherwise ClickWrap can't associate the values with the submitted consent. - The CORS policy on the ClickWrap API side only allows requests from specific origins
(e.g.
*.namirial.appdomains, plus a few whitelisted local ports such ashttp://localhost:8080). If the widget fails to render with a CORS error in the console, the origin you're serving the sample from isn't in that allowlist.