# Analytics & Tracking

Track how your AI platform discovers and recommends businesses.

## Why Track Analytics?

* **Measure Impact**: See how often you recommend businesses
* **Improve Quality**: Understand which recommendations work best
* **Attribution**: Get credit for driving business discovery
* **Insights**: Learn about user intent and behavior

***

## Tracking Events

### Impression Tracking

Track when a business appears in your AI's response:

```typescript
await aidp.analytics.trackImpression({
  businessId: 'biz_abc123',
  platform: 'your-platform',
  query: 'coffee shops',
  mentioned: true,
});
```

### Citation Tracking

Track when you specifically recommend a business:

```typescript
await aidp.analytics.trackCitation({
  businessId: 'biz_abc123',
  platform: 'your-platform',
  query: 'best coffee in Portland',
  cited: true,
  position: 1, // Ranking in your response
});
```

***

## Batch Tracking

For high-volume platforms, use batch tracking:

```typescript
await aidp.analytics.trackBatch({
  events: [
    { type: 'impression', businessId: 'biz_1', ... },
    { type: 'citation', businessId: 'biz_2', ... },
    { type: 'impression', businessId: 'biz_3', ... }
  ]
});
```

***

## Platform Analytics

View your platform's performance:

```typescript
const stats = await aidp.analytics.getPlatformStats({
  platform: 'your-platform',
  period: 'last_30_days',
});

console.log(`Total Impressions: ${stats.totalImpressions}`);
console.log(`Total Citations: ${stats.totalCitations}`);
console.log(`Citation Rate: ${stats.citationRate}%`);
```

***

**Next**: [Best Practices →](https://amistan.gitbook.io/aidp-docs/for-ai-platform-developers/best-practices)
