Skip to content

Commit

Permalink
Create dataAnalyticsAPI.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 3, 2024
1 parent b31d1d3 commit 98ff184
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/api/dataAnalyticsAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// dataAnalyticsAPI.js

class DataAnalyticsAPI {
constructor() {
this.analyticsData = {
userActivity: [],
transactionStats: [],
};
}

// Log user activity
logUserActivity(userId, activity) {
const activityEntry = {
userId,
activity,
timestamp: new Date(),
};
this.analyticsData.userActivity.push(activityEntry);
console.log(`User activity logged:`, activityEntry);
}

// Log transaction statistics
logTransaction(transaction) {
this.analyticsData.transactionStats.push(transaction);
console.log(`Transaction logged:`, transaction);
}

// Get user activity data
getUserActivity(userId) {
return this.analyticsData.userActivity.filter(entry => entry.userId === userId);
}

// Get transaction statistics
getTransactionStats() {
return this.analyticsData.transactionStats;
}

// Get overall analytics summary
getAnalyticsSummary() {
return {
totalUsers: new Set(this.analyticsData.userActivity.map(entry => entry.userId)).size,
totalTransactions: this.analyticsData.transactionStats.length,
totalActivityLogs: this.analyticsData.userActivity.length,
};
}
}

// Example usage
const analyticsAPI = new DataAnalyticsAPI();
analyticsAPI.logUserActivity('user123', 'Logged in');
analyticsAPI.logUserActivity('user123', 'Made a purchase');
analyticsAPI.logTransaction({ id: 'txn_123456', amount: 100, currency: 'USD', date: new Date() });

const userActivity = analyticsAPI.getUserActivity('user123');
console.log('User Activity for user123:', userActivity);

const transactionStats = analyticsAPI.getTransactionStats();
console.log('Transaction Statistics:', transactionStats);

const analyticsSummary = analyticsAPI.getAnalyticsSummary();
console.log('Analytics Summary:', analyticsSummary);

export default DataAnalyticsAPI;

0 comments on commit 98ff184

Please sign in to comment.