arrow_back
Back to Tickets
Edit Trouble Ticket
Update the ticket information below
Date Initiated
*
Status
*
Open
Pending
Completed
Terminated
Creator
*
marcus
Priority
*
1
Urgent
Select urgency...
Urgent
Not Urgent
Important
Select importance...
Important
Not Important
Project Name
*
zfrika
Problem
*
1. all the user to select a option and collect data on what options were collected. then create a report that shows th number of times a category was selected. that will show you what feature is most engaging to users. 2. add swimming 3. trouble tickets 4. smart goals 5. prioritize tasks. 6. business directory 7. add kaban table using react.
Question
Root Cause
Notes
track user selection of features. To implement this, you’ll need a function that reads a JSON file, updates the count for a specific feature, and saves it back. Since you are running on a **Node.js** server (as seen in your PM2 logs), we will use the built-in `fs` (File System) module. ### 1. The JSON Structure First, ensure you have a file named `stats.json` in your project root. If it doesn't exist, the function below will create it. ```json { "features": { "google_login": 0, "regular_login": 0, "password_reset": 0 } } ``` --- ### 2. The Tracking Function I've improved the function to be `async` to prevent blocking your server's main thread, which is important for a production app like Zfrika. ```javascript const fs = require('fs').promises; const path = require('path'); async function track_feature_stats(feature_name) { const statsFilePath = path.join(__dirname, 'stats.json'); try { let stats = { features: {} }; // 1. Try to read existing stats try { const data = await fs.readFile(statsFilePath, 'utf8'); stats = JSON.parse(data); } catch (readError) { // If file doesn't exist, we'll start with the empty object console.log("Creating new stats file..."); } // 2. Increment the feature count if (!stats.features[feature_name]) { stats.features[feature_name] = 0; } stats.features[feature_name] += 1; // 3. Save back to JSON await fs.writeFile(statsFilePath, JSON.stringify(stats, null, 4)); console.log(`Stat Updated: ${feature_name} is now ${stats.features[feature_name]}`); } catch (error) { console.error("Error updating feature stats:", error); } } ``` --- ### 3. How to use it in your Routes You can call this function inside your existing controllers or routes to track what your users are doing: **Tracking Google Login:** ```javascript // Inside your Google Callback app.get('/auth/google/callback', async (req, res) => { await track_feature_stats('google_oauth_success'); // ... rest of your code }); ``` **Tracking Regular Login:** ```javascript app.post('/login', async (req, res) => { await track_feature_stats('regular_login_attempt'); // ... rest of your code }); ``` --- ### 4. Improving it for "By Which User" If you want to track **who** used the feature, we should change the structure to store an array of user IDs or a "unique users" count. **Modified Logic for User Tracking:** ```javascript // Add a user_id parameter async function track_feature_stats(feature_name, user_id = 'anonymous') { // ... (read file logic same as above) if (!stats.user_activity) stats.user_activity = {}; // Track total hits stats.features[feature_name] = (stats.features[feature_name] || 0) + 1; // Track specific user usage if (!stats.user_activity[user_id]) stats.user_activity[user_id] = []; stats.user_activity[user_id].push({ feature: feature_name, timestamp: new Date().toISOString() }); // ... (write file logic) } ``` ### Pro-Tip for Zfrika: Since your server is at **92% disk usage**, writing frequently to a JSON file can contribute to disk fragmentation and eventual "disk full" errors. If Zfrika grows, I recommend moving these stats to a **MongoDB collection** instead of a JSON file for better performance. Would you like me to show you the MongoDB version of this function so it's more scalable?
Strategy
Helpful People
Helpful Links
Diagram
Previous Steps
1. add the interface for all the features. 2. and allow people to click on them. 3. then notify them of the date that feature will be available. 4. and ask them if they want to be notified when that feature is ready. this creates engagement and move the0
Next Steps
add how long a user has been on the website. organize the notification based on the pageTitle add the notification concept to track user movement and log their movement when they click on any feature . or on any country. and a category. then learn to trace the users movement through the site to see how long they stayed on the site. and where they lost interested and left the site.
Solution
add the interface for all the features. move the links to my server. 1. add the interface for all the features. 2. and allow people to click on them. 3. then notify them of the date that feature will be available. 4. and ask them if they want to be notified when that feature is ready. this creates engagement and helps you prioritize certain features to release sooner. select which feature you want released sooner.
Insight
Date Resolved
save
Update Ticket
Cancel