[Getting started] How to integrate API PD Measurement?
Requirements and Options to Integrate PD Measurement API
Requirements
PD Measurement requires a unique API key (apiKey).
If you haven’t received your API key, please contact FittingBox Customer Support.
Integration
This integration can be implemented on any web page.
1. Add the script to your page
<head>
...
<script src="https://msrt-integration-api.fittingbox.com/index.js" type="text/javascript"></script>
</head>
2. Add a container element
Add an element with the following ID to the page — this will host the PD Measurement experience when it opens:
<div id="msrt-container"></div>
This container will receive an iframe.
You must define its size in CSS, for example:
#msrt-container { width: 400px; height: 740px; }
3. Initialize PD Measurement
Once the script from step 1 is loaded, a global variable namedMsrt becomes available on the page.Use it to open PD Measurement with the
createWidget function.window.addEventListener("load", function () {
// This example loads PD Measurement automatically on page load.
// To open it via a button, see:
// https://www.fittingbox.com/en/resources/help-center/fc-how-do-i-integrate-the-tool-on-my-website
Msrt.createWidget("msrt-container", {
apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", // Replace with your own API key
});
});
-
The first parameter is the ID of the PD Measurement container (from step 2).
-
The second parameter is an object containing PD Measurement options.
Additional Documentation
Options
|
param |
type |
description |
example |
|---|---|---|---|
|
apiKey |
string |
The API key allowing the use of PD Measurement |
Msrt.createWidget("msrt-container", {
|
|
pdCopyClipboard |
boolean |
Adds a button to copy results to the clipboard at the end of the experience. Useful when results are not retrieved via |
Msrt.createWidget("msrt-container", {
|
onGetResultPd |
callback function (result: {
|
Triggered once the user completes the experience. Returns binocular and (if available) monocular PDs. |
Msrt.createWidget("msrt-container", {
|
|
onTooManyErrors |
callback function () => {}
|
Triggered after three failed attempts. Can be used to handle users who cannot complete the measurement. |
Msrt.createWidget("msrt-container", { |
|
onClose |
callback function () => {}
|
Triggered when the experience is closed (either via the close button or the Finish button). |
Msrt.createWidget("msrt-container", { |
|
darkMode |
boolean |
Enables the dark background theme. If set to See CodePen exemple : here |
Msrt.createWidget("msrt-container", {
|
|
theme |
string |
Customizes color values (in hexadecimal). If any parameter is missing, default colors will be used. See CodePen exemple : here |
theme: {
|
|
disableNpsRating |
boolean | Disables the NPS (user rating) step at the end of the experience. |
Msrt.createWidget("msrt-container", {
|