Custom Client
Implement your own consent storage solution with a custom client for ultimate flexibility and control
The custom client mode gives you complete control over how consent decisions are stored and retrieved, allowing for integration with any storage backend or custom logic.
Key Characteristics
- Maximum flexibility - Design a storage solution that meets your specific requirements
- Full integration - Connect with existing user data systems or authentication services
- Complete control - Implement custom caching, batching, or synchronization mechanisms
- Advanced use cases - Support for complex scenarios like multi-tenant applications
The custom client mode is the most flexible but also the most complex implementation option. Only use it if you need complete control over consent handling.
Implementation
Create Custom Endpoint Handlers
You must implement all three core handlers: showConsentBanner
, setConsent
, and verifyConsent
.
First, create handlers for the required endpoints:
Configure the Provider with Custom Client
Custom Handler Interface
Each handler must return a Promise that resolves to a ResponseContext
object with the appropriate data structure.
Each handler function must implement the EndpointHandler
interface, which returns a Promise resolving to a ResponseContext
object:
Required Endpoint Handlers
Your custom client must implement three core endpoint handlers:
1. showConsentBanner
Determines if the consent banner should be displayed to the user.
2. setConsent
Saves user consent preferences.
3. verifyConsent
Checks if existing consent meets required criteria.
Advanced Features
Dynamic Handlers
Dynamic handlers allow you to extend the client's functionality beyond the core consent operations.
You can register additional custom endpoint handlers for specialized functionality:
Error Handling
Proper error handling is essential for custom clients to ensure your application behaves predictably.
Custom handlers should handle errors and return appropriate response contexts:
Integration with External Systems
Custom clients can seamlessly integrate with third-party consent management systems:
Use Cases
Integration with Existing Systems
If your organization already has a consent management system, custom handlers provide a bridge between it and c15t's UI components.
A/B Testing Consent Flows
Hybrid Storage Approach
A hybrid approach can give you the best of both worlds: local storage for reliability and remote storage for analytics.
With External Consent Management Platform
When to Use Custom Client
Consider using the custom client mode when:
- You need to integrate with an existing user data system
- You have complex consent storage requirements
- You want to implement advanced features like batching or caching
- You're integrating with an external consent management platform
- You need to support multi-tenant applications
- You're implementing a hybrid online/offline strategy
For simpler use cases, consider Server-Based Storage or Offline Mode instead.
Next Steps
Offline Mode
Store consent decisions in the browser with offline mode, perfect for sites without backend requirements
useConsentManager
The useConsentManager hook provides access to the complete consent management API, allowing you to interact with and control the consent state throughout your application.