Installation & Setup
Learn how to install and set up the ToughClicks JavaScript SDK in your application.
Installation Methods
NPM Installation (Recommended)
Install the package via npm:
npm install @toughclicks/js-client-sdk
Then import it in your application:
import { ToughClicks, TCDisplayMethod, TCEnvironment } from '@toughclicks/js-client-sdk';
// Import CSS
import '@toughclicks/js-client-sdk/toughclicks.css';
View the package on NPM.
CDN Installation
For quick prototyping or non-bundled applications, use the CDN:
<!-- JavaScript Library -->
<script src="https://cdn.toughclicks.com/lib/{version}/toughclicks.umd.js"></script>
<!-- Optional: Include Default CSS -->
<link rel="stylesheet" href="https://cdn.toughclicks.com/lib/{version}/toughclicks.css" />
Then access ToughClicks from the global namespace:
const { ToughClicks } = window.ToughClicks;
const tc = new ToughClicks(clientToken, packetId);
Importing CSS
The SDK requires CSS to be imported for proper styling.
With Module Bundlers (Vite, Webpack, etc.)
// ES Modules
import '@toughclicks/js-client-sdk/toughclicks.css';
// Or use the full path
import '@toughclicks/js-client-sdk/build/toughclicks.css';
Without Module Bundlers
Reference the CDN version:
<link rel="stylesheet" href="https://cdn.toughclicks.com/lib/{version}/toughclicks.css" />
The CSS is optional if you want complete control over styling, but it provides sensible defaults and required structure for modals and scrollable elements.
Basic Initialization
Single Packet
For simple use cases with one document packet:
import { ToughClicks } from '@toughclicks/js-client-sdk';
const toughClicks = new ToughClicks(
'your-client-token',
'your-packet-id'
);
Multiple Packets
For applications requiring multiple document sets:
import { ToughClicks, TCDisplayMethod } from '@toughclicks/js-client-sdk';
const toughClicks = new ToughClicks(
'your-client-token',
['packet-1-id', 'packet-2-id', 'packet-3-id']
);
Constructor Parameters
new ToughClicks(
token: string, // Your client token
packetIds: string | string[], // Single packet ID or array of packet IDs
debug?: boolean, // Enable debug logging (default: false)
environment?: TCEnvironment, // 'production' or 'staging' (default: 'production')
packetDisplayOptions?: TCPacketDisplayOptions | TCPacketDisplayOptions[], // Display options per packet
globalSettings?: TCGlobalSettings, // Global settings for signer ID and acceptance
getPageContext?: () => object // Custom context provider
)
Parameters Explained
- token (required) - Your client authentication token from the ToughClicks Management Portal
- packetIds (required) - One or more packet IDs to render
- debug (optional) - Set to
truefor detailed console logging during development - environment (optional) - Use
TCEnvironment.stagingfor sandbox testing - packetDisplayOptions (optional) - Single object or array of display configurations for each packet
- globalSettings (optional) - Global settings including
signerIdSelector,signerId, andmanualAcceptance - getPageContext (optional) - Custom function to provide additional context (for testing)
Environment Configuration
Production Environment
Default configuration for live applications:
import { ToughClicks } from '@toughclicks/js-client-sdk';
const tc = new ToughClicks(clientToken, packetId);
Sandbox/Staging Environment
Use the staging environment for testing:
import { ToughClicks, TCEnvironment } from '@toughclicks/js-client-sdk';
const tc = new ToughClicks(
clientToken,
packetId,
true, // Enable debug mode
TCEnvironment.staging // Use staging environment
);
If you're using a ToughClicks sandbox account, you must specify TCEnvironment.staging. See Sandbox Environments for more details.
Debug Mode
Enable debug mode during development to see detailed logging:
const tc = new ToughClicks(
clientToken,
packetId,
true // Enable debug logging
);
// Or enable it later
tc.setDebug(true);
Debug mode logs:
- API requests and responses
- State changes
- Validation events
- Error details
Test Credentials
For testing and development, you can use these public credentials:
const clientToken = '477951a5-069b-401f-ab7f-32db486d5741';
const packetId = '3646a13b-cbd1-482c-9947-460cb74a71f2';
const tc = new ToughClicks(clientToken, packetId);
These test credentials may change at any time. For production use, obtain your own credentials from the ToughClicks Management Portal.
Next Steps
- Learn about basic usage with single packets
- Explore multiple packets for advanced scenarios
- Configure display options to customize behavior
- Set up event listeners for validation and acceptance