From algolia-pack
Implements Algolia Insights API for click, conversion, view tracking; search analytics; real-time index updates via database change listeners.
How this skill is triggered — by the user, by Claude, or both
Slash command
/algolia-pack:algolia-webhooks-eventsThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Algolia doesn't use traditional webhooks. Instead, it provides the **Insights API** for sending user behavior events (clicks, conversions, views) back to Algolia, and the **Analytics API** for reading search performance data. For keeping your index in sync, you build event-driven pipelines from your database to Algolia.
Algolia doesn't use traditional webhooks. Instead, it provides the Insights API for sending user behavior events (clicks, conversions, views) back to Algolia, and the Analytics API for reading search performance data. For keeping your index in sync, you build event-driven pipelines from your database to Algolia.
algoliasearch v5 installed (Insights client is included)queryID enabled (for click analytics)search-insights npm package for frontend event trackingimport { algoliasearch } from 'algoliasearch';
const client = algoliasearch(process.env.ALGOLIA_APP_ID!, process.env.ALGOLIA_ADMIN_KEY!);
// Enable clickAnalytics to get queryID in search results
const { hits, queryID } = await client.searchSingleIndex({
indexName: 'products',
searchParams: {
query: 'running shoes',
clickAnalytics: true, // Returns queryID for event correlation
},
});
// queryID links this search to subsequent click/conversion events
// The Insights API is built into the algoliasearch client
// Events connect user behavior back to specific search queries
// Track a click on a search result
await client.pushEvents({
events: [{
eventType: 'click',
eventName: 'Product Clicked',
index: 'products',
userToken: 'user-123', // Unique user identifier
queryID: queryID, // From search response
objectIDs: ['product-456'], // What was clicked
positions: [3], // Position in results (1-indexed)
timestamp: Date.now(),
}],
});
// Track a conversion (purchase, add-to-cart)
await client.pushEvents({
events: [{
eventType: 'conversion',
eventName: 'Product Purchased',
index: 'products',
userToken: 'user-123',
queryID: queryID,
objectIDs: ['product-456'],
timestamp: Date.now(),
}],
});
// Track a view (product page visit, no search context)
await client.pushEvents({
events: [{
eventType: 'view',
eventName: 'Product Viewed',
index: 'products',
userToken: 'user-123',
objectIDs: ['product-456'],
timestamp: Date.now(),
}],
});
npm install search-insights
// Frontend: lightweight event tracking
import { default as aa } from 'search-insights';
aa('init', {
appId: 'YourAppID',
apiKey: 'YourSearchOnlyKey', // Search-only key is fine for events
});
// Set user token (anonymous or authenticated)
aa('setUserToken', 'user-123');
// After user clicks a search result
aa('clickedObjectIDsAfterSearch', {
eventName: 'Product Clicked',
index: 'products',
queryID: 'abc123', // From search response
objectIDs: ['product-456'],
positions: [3],
});
// After user converts (purchases)
aa('convertedObjectIDsAfterSearch', {
eventName: 'Product Purchased',
index: 'products',
queryID: 'abc123',
objectIDs: ['product-456'],
});
// The analytics client is part of algoliasearch
const analyticsClient = client.initAnalytics({ region: 'us' });
// Top searches
const { searches } = await client.getTopSearches({
index: 'products',
startDate: '2025-01-01',
endDate: '2025-01-31',
});
searches.forEach(s => console.log(`"${s.search}" — ${s.count} searches, ${s.nbHits} avg hits`));
// Searches with no results (critical for relevance tuning)
const { searches: noResults } = await client.getSearchesNoResults({
index: 'products',
startDate: '2025-01-01',
endDate: '2025-01-31',
});
noResults.forEach(s => console.log(`"${s.search}" — ${s.count} times, 0 results`));
// Click-through rate and conversion rate
const { clickRate, conversionRate } = await client.getClickThroughRate({
index: 'products',
});
console.log(`CTR: ${(clickRate * 100).toFixed(1)}%, CVR: ${(conversionRate * 100).toFixed(1)}%`);
// Real-time index updates from your database change events
// Works with Prisma, Drizzle, Mongoose change streams, PostgreSQL LISTEN/NOTIFY
import { getClient } from './algolia/client';
// Prisma middleware example
prisma.$use(async (params, next) => {
const result = await next(params);
const client = getClient();
if (params.model === 'Product') {
switch (params.action) {
case 'create':
case 'update':
await client.saveObject({
indexName: 'products',
body: {
objectID: result.id,
name: result.name,
price: result.price,
category: result.category,
},
});
break;
case 'delete':
await client.deleteObject({
indexName: 'products',
objectID: params.args.where.id,
});
break;
}
}
return result;
});
| Issue | Cause | Solution |
|---|---|---|
queryID is null | clickAnalytics: true not set | Add to search params |
| Events not appearing in dashboard | Wrong userToken format | Use stable, non-empty string identifiers |
| Analytics shows 0 CTR | Events not correlated | Ensure queryID matches between search and click |
| Sync pipeline losing events | No retry on failure | Add dead-letter queue for failed updates |
For performance optimization, see algolia-performance-tuning.
npx claudepluginhub jeremylongshore/claude-code-plugins-plus-skills --plugin algolia-packProvides expert patterns for Algolia search implementation, indexing strategies, React InstantSearch hooks, relevance tuning, and Next.js SSR integration.
Provides expert patterns for Algolia search implementation, including React InstantSearch hooks, indexing strategies, relevance tuning, and Next.js SSR integration.
Instruments Algolia search client with Prometheus metrics for latency/errors, OpenTelemetry tracing, structured logging, and Grafana dashboards.