What It Covers
Advanced Topics:- Identity resolution and linking
- Event batching and queuing
- Offline support
- Performance optimization
- Error handling and retries
- Plugin architecture
- Custom integrations
Identity Resolution
Understanding Identity
DATALYR uses multiple identifiers to track users across sessions and devices: Identity Fields:anonymousId: Persistent anonymous identifier (set by SDK)visitorId: Browser/device visitor ID (Web/Mobile SDKs)userId: Your application’s user ID (after login)distinctId: Resolved ID (userId if available, else anonymousId)
Anonymous Tracking
Web SDK:Linking Anonymous to Known Users
Scenario: User visits site anonymously, then signs up. Step 1: Anonymous Tracking (Web SDK)user_456.
Cross-Platform Identity
Web to Server:Aliasing
Use Case: User has multiple IDs (email, phone, external ID).Event Batching
How Batching Works
SDKs batch events for efficiency instead of sending individually. Default Behavior:- Events queued in memory
- Batch sent when
flushAtsize reached - Or when
flushIntervalelapsed - Automatically flushed on page unload/app background
Configuration
Web SDK:Manual Flushing
Force Immediate Send:- Before page navigation
- Before app closes
- After critical events
- Before serverless function exits
Batch Size Optimization
Small Batches (1-5 events):- Real-time tracking
- Low traffic sites
- Critical events
- Default for most sites
- Balanced latency/performance
- High traffic applications
- Bulk imports
- Non-time-sensitive tracking
Offline Support
How Offline Queue Works
SDKs queue events when offline and send when connection restored. Features:- Automatic network detection
- Persistent queue (survives app restart)
- Automatic retry with backoff
- Max queue size limit
Configuration
Web SDK:Handling Offline State
Check Network Status:maxQueueSize, oldest events dropped first.
Performance Optimization
Lazy Loading (Web SDK)
Defer Script Loading:defer attribute to load script without blocking page render.
Reduce Event Volume
Track Selectively:Debounce Frequent Events
Use Super Properties
Instead of Repeating Properties:Increase Batch Size
Error Handling
Automatic Retries
All SDKs retry failed requests automatically. Retry Logic:- Exponential backoff (1s, 2s, 4s, 8s…)
- Max retry attempts configurable
- Client errors (4xx) not retried
- Server errors (5xx) retried
Error Handling
Web SDK:Graceful Degradation
SDKs designed to fail silently without breaking your application.Plugin Architecture (Web SDK)
Custom Plugins
Create Plugin:Plugin Use Cases
Google Analytics Integration:Advanced Patterns
Conditional Tracking
Event Validation
Rate Limiting
Context Enrichment
Testing SDKs
Debug Mode
Enable Debug Logs:Testing Environment
Use Test Workspace:Mock SDK for Tests
Best Practices
Initialize Once: Create single SDK instance and reuse throughout application. Flush Before Exit: Callflush() before page navigation, app close, or function termination.
Use Super Properties:
Set common properties once instead of repeating in every event.
Batch Appropriately:
Balance real-time needs with performance (larger batches = better performance).
Handle Errors:
Wrap tracking in try/catch for critical paths.
Respect Privacy:
Enable Do Not Track, respect user consent, anonymize sensitive data.
Test Thoroughly:
Use debug mode and test workspace during development.
Monitor Queue Size:
Check queue size in high-traffic scenarios to prevent memory issues.