Skip to content

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:

IdentifierField NameField Type
appIdApplication IDSingle Line Text
appNameApplication NameSingle Line Text
moduleIdModule IDSingle Line Text
moduleNameModule NameSingle Line Text
accessCountAccess CountInteger
lastAccessTimeLast Access TimeDate
lastAccessUserLast Access UserSingle Line Text

This data table is used to store access records.

2. Create Application Listener

  1. Open App Designer => Global Settings => Listeners

  2. 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.

js
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,
});

4. Configure Dashboard

Data Source Settings

Chart Settings