---
title: Databuddy
description: Databuddy is a privacy-focused analytics platform that helps you understand user behavior and track events. It supports cookieless tracking and manages consent automatically through c15t's consent state synchronization.
lastModified: 2025-10-31

icon: databuddy
---
The Databuddy script automatically respects consent preferences by toggling tracking on and off based on the user's consent state.

## Script Implementation

1. **Adding the Databuddy script to c15t**

   import \{ configureConsentManager } from 'c15t';
   import \{ databuddy } from '@c15t/scripts/databuddy';

   configureConsentManager(\{
   &#x20;// ...&#x20;
   &#x20;scripts: \[
   &#x20;databuddy(\{&#x20;
   &#x20;clientId: 'your-client-id',
   &#x20;scriptUrl: 'https\://cdn.databuddy.cc/databuddy.js',
   &#x20;apiUrl: 'https\://basket.databuddy.cc',
   &#x20;options: \{
   &#x20;trackScreenViews: true,
   &#x20;trackOutgoingLinks: true,
   &#x20;}
   &#x20;}),
   &#x20;],
   });import \{ databuddy } from '@c15t/scripts/databuddy';
   import \{ ConsentManagerProvider } from '@c15t/react';

   export function App(\{ children }: \{ children: React.ReactNode }) \{
   &#x20;return (
   &#x20;\<ConsentManagerProvider
   &#x20;options=\{\{
   &#x20;scripts: \[
   &#x20;databuddy(\{&#x20;
   &#x20;clientId: 'your-client-id',
   &#x20;scriptUrl: 'https\://cdn.databuddy.cc/databuddy.js',
   &#x20;apiUrl: 'https\://basket.databuddy.cc',
   &#x20;options: \{
   &#x20;trackScreenViews: true,
   &#x20;trackOutgoingLinks: true,
   &#x20;}
   &#x20;}),
   &#x20;],
   &#x20;}}
   &#x20;\>
   &#x20;\{children}
   &#x20;\</ConsentManagerProvider>
   &#x20;);
   }'use client';
   import \{ databuddy } from '@c15t/scripts/databuddy';
   import \{ ClientSideOptionsProvider } from '@c15t/nextjs/client';

   export function ConsentManagerClient(\{ children }: \{ children: React.ReactNode }) \{&#x20;
   &#x20;return (
   &#x20;\<ClientSideOptionsProvider
   &#x20;scripts=\{\[
   &#x20;databuddy(\{&#x20;
   &#x20;clientId: 'your-client-id',
   &#x20;scriptUrl: 'https\://cdn.databuddy.cc/databuddy.js',
   &#x20;apiUrl: 'https\://basket.databuddy.cc',
   &#x20;options: \{
   &#x20;trackScreenViews: true,
   &#x20;trackOutgoingLinks: true,
   &#x20;}
   &#x20;}),
   &#x20;]}
   &#x20;\>
   &#x20;\{children}
   &#x20;\</ClientSideOptionsProvider>
   &#x20;);
   }import \{ databuddy } from '@c15t/scripts/databuddy';
   import \{ ConsentManagerProvider } from '@c15t/nextjs';

   export function App(\{ children }: \{ children: React.ReactNode }) \{
   &#x20;return (
   &#x20;\<ConsentManagerProvider
   &#x20;options=\{\{
   &#x20;scripts: \[
   &#x20;databuddy(\{&#x20;
   &#x20;clientId: 'your-client-id',
   &#x20;scriptUrl: 'https\://cdn.databuddy.cc/databuddy.js',
   &#x20;apiUrl: 'https\://basket.databuddy.cc',
   &#x20;options: \{
   &#x20;trackScreenViews: true,
   &#x20;trackOutgoingLinks: true,
   &#x20;}
   &#x20;}),
   &#x20;],
   &#x20;}}
   &#x20;\>
   &#x20;\{children}
   &#x20;\</ConsentManagerProvider>
   &#x20;);
   }

2. **Using Databuddy in your application** Once initialized, Databuddy is available globally via window\.databuddy or window\.db:

   ```ts
   // Track a custom event
   window.databuddy?.trackCustomEvent('button_clicked', {
     button_id: 'signup',
     page: '/landing'
   });

   // Or use the shorthand
   window.db?.track('purchase_completed', {
     amount: 99.99,
     currency: 'USD'
   });

   // Track a screen view manually
   window.databuddy?.screenView('/dashboard', {
     user_role: 'admin'
   });

   // Set global properties for all events
   window.databuddy?.setGlobalProperties({
     app_version: '1.2.3',
     environment: 'production'
   });
   ```

## How Consent Management Works

The Databuddy integration automatically handles consent management:

1. **Before Script Load**: Sets `window.databuddyConfig.disabled` based on initial consent state
2. **On Consent Grant**: Enables tracking by setting `window.databuddy.options.disabled = false`
3. **On Consent Revoke**: Disables tracking by setting `window.databuddy.options.disabled = true`

This ensures that no tracking occurs without user consent, keeping your analytics privacy-compliant.

## Configuration Options

The `options` parameter allows you to customize Databuddy's behavior:

