From 2c03cecbb136305c592bc467ffa92e313e3e1616 Mon Sep 17 00:00:00 2001 From: Vishnu Gp Date: Tue, 9 Aug 2022 18:35:00 +0530 Subject: [PATCH] feat: Added more data to existing analytics events (#15684) * feat: added more data to existing analytics events * Added extra audit data points for page and action events * Corrected minor comment issue * Review changes * Removed audit references in variable names * Review changes related to sending analytics events and DB optimization --- .../appsmith/server/constants/FieldName.java | 6 ++++- .../services/ce/AnalyticsServiceCEImpl.java | 7 +++--- .../ce/ApplicationPageServiceCEImpl.java | 9 +++---- .../services/ce/NewActionServiceCEImpl.java | 25 +++++++++++++++---- .../ce/ApplicationForkingServiceCEImpl.java | 11 +++++--- .../ImportExportApplicationServiceCEImpl.java | 4 +-- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java index eccbf731dd..9f5860bd31 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java @@ -115,7 +115,11 @@ public class FieldName { public static final String THEME = "theme"; public static final String EDIT_MODE_THEME = "editModeTheme"; public static final String FLOW_NAME = "flowName"; - public static final String AUDIT_DATA = "auditData"; + public static final String EVENT_DATA = "eventData"; public static final String MODE_OF_LOGIN = "modeOfLogin"; public static final String FORM_LOGIN = "FormLogin"; + public static final String VIEW_MODE = "viewMode"; + public static final String ACTION_EXECUTION_REQUEST = "actionExecutionRequest"; + public static final String ACTION_EXECUTION_RESULT = "actionExecutionResult"; + public static final String ACTION_EXECUTION_TIME = "actionExecutionTime"; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/AnalyticsServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/AnalyticsServiceCEImpl.java index 6e4d4fc339..b706453174 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/AnalyticsServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/AnalyticsServiceCEImpl.java @@ -164,7 +164,8 @@ public class AnalyticsServiceCEImpl implements AnalyticsServiceCE { return Mono.just(object); } - final String eventTag = event.getEventName() + "_" + object.getClass().getSimpleName().toUpperCase(); + // In case of action execution, event.getEventName() only is used to support backward compatibility of event name + final String eventTag = AnalyticsEvents.EXECUTE_ACTION.equals(event) ? event.getEventName() : event.getEventName() + "_" + object.getClass().getSimpleName().toUpperCase(); // We will create an anonymous user object for event tracking if no user is present // Without this, a lot of flows meant for anonymous users will error out @@ -197,8 +198,8 @@ public class AnalyticsServiceCEImpl implements AnalyticsServiceCE { analyticsProperties.put("oid", object.getId()); if (extraProperties != null) { analyticsProperties.putAll(extraProperties); - // To avoid sending extra audit data to analytics - analyticsProperties.remove(FieldName.AUDIT_DATA); + // To avoid sending extra event data to analytics + analyticsProperties.remove(FieldName.EVENT_DATA); } sendEvent(eventTag, username, analyticsProperties); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java index f7689c08f2..0c981155af 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ApplicationPageServiceCEImpl.java @@ -1117,7 +1117,7 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE { private Mono sendCloneApplicationAnalyticsEvent(Application sourceApplication, Application application) { return workspaceService.getById(application.getWorkspaceId()) .flatMap(workspace -> { - final Map auditData = Map.of( + final Map eventData = Map.of( FieldName.SOURCE_APPLICATION, sourceApplication, FieldName.APPLICATION, application, FieldName.WORKSPACE, workspace @@ -1127,7 +1127,7 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE { FieldName.SOURCE_APPLICATION_ID, sourceApplication.getId(), FieldName.APPLICATION_ID, application.getId(), FieldName.WORKSPACE_ID, workspace.getId(), - FieldName.AUDIT_DATA, auditData + FieldName.EVENT_DATA, eventData ); return analyticsService.sendObjectEvent(AnalyticsEvents.CLONE, application, data); @@ -1145,13 +1145,12 @@ public class ApplicationPageServiceCEImpl implements ApplicationPageServiceCE { return Mono.empty(); } - //TODO: Add more audit data - final Map auditData = Map.of( + final Map eventData = Map.of( FieldName.PAGE, newPage ); final Map data = Map.of( - FieldName.AUDIT_DATA, auditData + FieldName.EVENT_DATA, eventData ); return analyticsService.sendObjectEvent(AnalyticsEvents.VIEW, newPage, data); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewActionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewActionServiceCEImpl.java index 7415fc81fa..2cf58f35f5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewActionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/NewActionServiceCEImpl.java @@ -990,13 +990,15 @@ public class NewActionServiceCEImpl extends BaseService eventData = Map.of( + FieldName.ACTION, action, + FieldName.DATASOURCE, datasource, + FieldName.VIEW_MODE, viewMode, + FieldName.ACTION_EXECUTION_RESULT, actionExecutionResult, + FieldName.ACTION_EXECUTION_TIME, timeElapsed, + FieldName.ACTION_EXECUTION_REQUEST, request, + FieldName.APPLICATION, application, + FieldName.PLUGIN, plugin + ); + data.put(FieldName.EVENT_DATA, eventData); + analyticsService.sendObjectEvent(AnalyticsEvents.EXECUTE_ACTION, action, data); return request; }) .onErrorResume(error -> { @@ -1860,7 +1872,10 @@ public class NewActionServiceCEImpl extends BaseService analyticsProperties = this.getAnalyticsProperties(savedAction); + Map eventData = Map.of(FieldName.DATASOURCE, datasource); + analyticsProperties.put(FieldName.EVENT_DATA, eventData); + return analyticsProperties; } @Override diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationForkingServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationForkingServiceCEImpl.java index 6bd2395f3d..72bb85cb9a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationForkingServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationForkingServiceCEImpl.java @@ -22,6 +22,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -47,11 +48,14 @@ public class ApplicationForkingServiceCEImpl implements ApplicationForkingServic Mono userMono = sessionUserService.getCurrentUser(); + // For collecting all the possible event data + Map eventData = new HashMap<>(); Mono forkApplicationMono = Mono.zip(sourceApplicationMono, targetWorkspaceMono, userMono) .flatMap(tuple -> { final Application application = tuple.getT1(); final Workspace targetWorkspace = tuple.getT2(); final User user = tuple.getT3(); + eventData.put(FieldName.WORKSPACE, targetWorkspace); //If the forking application is connected to git, do not copy those data to the new forked application application.setGitApplicationMetadata(null); @@ -76,7 +80,7 @@ public class ApplicationForkingServiceCEImpl implements ApplicationForkingServic final String newApplicationId = applicationIds.get(0); return applicationService.getById(newApplicationId) .flatMap(application -> - sendForkApplicationAnalyticsEvent(srcApplicationId, targetWorkspaceId, application)); + sendForkApplicationAnalyticsEvent(srcApplicationId, targetWorkspaceId, application, eventData)); }); // Fork application is currently a slow API because it needs to create application, clone all the pages, and then @@ -116,14 +120,15 @@ public class ApplicationForkingServiceCEImpl implements ApplicationForkingServic .map(responseUtils::updateApplicationWithDefaultResources); } - private Mono sendForkApplicationAnalyticsEvent(String applicationId, String workspaceId, Application application) { + private Mono sendForkApplicationAnalyticsEvent(String applicationId, String workspaceId, Application application, Map eventData) { return applicationService.findById(applicationId, AclPermission.READ_APPLICATIONS) .flatMap(sourceApplication -> { final Map data = Map.of( "forkedFromAppId", applicationId, "forkedToOrgId", workspaceId, - "forkedFromAppName", sourceApplication.getName() + "forkedFromAppName", sourceApplication.getName(), + FieldName.EVENT_DATA, eventData ); return analyticsService.sendObjectEvent(AnalyticsEvents.FORK, application, data); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java index d2802975ac..117370464e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java @@ -2116,7 +2116,7 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica .flatMap(tuple -> { Application application = tuple.getT1(); Workspace workspace = tuple.getT2(); - final Map auditData = Map.of( + final Map eventData = Map.of( FieldName.APPLICATION, application, FieldName.WORKSPACE, workspace ); @@ -2124,7 +2124,7 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica final Map data = Map.of( FieldName.APPLICATION_ID, application.getId(), FieldName.WORKSPACE_ID, workspace.getId(), - FieldName.AUDIT_DATA, auditData + FieldName.EVENT_DATA, eventData ); return analyticsService.sendObjectEvent(event, application, data);