ainamika-sdk
v1.0.5
Published
Advanced AI-powered analytics SDK with error tracking, event management, and real-time insights for web applications
Maintainers
Readme
Ainamika SDK
Ainamika SDK is an advanced AI-powered analytics SDK that provides comprehensive error tracking, event management, and real-time insights for web applications. Built with TypeScript and designed for modern web development.
🚀 Features
- 🤖 AI-Powered Analytics: Intelligent event tracking with AI-generated insights
- 🛡️ Advanced Error Tracking: Comprehensive error capture with stack traces, screenshots, and DOM snapshots
- � Client ID Security: Secure API access with client ID validation to prevent unauthorized usage
- �📊 Real-time Event Tracking: Track user interactions, page views, and custom events
- 🔧 Auto-Configuration: Automatically analyze your DOM and suggest optimal tracking configurations
- ⚡ Web Worker Support: Batched event processing for optimal performance
- 🌐 Offline Support: Queue events when offline and sync when online
- 🎯 Environment Detection: Automatic development/production environment detection
- 📱 Cross-Platform: Works across all modern browsers and frameworks
📦 Installation
npm install ainamika-sdkOr via CDN:
<script src="https://unpkg.com/ainamika-sdk@latest/dist/ainamika-sdk.js"></script>🏁 Quick Start
Basic Usage
import AInamikaSDK from 'ainamika-sdk';
// Initialize the SDK
const analytics = new AInamikaSDK({
apiKey: '',
autoConfig: true,
debug: true,
clientId: 'YOU_WILL_GET_AFTER_SIGINING_UP_IN_DASHBOARD_UNDER_PROFILE',
apiDetails: {
},
workerConfig: {
batchSize: 50, // Increased from 5 to 50
batchInterval: 3000 // Reduced interval to 3 seconds
},
});
// Track custom events
analytics.track('button_click', {
button_id: 'signup-btn',
page: 'landing',
user_id: 'user123'
});
// Track user identification
analytics.setUser('user123');With Error Tracking
const sdk = new AInamikaSDKPro({
apiKey: '',
autoConfig: true,
debug: true,
clientId: 'YOU_WILL_GET_AFTER_SIGINING_UP_IN_DASHBOARD_UNDER_PROFILE',
apiDetails: {
},
workerConfig: {
batchSize: 50, // Increased from 5 to 50
batchInterval: 3000 // Reduced interval to 3 seconds
},
errorTracking: {
enabled: true,
captureScreenshots: true,
captureDomSnapshots: true,
maxStackTraceDepth: 10,
maxErrorsPerSession: 50,
debounceMs: 1000,
enableNetworkTracking: true,
enableConsoleCapture: true
}
});
// Manually capture exceptions
try {
// Your code here
} catch (error) {
analytics.captureException(error, {
context: 'user-action',
severity: 'high'
});
}Auto-Configuration
Ainamika SDK can automatically analyze your DOM structure and generate optimal tracking configurations:
const analytics = new window.AInamikaSDK({
apiKey: '',
autoConfig: true,
debug: true,
clientId: 'YOU_WILL_GET_AFTER_SIGINING_UP_IN_DASHBOARD_UNDER_PROFILE',
apiDetails: {
},
workerConfig: {
batchSize: 50, // Increased from 5 to 50
batchInterval: 3000 // Reduced interval to 3 seconds
},
errorTracking: {
enabled: true,
captureScreenshots: true,
captureDomSnapshots: true,
maxStackTraceDepth: 10,
maxErrorsPerSession: 50,
debounceMs: 1000,
enableNetworkTracking: true,
enableConsoleCapture: true
}
});
// The SDK will automatically:
// 1. Analyze your DOM structure
// 2. Generate tracking configuration via AI
// 3. Attach event listeners to relevant elements
// 4. Track user interactions automatically- Batching & Retry Logic: Batches events and sends them to the backend, with retry logic for failed sends.
- Web Worker Support: Offloads event batching and sending to a web worker for performance and reliability.
- Manual Event Tracking: Supports manual
.track(eventName, properties)calls for custom analytics events. - Flexible API Endpoint: Can send events to a custom API endpoint with custom headers.
- Session & User ID Management: Generates session and user IDs for event context.
- Debug Logging: Optional debug mode for verbose logging in the browser console.
Usage
Include the SDK
<script src="./sdk.js"></script> <script> new AInamikaSDKPro({ apiKey: '', autoConfig: true, debug: true, clientId: 'YOU_WILL_GET_AFTER_SIGINING_UP_IN_DASHBOARD_UNDER_PROFILE', apiDetails: { }, workerConfig: { batchSize: 50, // Increased from 5 to 50 batchInterval: 3000 // Reduced interval to 3 seconds }, errorTracking: { enabled: true, captureScreenshots: true, captureDomSnapshots: true, maxStackTraceDepth: 10, maxErrorsPerSession: 50, debounceMs: 1000, enableNetworkTracking: true, enableConsoleCapture: true } }); </script>Manual Event Tracking
window.AInamikaSDKPro.track('custom_event', { foo: 'bar' });Config Caching
- Configs are cached in localStorage under the key
ainamika_dom_config_cacheby DOM hash. - Configs can also be saved/loaded as a JSON file (if debug mode is enabled).
- Configs are cached in localStorage under the key
Dynamic DOM Support
- The SDK automatically detects DOM changes and fetches/apply new configs as needed.
Batching & Web Worker
- Events are batched and sent in the background using a web worker (if supported).
🔐 Security
Client ID Validation: All SDK requests are secured with client ID validation to prevent unauthorized access.
- Required: Every request must include a valid
clientIdthat is registered with your Ainamika account - Automatic: The SDK automatically includes your client ID in all API requests
- Secure: Invalid or missing client IDs will result in
400error responses - Get Your Client ID: Sign up in the Ainamika dashboard and find your unique client ID under Profile settings
// ✅ Correct - Always provide your registered client ID
const analytics = new AInamikaSDK({
clientId: 'your-registered-client-id-from-dashboard',
// ... other config
});
// ❌ Invalid - Using unregistered client ID will fail
const analytics = new AInamikaSDK({
clientId: 'invalid-or-unregistered-id',
// ... other config
});Advanced
- Custom API Endpoint: Use the
apiDetailsoption to send events to a custom endpoint with custom headers. - Worker Config: Control batch size and interval via
workerConfig. - Debug Mode: Set
debug: truefor verbose logs.
Example AI generated Config
{
"events_to_track": [
{
"element_selector": "button",
"event_type": "click",
"event_name": "user_login_button_click"
},
{
"element_selector": "form",
"event_type": "submit",
"event_name": "form_submit"
}
]
}File Structure
sdk.js: Main SDK logic (compiled from TypeScript)sdk.ts: TypeScript sourceworker.js: Web worker for batching and sending events
Requirements
- Modern browser with ES6 support
- Backend server for config generation and event ingestion
License
MIT
