# Custom Analytics Provider

> Extend the checked-in analytics package with your own provider.

*Canonical: https://makerkit.dev/docs/tanstack-prisma/analytics/custom-analytics-provider*

---

The repo ships an extensible analytics manager, but no concrete provider beyond the default `null` service.

## Implement the Interface

Create a provider that satisfies `AnalyticsService`:

```typescript {% title="packages/analytics/src/my-analytics-service.ts" %}
import type { AnalyticsService } from './types';

export class MyAnalyticsService implements AnalyticsService {
  async initialize() {}

  async identify(userId: string, traits?: Record<string, string>) {
    // send identify call
  }

  async trackPageView(path: string) {
    // send page view
  }

  async trackEvent(
    eventName: string,
    eventProperties?: Record<string, string | string[]>,
  ) {
    // send event
  }
}
```

## Register It

Update the client entrypoint:

```typescript {% title="packages/analytics/src/index.ts" %}
import { createAnalyticsManager } from './analytics-manager';
import { MyAnalyticsService } from './my-analytics-service';
import { NullAnalyticsService } from './null-analytics-service';

export const analytics = createAnalyticsManager({
  providers: {
    myProvider: () => new MyAnalyticsService(),
    null: () => NullAnalyticsService,
  },
});
```

If you need server-side tracking too, mirror the change in `packages/analytics/src/server.ts`.

## Notes

- The package is ESM. Use `import`, not CommonJS `require(...)`.
- The manager supports multiple providers, but only the providers you register actually run.
- If no provider is active, calls fall back to the no-op service.
