Module Access Count Statistics
This case uses application listeners in global settings to monitor user module access events. After a user accesses a module, it calls automation to record the module access logs in the module access statistics table. It also cooperates with the dashboard to display module access count statistics.
Effect Display
Operation Steps
1. Prepare Access Record Data Table
The data table structure is as follows:
| Identifier | Field Name | Field Type |
|---|---|---|
| appId | Application ID | Single Line Text |
| appName | Application Name | Single Line Text |
| moduleId | Module ID | Single Line Text |
| moduleName | Module Name | Single Line Text |
| accessCount | Access Count | Integer |
| lastAccessTime | Last Access Time | Date |
| lastAccessUser | Last Access User | Single Line Text |
This data table is used to store access records.
2. Create Application Listener
Open App Designer => Global Settings => Listeners
Create a listener with the following settings:
3. Script Example
This example calls a script to write access data to the statistics table. For multi-application scenarios, you can create a separate statistics application and expose a statistics API, similar to Baidu Statistics. In the script, call this API via HTTP, so that access information from multiple applications can be displayed in one application. Additionally, this example only records access counts and does not record detailed data. If you want more granular statistics on usage, you can log every access.
let event = automatic.getVar("event");
let appId = event.appId;
let moduleId = event.moduleId;
//
let tableName = "moduleStatistics";
//
let record = null;
let oldRecordList = informat.table.queryList(tableName, {
filter: {
conditionList: [
{ fieldId: "appId", opt: "eq", value: appId },
{ fieldId: "moduleId", opt: "eq", value: moduleId },
],
},
});
if (oldRecordList.length === 0) {
record = {
appId: appId,
moduleId: moduleId,
appName: event.eventContent.app.name,
moduleName: event.eventContent.moduleDefine.name,
accessCount: 0,
};
record.id = informat.table.insert(tableName, record);
} else {
record = oldRecordList[0];
}
//
informat.table.update(tableName, {
id: record.id,
lastAccessTime: new Date(),
lastAccessUser: event.eventContent.user.name,
accessCount: record.accessCount + 1,
});
