Multiple Packets
Handle multiple document packets with individual display options for each. This powerful feature allows you to manage different document sets across your application.
Why Multiple Packets?
Multiple packets let you:
- Separate concerns - Keep required legal documents separate from optional marketing consent
- Different display methods - Use scroll for terms, individual for preferences
- Targeted rendering - Render different packets in different parts of your page
- Optional packets - Let users opt into additional agreements
- Flexible UX - Customize display for each document set independently
Basic Multiple Packet Setup
Pass an array of packet IDs instead of a single ID:
import { ToughClicks, TCDisplayMethod } from '@toughclicks/js-client-sdk';
const toughClicks = new ToughClicks(
'your-client-token',
['packet1-id', 'packet2-id', 'packet3-id'] // Array of packet IDs
);
Per-Packet Display Options
Configure display options for each packet individually:
const toughClicks = new ToughClicks(
'your-client-token',
['packet1-id', 'packet2-id', 'packet3-id'],
true, // debug mode
'production', // environment
[
{
packetId: 'packet1-id',
displayOptions: {
containerId: 'packet1-container',
signerIdSelector: 'user-email',
displayMethod: TCDisplayMethod.individual,
shouldOpenModal: true,
manualAcceptance: false
}
},
{
packetId: 'packet2-id',
displayOptions: {
containerId: 'packet2-container',
signerIdSelector: 'user-email',
displayMethod: TCDisplayMethod.group,
shouldOpenModal: false,
manualAcceptance: true
}
},
{
packetId: 'packet3-id',
displayOptions: {
containerId: 'packet3-container',
signerIdSelector: 'user-email',
displayMethod: TCDisplayMethod.scroll,
shouldOpenModal: true,
manualAcceptance: false
}
}
]
);
// Render all packets
toughClicks.render();
Setting Display Options After Initialization
You can also set display options after creating the instance:
For a Single Packet
toughClicks.setPacketDisplayOptions('packet1-id', {
containerId: 'packet1-container',
signerIdSelector: 'user-email',
displayMethod: TCDisplayMethod.individual,
shouldOpenModal: true
});
For Multiple Packets at Once
toughClicks.setAllPacketDisplayOptions([
{
packetId: 'packet1-id',
displayOptions: { /* options */ }
},
{
packetId: 'packet2-id',
displayOptions: { /* options */ }
}
]);
Get Options for a Packet
const options = toughClicks.getPacketDisplayOptions('packet1-id');
Optional Packets
Mark packets as optional to let users opt in without requiring acceptance:
const toughClicks = new ToughClicks(
'your-client-token',
['required-terms', 'optional-marketing'],
true,
'production',
[
{
packetId: 'required-terms',
displayOptions: {
containerId: 'required-container',
signerIdSelector: 'user-email',
displayMethod: TCDisplayMethod.individual,
shouldOpenModal: false,
manualAcceptance: false,
optional: false // Required packet (default)
}
},
{
packetId: 'optional-marketing',
displayOptions: {
containerId: 'optional-container',
signerIdSelector: 'user-email',
displayMethod: TCDisplayMethod.individual,
shouldOpenModal: false,
manualAcceptance: false,
optional: true // Optional packet
}
}
]
);
How Optional Packets Work
- Validation - The
tc-validevent fires when all REQUIRED packets are valid (optional packets don't affect this) - API calls - Only sent for packets that were actually checked by the user
- User experience - Users can proceed with only required packets checked
- Opt-in consent - Perfect for marketing communications, newsletters, etc.
Event Handling with Optional Packets
toughClicks.on('tc-valid', (state) => {
// Fires when all REQUIRED packets are valid
// Optional packets don't affect this validation
console.log('All required packets valid!');
document.getElementById('submit-btn').disabled = false;
});
toughClicks.on('tc-accepted', (state) => {
// Fires when all checked packets are accepted
// Only includes packets the user actually checked
console.log('Packets accepted:', state);
});
Mixed Display Methods Example
Use different display methods for different use cases:
const toughClicks = new ToughClicks(
'token',
['terms-packet', 'privacy-packet', 'consent-packet'],
true,
'production',
[
{
packetId: 'terms-packet',
displayOptions: {
containerId: 'terms-container',
signerIdSelector: 'user-id',
displayMethod: TCDisplayMethod.scroll, // Must scroll through
shouldOpenModal: true,
manualAcceptance: false
}
},
{
packetId: 'privacy-packet',
displayOptions: {
containerId: 'privacy-container',
signerIdSelector: 'user-id',
displayMethod: TCDisplayMethod.group, // Single checkbox for all
shouldOpenModal: false,
manualAcceptance: true
}
},
{
packetId: 'consent-packet',
displayOptions: {
containerId: 'consent-container',
signerIdSelector: 'user-id',
displayMethod: TCDisplayMethod.individual, // Checkbox per document
shouldOpenModal: true,
manualAcceptance: false
}
}
]
);
Complete HTML Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.toughclicks.com/lib/latest/toughclicks.css" />
<style>
.packet-section {
margin: 20px 0;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
}
.required { border-left: 4px solid #e74c3c; }
.optional { border-left: 4px solid #3498db; }
</style>
</head>
<body>
<form id="registration-form">
<label>Email:</label>
<input type="email" id="userEmail" required />
<!-- Required Terms -->
<div class="packet-section required">
<h3>Required: Terms of Service</h3>
<div id="terms-container"></div>
</div>
<!-- Required Privacy -->
<div class="packet-section required">
<h3>Required: Privacy Policy</h3>
<div id="privacy-container"></div>
</div>
<!-- Optional Marketing -->
<div class="packet-section optional">
<h3>Optional: Marketing Communications</h3>
<p>Receive updates about our products and services</p>
<div id="marketing-container"></div>
</div>
<button type="submit" id="submit-btn" disabled>Complete Registration</button>
</form>
<script src="https://cdn.toughclicks.com/lib/latest/toughclicks.umd.js"></script>
<script>
const { ToughClicks, TCDisplayMethod } = window.ToughClicks;
const tc = new ToughClicks(
'your-client-token',
['terms-packet', 'privacy-packet', 'marketing-packet'],
true,
'production',
[
{
packetId: 'terms-packet',
displayOptions: {
containerId: 'terms-container',
signerIdSelector: 'userEmail',
displayMethod: TCDisplayMethod.scroll,
shouldOpenModal: true,
optional: false
}
},
{
packetId: 'privacy-packet',
displayOptions: {
containerId: 'privacy-container',
signerIdSelector: 'userEmail',
displayMethod: TCDisplayMethod.group,
shouldOpenModal: false,
optional: false
}
},
{
packetId: 'marketing-packet',
displayOptions: {
containerId: 'marketing-container',
signerIdSelector: 'userEmail',
displayMethod: TCDisplayMethod.individual,
shouldOpenModal: false,
optional: true // Optional!
}
}
]
);
tc.render();
tc.on('tc-valid', (state) => {
// Enable submit when all required packets are valid
document.getElementById('submit-btn').disabled = !state.allPacketsValid;
});
tc.on('tc-accepted', (state) => {
console.log('Acceptance complete!', state);
alert('Thank you for completing registration!');
});
</script>
</body>
</html>
React Example with Multiple Packets
import { useEffect, useRef, useState } from 'react';
import { ToughClicks, TCDisplayMethod } from '@toughclicks/js-client-sdk';
import '@toughclicks/js-client-sdk/toughclicks.css';
function MultiPacketRegistration() {
const tcRef = useRef(null);
const [email, setEmail] = useState('');
const [isValid, setIsValid] = useState(false);
useEffect(() => {
if (!email) return;
const tc = new ToughClicks(
'your-client-token',
['terms', 'privacy', 'marketing'],
true,
'production',
[
{
packetId: 'terms',
displayOptions: {
containerId: 'terms-container',
signerId: email,
displayMethod: TCDisplayMethod.scroll,
optional: false
}
},
{
packetId: 'privacy',
displayOptions: {
containerId: 'privacy-container',
signerId: email,
displayMethod: TCDisplayMethod.group,
optional: false
}
},
{
packetId: 'marketing',
displayOptions: {
containerId: 'marketing-container',
signerId: email,
displayMethod: TCDisplayMethod.individual,
optional: true // Optional marketing consent
}
}
]
);
tc.on('tc-valid', (state) => {
setIsValid(state.allPacketsValid);
});
tc.render();
tcRef.current = tc;
}, [email]);
return (
<div>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Your email"
/>
<div className="required">
<h3>Required: Terms of Service</h3>
<div id="terms-container"></div>
</div>
<div className="required">
<h3>Required: Privacy Policy</h3>
<div id="privacy-container"></div>
</div>
<div className="optional">
<h3>Optional: Marketing Communications</h3>
<div id="marketing-container"></div>
</div>
<button disabled={!isValid}>
Complete Registration
</button>
</div>
);
}
Verification Across Multiple Packets
Verify user acceptance across all packets:
const results = await toughClicks.verify('user@example.com');
// Results is an array with one entry per packet
results.forEach(result => {
console.log(`Packet ${result.id}:`, result.userCompliant, result.verificationFailed ? '(could not verify)' : '');
});
Migration from Single Packet
If you're upgrading from single-packet to multi-packet:
Before (Single Packet)
const tc = new ToughClicks(token, 'packet-id');
tc.setDisplayOptions({ /* options */ });
After (Multiple Packets)
const tc = new ToughClicks(token, ['packet-id']);
tc.setPacketDisplayOptions('packet-id', { /* options */ });
Backward Compatible
You can still pass a single string packet ID - ToughClicks will handle it as a single-item array internally.
Next Steps
- Learn about display methods (individual, group, scroll)
- Configure display options in detail
- Handle events for validation and acceptance
- Explore manual acceptance for custom flows