```ts
databuddy({
  clientId: 'your-client-id',
  scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
  apiUrl: 'https://basket.databuddy.cc', // Optional, defaults to basket.databuddy.cc, change if self-hosting
  options: {
    // Tracking options
    trackScreenViews: true,        // Automatically track page views
    trackOutgoingLinks: true,      // Track clicks on external links
    trackAttributes: false,        // Track data-track attributes on elements
    trackErrors: false,            // Track JavaScript errors
    trackPerformance: true,        // Track performance metrics
    trackWebVitals: false,         // Track Core Web Vitals
  
    
    // Network options
    enableBatching: false,         // Batch events before sending
    batchSize: 10,                 // Events per batch
    batchTimeout: 2000,            // Batch timeout in ms
    samplingRate: 1.0,             // Sample rate (0.0-1.0)
  }
})
```

## Types

### DatabuddyConsentOptions

| Property  | Type                                  | Description                                                                                                                        | Default                                  |  Required  |
| :-------- | :------------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------- | :--------: |
| clientId  | string                                | Your Databuddy client ID.                                                                                                          | -                                        | ✅ Required |
| apiUrl    | string \| undefined                   | Your Databuddy API URL.                                                                                                            | 'https\://basket.databuddy.cc'           |  Optional  |
| scriptUrl | string \| undefined                   | The Databuddy script URL.                                                                                                          | 'https\://cdn.databuddy.cc/databuddy.js' |  Optional  |
| options   | Record\<string, unknown> \| undefined | Additional configuration options for Databuddy.                                                                                    | -                                        |  Optional  |
| script    | any                                   | Override or extend the default script values.&#xA;&#xA;Default values:&#xA;- \`id\`: 'databuddy'&#xA;- \`category\`: 'measurement' | -                                        |  Optional  |

### Script

| Property                   | Type                                              | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Default |  Required  |
| :------------------------- | :------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------ | :--------: |
| id                         | string                                            | Unique identifier for the script                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | -       | ✅ Required |
| src                        | string \| undefined                               | URL of the script to load                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | -       |  Optional  |
| textContent                | string \| undefined                               | Inline JavaScript code to execute                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | -       |  Optional  |
| category                   | HasCondition\<AllConsentNames>                    | Consent category or condition required to load this script                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | -       | ✅ Required |
| callbackOnly               | boolean \| undefined                              | Whether this is a callback-only script that doesn't need to load an external resource.&#xA;When true, no script tag will be added to the DOM, only callbacks will be executed.&#xA;&#xA;This is useful for:&#xA;- Managing consent for libraries already loaded on the page&#xA;- Enabling/disabling tracking features based on consent changes&#xA;- Running custom code when consent status changes without loading external scripts&#xA;&#xA;Example use cases:&#xA;- Enabling/disabling Posthog tracking&#xA;- Configuring Google Analytics consent mode&#xA;- Managing cookie consent for embedded content | false   |  Optional  |
| persistAfterConsentRevoked | boolean \| undefined                              | Whether the script should persist after consent is revoked.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | false   |  Optional  |
| alwaysLoad                 | boolean \| undefined                              | Whether the script should always load regardless of consent state.&#xA;&#xA;This is useful for scripts like Google Tag Manager or PostHog that manage&#xA;their own consent state internally. The script will load immediately and&#xA;never be unloaded based on consent changes.&#xA;&#xA;Note: When using this option, you are responsible for ensuring the script&#xA;itself respects user consent preferences through its own consent management.                                                                                                                                                          | false   |  Optional  |
| fetchPriority              | "high" \| "low" \| "auto" \| undefined            | Priority hint for browser resource loading                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | -       |  Optional  |
| attributes                 | Record\<string, string> \| undefined              | Additional attributes to add to the script element                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | -       |  Optional  |
| async                      | boolean \| undefined                              | Whether to use async loading                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | -       |  Optional  |
| defer                      | boolean \| undefined                              | Whether to defer script loading                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | -       |  Optional  |
| nonce                      | string \| undefined                               | Content Security Policy nonce                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | -       |  Optional  |
| anonymizeId                | boolean \| undefined                              | Whether to use an anonymized ID for the script element, this helps ensure the script is not blocked by ad blockers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | true    |  Optional  |
| target                     | "head" \| "body" \| undefined                     | Where to inject the script element in the DOM.&#xA;- \`'head'\`: Scripts are appended to \`\<head>\` (default)&#xA;- \`'body'\`: Scripts are appended to \`\<body>\`&#xA;&#xA;Use \`'body'\` for scripts that:&#xA;- Need to manipulate DOM elements that don't exist until body loads&#xA;- Should load after page content for performance reasons&#xA;- Are required by third-party services to be in the body&#xA;&#xA;Use \`'head'\` (default) for scripts that:&#xA;- Need to track early page events (analytics)&#xA;- Should be available before page render&#xA;- Most tracking/analytics scripts       | 'head'  |  Optional  |
| onBeforeLoad               | ((info: ScriptCallbackInfo) => void) \| undefined | Callback executed before the script is loaded                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | -       |  Optional  |
| onLoad                     | ((info: ScriptCallbackInfo) => void) \| undefined | Callback executed when the script loads successfully                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | -       |  Optional  |
| onDelete                   | ((info: ScriptCallbackInfo) => void) \| undefined | Callback executed when the script is being unloaded/removed                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | -       |  Optional  |
| onError                    | ((info: ScriptCallbackInfo) => void) \| undefined | Callback executed if the script fails to load                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | -       |  Optional  |
| onConsentChange            | ((info: ScriptCallbackInfo) => void) \| undefined | Callback executed whenever the consent store is changed.&#xA;This callback only applies to scripts already loaded.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | -       |  Optional  |
