|
| 1 | +/** |
| 2 | + * Script to check statistics for Adjust data in Countly. |
| 3 | + * |
| 4 | + * This script checks: |
| 5 | + * 1. Number of documents in the adjust collection for the specified app_id |
| 6 | + * 2. Number of users in app_users{APP_ID} collection with custom.adjust_id |
| 7 | + * 3. Number of adjust_install events in the drill collection |
| 8 | + * |
| 9 | + * Location: |
| 10 | + * Place this script in the `bin/scripts` directory of your Countly installation. |
| 11 | + * |
| 12 | + * Usage: |
| 13 | + * 1. Replace the `APP_ID` variable with the desired app's ID. |
| 14 | + * 2. Run the script using Node.js: |
| 15 | + * ``` |
| 16 | + * node /var/countly/bin/scripts/adjust_stats.js |
| 17 | + * ``` |
| 18 | + */ |
| 19 | + |
| 20 | +// Define the APP_ID variable |
| 21 | +const APP_ID = '5ab0c3ef92938d0e61cf77f4'; |
| 22 | + |
| 23 | +const plugins = require('../../plugins/pluginManager.js'); |
| 24 | + |
| 25 | +(async() => { |
| 26 | + console.log(`Checking Adjust statistics for APP_ID: ${APP_ID}`); |
| 27 | + |
| 28 | + try { |
| 29 | + // Connect to countly database |
| 30 | + const db = await plugins.dbConnection("countly"); |
| 31 | + |
| 32 | + // Connect to countly_drill database |
| 33 | + const drillDb = await plugins.dbConnection("countly_drill"); |
| 34 | + |
| 35 | + console.log('Connected to databases successfully.'); |
| 36 | + |
| 37 | + // 1. Check how many documents are in adjust collection for this app_id |
| 38 | + console.log('\n--- Checking adjust collection ---'); |
| 39 | + |
| 40 | + // Define date range for filtering (July 17-22, 2025) |
| 41 | + const startDate = new Date('2025-07-17T00:00:00.000Z'); |
| 42 | + const endDate = new Date('2025-07-22T23:59:59.999Z'); |
| 43 | + console.log(`Date range filter: ${startDate.toISOString()} to ${endDate.toISOString()}`); |
| 44 | + |
| 45 | + const adjustQuery = { |
| 46 | + app_id: APP_ID, |
| 47 | + cd: { |
| 48 | + $gte: startDate, |
| 49 | + $lte: endDate |
| 50 | + } |
| 51 | + }; |
| 52 | + |
| 53 | + const adjustCount = await db.collection('adjust').countDocuments(adjustQuery); |
| 54 | + console.log(`Documents in adjust collection for app_id ${APP_ID} (${startDate.toDateString()} - ${endDate.toDateString()}): ${adjustCount}`); |
| 55 | + |
| 56 | + // 1a. Check unique amount of adjust_id values in adjust collection |
| 57 | + const uniqueAdjustIds = await db.collection('adjust').distinct('adjust_id', adjustQuery); |
| 58 | + console.log(`Unique adjust_id values in adjust collection for app_id ${APP_ID} (${startDate.toDateString()} - ${endDate.toDateString()}): ${uniqueAdjustIds.length}`); |
| 59 | + |
| 60 | + // 1b. Breakdown by event property in adjust collection |
| 61 | + console.log('\n--- Event breakdown in adjust collection ---'); |
| 62 | + const eventBreakdown = await db.collection('adjust').aggregate([ |
| 63 | + { $match: adjustQuery }, |
| 64 | + { $group: { _id: "$event", count: { $sum: 1 } } }, |
| 65 | + { $sort: { count: -1 } } |
| 66 | + ]).toArray(); |
| 67 | + |
| 68 | + console.log('Event breakdown:'); |
| 69 | + eventBreakdown.forEach(item => { |
| 70 | + console.log(` ${item._id}: ${item.count}`); |
| 71 | + }); |
| 72 | + |
| 73 | + // 2. Check how many users in app_users{APP_ID} collection have custom.adjust_id value |
| 74 | + console.log('\n--- Checking app_users collection ---'); |
| 75 | + const appUsersCollection = 'app_users' + APP_ID; |
| 76 | + |
| 77 | + // Use the same date range but convert to seconds for fac field |
| 78 | + const appUsersQuery = { |
| 79 | + 'custom.adjust_id': { $exists: true }, |
| 80 | + fac: { |
| 81 | + $gte: Math.floor(startDate.getTime() / 1000), |
| 82 | + $lte: Math.floor(endDate.getTime() / 1000) |
| 83 | + } |
| 84 | + }; |
| 85 | + |
| 86 | + const usersWithAdjustId = await db.collection(appUsersCollection).countDocuments(appUsersQuery); |
| 87 | + console.log(`Users with custom.adjust_id in ${appUsersCollection} (${startDate.toDateString()} - ${endDate.toDateString()}): ${usersWithAdjustId}`); |
| 88 | + |
| 89 | + // 2a. Check unique custom.adjust_id values in app_users collection |
| 90 | + const uniqueUserAdjustIds = await db.collection(appUsersCollection).distinct('custom.adjust_id', appUsersQuery); |
| 91 | + console.log(`Unique custom.adjust_id values in ${appUsersCollection} (${startDate.toDateString()} - ${endDate.toDateString()}): ${uniqueUserAdjustIds.length}`); |
| 92 | + |
| 93 | + // 3. Check how many adjust_install events are in drill collection |
| 94 | + console.log('\n--- Checking drill collection for adjust_install events ---'); |
| 95 | + const drillCollectionName = 'drill_events'; |
| 96 | + console.log(`Drill collection name: ${drillCollectionName}`); |
| 97 | + |
| 98 | + // Use the same date range but convert to milliseconds for ts field |
| 99 | + const drillQuery = { |
| 100 | + "a": APP_ID, |
| 101 | + "e": "adjust_install", |
| 102 | + ts: { |
| 103 | + $gte: startDate.getTime(), |
| 104 | + $lte: endDate.getTime() |
| 105 | + } |
| 106 | + }; |
| 107 | + |
| 108 | + const adjustInstallEvents = await drillDb.collection(drillCollectionName).countDocuments(drillQuery); |
| 109 | + console.log(`adjust_install events in drill collection (${startDate.toDateString()} - ${endDate.toDateString()}): ${adjustInstallEvents}`); |
| 110 | + |
| 111 | + // 3a. Check unique custom.adjust_id values in drill collection |
| 112 | + const uniqueDrillAdjustIds = await drillDb.collection(drillCollectionName).distinct('custom.adjust_id', drillQuery); |
| 113 | + console.log(`Unique custom.adjust_id values in drill collection (${startDate.toDateString()} - ${endDate.toDateString()}): ${uniqueDrillAdjustIds.length}`); |
| 114 | + |
| 115 | + // Summary |
| 116 | + console.log('\n--- SUMMARY ---'); |
| 117 | + console.log(`APP_ID: ${APP_ID}`); |
| 118 | + console.log(`Date range: ${startDate.toDateString()} - ${endDate.toDateString()}`); |
| 119 | + console.log(`Adjust collection documents: ${adjustCount}`); |
| 120 | + console.log(`Unique adjust_id values: ${uniqueAdjustIds.length}`); |
| 121 | + console.log(`Users with adjust_id: ${usersWithAdjustId}`); |
| 122 | + console.log(`Unique custom.adjust_id values in app_users: ${uniqueUserAdjustIds.length}`); |
| 123 | + console.log(`adjust_install events in drill collection: ${adjustInstallEvents}`); |
| 124 | + console.log(`Unique custom.adjust_id values in drill collection: ${uniqueDrillAdjustIds.length}`); |
| 125 | + |
| 126 | + console.log('\nStatistics check completed.'); |
| 127 | + |
| 128 | + } |
| 129 | + catch (error) { |
| 130 | + console.error('Error during statistics check:', error); |
| 131 | + } |
| 132 | + finally { |
| 133 | + console.log('Terminating the process...'); |
| 134 | + process.exit(0); |
| 135 | + } |
| 136 | +})(); |
0 commit comments