webjoy-analytics-mobile
v1.0.1
Published
Mobile analytics SDK for Webjoy - Track installs, sessions, events, and more
Downloads
21
Maintainers
Readme
webjoy-analytics-mobile
Comprehensive mobile analytics SDK for React Native apps. Track installs, sessions, events, screen views, and crashes with just 2 lines of code.
🔐 Security
Your Supabase credentials are SAFE:
- ✅ Anon key is public (protected by Row Level Security)
- ✅ Each project is isolated
- ✅ Clients can only write to their own
project_id - ✅ Service key never exposed
📦 Installation
npm install webjoy-analytics-mobile
# Or with yarn
yarn add webjoy-analytics-mobilePeer Dependencies
npm install @supabase/supabase-js @react-native-async-storage/async-storage react-native-device-info expo-application expo-device🚀 Quick Start
1. Get Your Project ID
Log into your Webjoy dashboard and copy your project ID.
2. Initialize SDK (2 lines!)
// App.tsx or App.js
import { useEffect } from 'react';
import WebjoyAnalytics from 'webjoy-analytics-mobile';
export default function App() {
useEffect(() => {
WebjoyAnalytics.init({
projectId: 'your-project-id-from-dashboard',
supabaseUrl: 'https://your-project.supabase.co',
supabaseKey: 'your-anon-key'
});
}, []);
return <YourApp />;
}That's it! The SDK now automatically tracks:
- ✅ App installs
- ✅ App opens/closes
- ✅ Session duration
- ✅ Daily/Monthly active users
- ✅ Crashes
📊 What Gets Tracked Automatically
App Installs
- First launch only (never duplicated)
- Platform (iOS/Android)
- App version
- OS version
- Device model & brand
- Country code
Sessions
- App opens/closes
- Session duration
- Active users (DAU/MAU)
Crashes
- Unhandled errors
- Stack traces
- Screen where crash occurred
🎯 Manual Tracking (Optional)
Track Custom Events
import WebjoyAnalytics from 'webjoy-analytics-mobile';
// Simple event
WebjoyAnalytics.trackEvent('button_clicked');
// Event with properties
WebjoyAnalytics.trackEvent('purchase_completed', {
amount: 29.99,
item: 'Premium Plan',
currency: 'USD'
});
WebjoyAnalytics.trackEvent('user_signup', {
method: 'email',
plan: 'free'
});Track Screen Views
// In your screen components
import { useEffect } from 'react';
import WebjoyAnalytics from 'webjoy-analytics-mobile';
function HomeScreen() {
useEffect(() => {
WebjoyAnalytics.trackScreen('HomeScreen');
}, []);
return <View>...</View>;
}Track Errors Manually
try {
// Your code
} catch (error) {
WebjoyAnalytics.trackCrash(error);
}⚙️ Configuration Options
WebjoyAnalytics.init({
projectId: 'your-project-id',
supabaseUrl: 'https://your-project.supabase.co',
supabaseKey: 'your-anon-key',
// Optional settings
enableAutoTracking: true, // Auto-track sessions (default: true)
enableCrashReporting: true, // Auto-track crashes (default: true)
debug: false // Enable debug logs (default: false)
});📈 View Analytics
Log into your Webjoy dashboard to see:
- 📥 Total Downloads
- 👥 Daily Active Users (DAU)
- 📊 Monthly Active Users (MAU)
- ⏱️ Average Session Duration
- 📱 Platform Breakdown (iOS vs Android)
- 🎯 Top Events
- 🔥 Most Viewed Screens
- 💥 Crash Reports
🔒 Privacy & GDPR Compliance
- No personal data collected by default
- Device IDs are anonymized
- You control all data (stored in your Supabase)
- Easy to implement data deletion requests
🛠️ Advanced Usage
Get Current Session ID
const sessionId = WebjoyAnalytics.getSessionId();Get Device ID
const deviceId = WebjoyAnalytics.getDeviceId();Clean Up
// Call when unmounting or logging out
WebjoyAnalytics.destroy();📝 TypeScript Support
Fully typed with TypeScript definitions included.
import WebjoyAnalytics, { WebjoyConfig, EventProperties } from 'webjoy-analytics-mobile';🐛 Troubleshooting
"Analytics not initialized"
Make sure you call init() before any other methods.
Data not showing in dashboard
- Check your project ID is correct
- Verify Supabase URL and anon key
- Enable
debug: trueto see logs
Duplicate install tracking
The SDK prevents this automatically using device ID + project ID unique constraint.
📚 Examples
E-commerce App
// Track product views
WebjoyAnalytics.trackEvent('product_viewed', {
productId: '123',
category: 'Electronics',
price: 299.99
});
// Track purchases
WebjoyAnalytics.trackEvent('purchase_completed', {
orderId: 'ORD-456',
total: 299.99,
items: 3
});Social App
// Track posts
WebjoyAnalytics.trackEvent('post_created', {
type: 'photo',
hasCaption: true
});
// Track engagement
WebjoyAnalytics.trackEvent('post_liked', {
postId: '789'
});🤝 Support
Need help? Contact [email protected]
📄 License
MIT
