Prerequisites
Before installing the SDK, confirm your environment meets the following requirements:- Node.js v12.x or later
- npm 6.x or later, or yarn 1.22.x or later
- Your application must be served over HTTPS (Content Security Policy headers are enforced). Localhost is also supported for development.
- A Tilta account with sandbox access – contact support@tilta.io if you do not have credentials yet.
Installation
1
Add the Web Elements SDK to your project
Choose the installation method that fits your stack:
- Npm
- Yarn
- Script tag (CDN)
2
Add the modal stylesheet
If you plan to use the Modal component, include Tilta’s CSS file so the overlay renders correctly:Place this inside the
<head> tag of your HTML, or import it at the top of your root stylesheet.3
Import the SDK functions
When using the npm or yarn package, import the functions you need at the top of your component or script file:
4
Obtain a session token
Web Elements are authenticated with a short-lived JWT. Request a token from the Tilta API on your server before rendering any element, and pass it to the client. Never generate or store tokens in client-side code.The response contains a
token string – pass this to createWidget or createModal in the next step.Rendering a widget
A Widget renders Tilta’s flow inline within your page. Add a containerdiv to your markup and then call createWidget with the session token.
createWidget is called:
Rendering a modal
A Modal overlays the current page when triggered.createModal returns a toggle function that you attach to any button or event handler.
Make sure the Modal CSS is loaded (see the installation steps above) before
toggle is called for the first time. Without the stylesheet the overlay will not render correctly.Token lifecycle
Tilta session tokens are short-lived JWTs. Keep the following in mind:- Tokens expire after a short period – generate a fresh token for each user session.
- Always generate tokens server-side using your API key, then pass them to the browser.
- If a token expires while the Widget or Modal is open, the user will see an authentication error. Handle this by catching the error event from the SDK and requesting a new token.
Troubleshooting
The widget or modal does not appear on the page
The widget or modal does not appear on the page
Check that the container element (
<div id="tiltaWidget"></div>) exists in the DOM before createWidget is called. If you are using a framework like React, ensure the component has mounted before calling the SDK – use useEffect rather than calling createWidget at the module level.I see a content security policy (CSP) error in the browser console
I see a content security policy (CSP) error in the browser console
Your server’s CSP headers must allow scripts and frames from Tilta’s domains. Add the following to your For local development, also permit
Content-Security-Policy header:localhost in the relevant directives.The modal CSS is not loading
The modal CSS is not loading
Verify that the
<link> tag for modal.css is included in your HTML <head> before the Widget or Modal is initialised. If you are importing CSS via a bundler, make sure the import is not being tree-shaken or conditionally excluded.CreateWidget is not a function
CreateWidget is not a function
If you installed the SDK via npm or yarn, confirm the import path is correct:If you are using the CDN script tag, the functions are available on the global
Tilta object. Check the browser console to confirm the script loaded without errors.The token I pass is immediately rejected
The token I pass is immediately rejected
Tokens must be generated server-side for the correct buyer and environment (sandbox vs. production). Confirm that:
- You are using the right base URL for your environment.
- The
buyer_external_idin the token request matches a registered buyer. - The token is being passed to the SDK immediately after generation and has not expired in transit.