Developer Documentation

Get started with TrustCookie in minutes

Quick Start

5-Minute Setup

Add TrustCookie to your website in just 2 lines of code

Step 1: Add the Script

Add this code before the closing </body> tag of your website:

<!-- TrustCookie Consent Banner -->
<script src="https://api.trustcookie.com/cdn/trustcookie.min.js"></script>
<script>
  TrustCookie.init({
    apiKey: 'YOUR_API_KEY_HERE',
    privacyNoticeVersion: 'V1.0',
    collectionPointId: 'homepage_banner',
    purposes: [
      { id: 'P_NECESSARY', name: 'Essential Cookies', required: true },
      { id: 'P_ANALYTICS', name: 'Analytics & Performance' },
      { id: 'P_MARKETING', name: 'Marketing & Advertising' }
    ]
  });
</script>

Step 2: Get Your API Key

Get your API key from the TrustCookie console:

  1. Sign up for a free account
  2. Add your website domain
  3. Copy your unique API key
  4. Replace YOUR_API_KEY_HERE with your actual key
Get Your API Key →

Configuration Options

OptionTypeDescription
apiKeystringYour website's API key (required)
privacyNoticeVersionstringVersion of your privacy policy
collectionPointIdstringWhere consent is collected (e.g., homepage_banner)
purposesarrayList of consent purposes
positionstring'bottom' or 'top' (default: bottom)
primaryColorstringAccept button color (default: #2563eb)
secondaryColorstringReject button color (default: #6b7280)

Customization Examples

Custom Colors

TrustCookie.init({
  apiKey: 'YOUR_API_KEY',
  primaryColor: '#059669',    // Green
  secondaryColor: '#dc2626',  // Red
  // ... other options
});

Banner at Top

TrustCookie.init({
  apiKey: 'YOUR_API_KEY',
  position: 'top',
  // ... other options
});

Custom Text & Language

TrustCookie.init({
  apiKey: 'YOUR_API_KEY',
  text: {
    b: 'We use cookies to enhance your experience.',
    a: 'Accept All',
    r: 'Reject All',
    c: 'Customize',
    s: 'Save Preferences',
    q: '(Required)'
  },
  // ... other options
});

Event Callbacks

TrustCookie.init({
  apiKey: 'YOUR_API_KEY',
  purposes: [...],
  onAccept: function(consent) {
    // Load analytics if accepted
    var analytics = consent.consents.find(c =>
      c.purpose_id === 'P_ANALYTICS' &&
      c.consent_status === 'Opt-In'
    );

    if (analytics) {
      // Load Google Analytics
      loadAnalytics();
    }
  },
  onReject: function(consent) {
    console.log('User rejected consent');
  }
});

What You Get

Under 8KB (minified & gzipped)
Zero dependencies
GDPR & KVKK compliant
Mobile responsive
Auto consent tracking
Customizable styling

Ready to Get Started?

Sign up now and get your API key in seconds

Start Free Trial →