Census
⌘K

Resources

  • npm Package
  • GitHub Repository

Features

Census SDK Documentation

Integrate feedback collection, knowledge base, and analytics into your application with the official Census SDK.

npm install @census-ai/census-sdk

Installation

Install the Census SDK using your preferred package manager:

npm install @census-ai/census-sdk
# or
yarn add @census-ai/census-sdk
# or
pnpm add @census-ai/census-sdk

Quick Start

Vanilla JavaScript/TypeScript

import { createCensus } from '@census-ai/census-sdk';

// Initialize the SDK
const census = createCensus({
  apiKey: 'cs_live_your_key_here',
});

// Identify users
await census.identify({
  userId: 'user_123',
  email: 'user@example.com',
  name: 'John Doe',
});

// Submit feedback
await census.submitFeedback({
  type: 'bug_report',
  message: 'The submit button is not working',
});

// Track events
await census.track('button_clicked', { buttonId: 'cta' });

React

import { CensusProvider, FeedbackButton } from '@census-ai/census-sdk/react';

function App() {
  return (
    <CensusProvider
      apiKey="cs_live_your_key_here"
      user={{ userId: 'user_123', email: 'user@example.com' }}
    >
      <YourApp />
      <FeedbackButton position="bottom-right" />
    </CensusProvider>
  );
}

API Reference

createCensus(config)

Creates a new Census client instance.

const census = createCensus({
  apiKey: string;      // Required: Your Census API key
  baseUrl?: string;    // Optional: Custom API base URL
  debug?: boolean;     // Optional: Enable debug logging
});

census.identify(user)

Identify a user for tracking. Call this when a user logs in.

await census.identify({
  userId: string;           // Required
  email?: string;
  name?: string;
  avatarUrl?: string;
  metadata?: object;
  organizationId?: string;
  organizationName?: string;
});

census.submitFeedback(options)

Submit feedback, bug reports, or feature requests.

await census.submitFeedback({
  type: 'feedback' | 'bug_report' | 'feature_request';
  message: string;
  metadata?: object;
});

census.track(eventType, properties)

Track custom analytics events.

await census.track('page_viewed', { page: '/pricing' });
await census.track('button_clicked', { buttonId: 'signup' });

React Components

<CensusProvider>

Wrap your app with this provider to use Census hooks and components.

<CensusProvider
  apiKey="cs_live_xxx"
  user={{ userId: 'user_123' }}
  theme={{ primaryColor: '#6366f1' }}
>
  {children}
</CensusProvider>

<FeedbackButton>

Floating feedback button with modal form.

<FeedbackButton
  position="bottom-right"
  text="Feedback"
  allowedTypes={['feedback', 'bug_report', 'feature_request']}
/>

<KnowledgeBase>

Embeddable knowledge base component.

<KnowledgeBase
  showSearch={true}
  showCategories={true}
/>

React Hooks

useCensus()

Access the Census client directly.

const census = useCensus();
await census.track('event_name');

useFeedback()

Submit feedback with loading/success state.

const { submitFeedback, isSubmitting, isSuccess, error } = useFeedback();

useArticles(options?)

Fetch articles from the knowledge base.

const { articles, isLoading, error } = useArticles({ category: 'guides' });

useRequests(options?)

Fetch the current user's submitted requests.

const { requests, isLoading, refetch } = useRequests();