Analytics

Databuddy

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

Integrate with c15t

import { type ReactNode } from 'react';
import { ConsentManagerProvider } from '@c15t/react';
import { databuddy } from '@c15t/scripts/databuddy';

const scripts = [
  databuddy({
    clientId: 'your-client-id',
    scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
    apiUrl: 'https://basket.databuddy.cc',
    configWhenGranted: {
      clientId: 'your-client-id',
      apiUrl: 'https://basket.databuddy.cc',
      disabled: false,
    },
    configWhenDenied: {
      clientId: 'your-client-id',
      apiUrl: 'https://basket.databuddy.cc',
      disabled: true,
    },
  }),
];

export function ConsentProvider({ children }: { children: ReactNode }) {
  return (
    <ConsentManagerProvider
      options={{
        mode: 'hosted',
        backendURL: 'https://your-instance.c15t.dev',
        scripts,
      }}
    >
      {children}
    </ConsentManagerProvider>
  );
}

How c15t loads it

  • Category: measurement (Analytics)
  • Loads when: alwaysLoad — runs on page start regardless of consent state
  • On consent change: c15t toggles window.databuddy.options.disabled so tracking turns on or off without removing the script

Configure the integration

The Databuddy manifest expects explicit initial config objects for the granted and denied consent states:

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
  configWhenGranted: {
    clientId: 'your-client-id',
    apiUrl: 'https://basket.databuddy.cc',
    // 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)
    disabled: false,
  },
  configWhenDenied: {
    clientId: 'your-client-id',
    apiUrl: 'https://basket.databuddy.cc',
    disabled: true,
  }
})

Tracking events in your app

Databuddy is alwaysLoad: true, so the script is in the DOM from page start regardless of consent. window.databuddy is therefore always defined and calls to track, screenView, or setGlobalProperties are safe to make at any time — when measurement consent is denied, c15t flips window.databuddy.options.disabled = true so the SDK becomes a no-op until consent is granted again.

window.databuddy?.track('signup');

You do not need to guard these calls with useConsentManager().has('measurement'), but doing so does no harm if you prefer the symmetry with other vendors.

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.

Types

DatabuddyConsentOptions

Warning: ExtractedTypeTable: Could not extract "DatabuddyConsentOptions" from "./packages/scripts/src/vendors/analytics/databuddy.ts" using base path "/vercel/path0/apps/c15t-docs/.leadtype/c15t". Verify the path/name and that the file is included by your tsconfig.

Loading…

Script

Warning: ExtractedTypeTable: Could not extract "Script" from "./packages/core/src/libs/script-loader/types.ts" using base path "/vercel/path0/apps/c15t-docs/.leadtype/c15t". Verify the path/name and that the file is included by your tsconfig.

Loading…