App
JavaScript
Add the SDK
- 1
Add the SDK using a script tag
This
<script>tag will load Monocle's JavaScript SDK from our CDN and initialize it with your Monocle Publishable Key.html<script async src="https://js.mcl.io/d/mcl.js?tk=<MONOCLE PUBLISHABLE KEY>" id="_mcl"></script>
Session-Level Analysis (Optional)
- 2
Add the monocle-enriched class to your form
By default, Monocle appends the encrypted assessment as a hidden field named
monocleto any form elements that have the classmonocle-enriched.html<form class="monocle-enriched" action="/submit" method="POST"><input type="text" name="name" /><input type="email" name="email" /><button type="submit">Submit</button></form> - 3
Decrypt the assessment
Use the
@spur.us/monocle-backendpackage to decrypt the assessment in your Node.js environment. In this example, we're using anexpressserver.terminalnpm install @spur.us/monocle-backend.envMONOCLE_SECRET_KEY=<your-secret-key>javascriptconst { createMonocleClient } = require("@spur.us/monocle-backend");const express = require("express");var app = express();app.post("/submit", express.urlencoded({ extended: true }), async (req, res) => {const encryptedAssessment = req.body.monocle;try {const monocleClient = await createMonocleClient({secretKey: process.env.MONOCLE_SECRET_KEY,});const decryptedAssessment = await monocleClient.decryptAssessment(encryptedAssessment);// Handle decrypted assessment} catch (error) {// Handle error}});
Related
- Monocle Assessment — Understand the decrypted assessment payload
- Assessment Decryption — Decryption API and backend decryption options