diff --git a/src/main/java/org/broadinstitute/dsm/DSMServer.java b/src/main/java/org/broadinstitute/dsm/DSMServer.java index 6051f0a03..18190bb36 100644 --- a/src/main/java/org/broadinstitute/dsm/DSMServer.java +++ b/src/main/java/org/broadinstitute/dsm/DSMServer.java @@ -539,6 +539,9 @@ private void setupMiscellaneousRoutes() { GetParticipantDataRoute getParticipantDataRoute = new GetParticipantDataRoute(); get(UI_ROOT + RoutePath.GET_PARTICIPANT_DATA, getParticipantDataRoute, new JsonTransformer()); + + FrontendAnalyticsRoute frontendAnalyticsRoute = new FrontendAnalyticsRoute(); + patch(UI_ROOT +RoutePath.GoogleAnalytics, frontendAnalyticsRoute, new JsonTransformer()); } private void setupSharedRoutes(@NonNull KitUtil kitUtil, @NonNull NotificationUtil notificationUtil, diff --git a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java index bd5b4654b..bd8222d87 100644 --- a/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java +++ b/src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java @@ -6,14 +6,12 @@ public class GoogleAnalyticsMetrics { // public static final String EVENT_ACTION_USER_REGISTRATION = "register-user"; // public static final String EVENT_LABEL_USER_REGISTRATION = "registration"; we may need it for FON - public static final String EVENT_CATEGORY_USER_LOGIN = "user-login"; - public static final String EVENT_ACTION_USER_LOGIN = "user-logged-in"; - public static final String EVENT_LABEL_USER_LOGIN = "login"; //studyGuid appended - - public static final String EVENT_CATEGORY_PARTICIPANT_LIST = "participant-list"; + public static final String EVENT_CATEGORY_PARTICIPANT_LIST = "participant-list"; public static final String EVENT_PARTICIPANT_LIST_LOAD_TIME = "participant-list-load-time"; - public static final String EVENT_CATEGORY_DASHBOARD = "dashboard"; + public static final String EVENT_PARTICIPANT_LIST_FRONTEND_LOAD_TIME = "participant-list-load-time_frontend"; + + public static final String EVENT_CATEGORY_DASHBOARD = "dashboard"; public static final String EVENT_DASHBOARD_LOAD_TIME = "dashboard-load-time"; public static final String DASHBOARD_LABEL_SHIPPING_REPORT = ":shipping-report"; public static final String DASHBOARD_LABEL_SHIPPING_DASHBOARD = ":shipping-dashboard"; @@ -27,10 +25,10 @@ public class GoogleAnalyticsMetrics { public static final String EVENT_PATCH_DATA_ANSWERS = "patch-data-answers"; public static final String EVENT_CATEGORY_TISSUE_LIST = "tissue-list"; - public static final String EVENT_TISSUE_LIST_LOADED = "tissue-list-loaded"; + public static final String EVENT_TISSUE_LIST_LOAD_TIME = "tissue-list-load-time"; public static int getTimeDifferenceToNow(Long start){ - return Math.toIntExact((System.currentTimeMillis() - start)/1000); + return (int) Math.ceil((System.currentTimeMillis() - start)/1000); } } diff --git a/src/main/java/org/broadinstitute/dsm/model/ParticipantWrapper.java b/src/main/java/org/broadinstitute/dsm/model/ParticipantWrapper.java index f8e6d9edd..c7d58ee3a 100644 --- a/src/main/java/org/broadinstitute/dsm/model/ParticipantWrapper.java +++ b/src/main/java/org/broadinstitute/dsm/model/ParticipantWrapper.java @@ -7,6 +7,8 @@ import lombok.Data; import lombok.NonNull; import org.apache.commons.lang3.StringUtils; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetrics; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetricsTracker; import org.broadinstitute.dsm.db.*; import org.broadinstitute.dsm.db.dao.ddp.instance.DDPInstanceDao; import org.broadinstitute.dsm.model.at.DefaultValues; @@ -78,6 +80,7 @@ public JsonObject getDataAsJson() { public static List getFilteredList(@NonNull DDPInstance instance, Map filters) { logger.info("Getting list of participant information"); Instant start = Instant.now(); + Long timer = System.currentTimeMillis(); if (StringUtils.isBlank(instance.getParticipantIndexES())) { throw new RuntimeException("No participant index setup in ddp_instance table for " + instance.getName()); @@ -115,6 +118,9 @@ public static List getFilteredList(@NonNull DDPInstance inst List r = addAllData(baseList, participantESData, participants, medicalRecords, oncHistoryDetails, kitRequests, abstractionActivities, abstractionSummary, proxyData, participantData); Duration elapsed = Duration.between(start, Instant.now()); logger.info("Getting all participant information took {} secs ({})", elapsed.getSeconds(), elapsed.toString()); + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(instance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PARTICIPANT_LIST, + GoogleAnalyticsMetrics.EVENT_PARTICIPANT_LIST_LOAD_TIME, GoogleAnalyticsMetrics.EVENT_PARTICIPANT_LIST_LOAD_TIME, GoogleAnalyticsMetrics.getTimeDifferenceToNow(timer)); + return r; } else { @@ -256,6 +262,8 @@ else if (ElasticSearchUtil.PROXY.equals(source)) { List r = addAllData(baseList, participantESData, participants, medicalRecords, oncHistories, kitRequests, abstractionActivities, abstractionSummary, proxyData, participantData); Duration elapsed = Duration.between(start, Instant.now()); logger.info("Getting all participant information took {} secs ({})", elapsed.getSeconds(), elapsed.toString()); + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(instance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_TISSUE_LIST, + GoogleAnalyticsMetrics.EVENT_TISSUE_LIST_LOAD_TIME, GoogleAnalyticsMetrics.EVENT_TISSUE_LIST_LOAD_TIME, GoogleAnalyticsMetrics.getTimeDifferenceToNow(timer)); return r; } } diff --git a/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java b/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java index c5d5f5330..337ffcd4b 100644 --- a/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java +++ b/src/main/java/org/broadinstitute/dsm/model/filter/participant/BaseFilterParticipantList.java @@ -109,14 +109,17 @@ protected List filterParticipantList(Filter[] filters, Map list = ParticipantWrapper.getFilteredList(instance, mergeConditions); GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PARTICIPANT_LIST, GoogleAnalyticsMetrics.EVENT_PARTICIPANT_LIST_LOAD_TIME, GoogleAnalyticsMetrics.EVENT_PARTICIPANT_LIST_LOAD_TIME, GoogleAnalyticsMetrics.getTimeDifferenceToNow(timer)); - //search bar ptL - return ParticipantWrapper.getFilteredList(instance, mergeConditions); + return list; + } else { + List list = ParticipantWrapper.getFilteredList(instance, null); GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_PARTICIPANT_LIST, GoogleAnalyticsMetrics.EVENT_PARTICIPANT_LIST_LOAD_TIME, GoogleAnalyticsMetrics.EVENT_PARTICIPANT_LIST_LOAD_TIME, GoogleAnalyticsMetrics.getTimeDifferenceToNow(timer)); - return ParticipantWrapper.getFilteredList(instance, null); + return list; } } diff --git a/src/main/java/org/broadinstitute/dsm/model/filter/tissue/ManualFilterTissueList.java b/src/main/java/org/broadinstitute/dsm/model/filter/tissue/ManualFilterTissueList.java index b7a7d807f..0e0f64e13 100644 --- a/src/main/java/org/broadinstitute/dsm/model/filter/tissue/ManualFilterTissueList.java +++ b/src/main/java/org/broadinstitute/dsm/model/filter/tissue/ManualFilterTissueList.java @@ -56,7 +56,7 @@ public List filter(QueryParamsMap queryParamsMap) { } logger.info("Found " + wrapperList.size() + " tissues for Tissue View"); GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(ddpInstance.getName(), GoogleAnalyticsMetrics.EVENT_CATEGORY_TISSUE_LIST, - GoogleAnalyticsMetrics.EVENT_TISSUE_LIST_LOADED, GoogleAnalyticsMetrics.EVENT_TISSUE_LIST_LOADED, GoogleAnalyticsMetrics.getTimeDifferenceToNow(timer)); + GoogleAnalyticsMetrics.EVENT_TISSUE_LIST_LOAD_TIME, GoogleAnalyticsMetrics.EVENT_TISSUE_LIST_LOAD_TIME, GoogleAnalyticsMetrics.getTimeDifferenceToNow(timer)); return wrapperList; } } diff --git a/src/main/java/org/broadinstitute/dsm/route/FrontendAnalyticsRoute.java b/src/main/java/org/broadinstitute/dsm/route/FrontendAnalyticsRoute.java new file mode 100644 index 000000000..fa605b4c7 --- /dev/null +++ b/src/main/java/org/broadinstitute/dsm/route/FrontendAnalyticsRoute.java @@ -0,0 +1,36 @@ +package org.broadinstitute.dsm.route; + +import org.broadinstitute.ddp.handlers.util.Result; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetrics; +import org.broadinstitute.dsm.analytics.GoogleAnalyticsMetricsTracker; +import org.broadinstitute.dsm.security.RequestHandler; +import org.broadinstitute.dsm.statics.RoutePath; +import spark.QueryParamsMap; +import spark.Request; +import spark.Response; + +public class FrontendAnalyticsRoute extends RequestHandler { + + @Override + protected Object processRequest(Request request, Response response, String userId) throws Exception { + QueryParamsMap queryParams = request.queryMap(); + + String realm = null; + int timer = 0; + if (queryParams.value(RoutePath.REALM) != null) { + realm = queryParams.get(RoutePath.REALM).value(); + if(queryParams.value("timer") != null){ + timer = (int) Math.ceil(Double.parseDouble(queryParams.get("timer").value())/1000); + GoogleAnalyticsMetricsTracker.getInstance().sendAnalyticsMetrics(realm, GoogleAnalyticsMetrics.EVENT_CATEGORY_PARTICIPANT_LIST, + GoogleAnalyticsMetrics.EVENT_PARTICIPANT_LIST_FRONTEND_LOAD_TIME, GoogleAnalyticsMetrics.EVENT_PARTICIPANT_LIST_FRONTEND_LOAD_TIME, timer); + return new Result(200); + }else{ + throw new RuntimeException("timer should not be empty"); + } + } + else{ + throw new RuntimeException("Realm should not be empty"); + } + + } +} diff --git a/src/main/java/org/broadinstitute/dsm/statics/RoutePath.java b/src/main/java/org/broadinstitute/dsm/statics/RoutePath.java index 42bfb86a5..755b2b708 100644 --- a/src/main/java/org/broadinstitute/dsm/statics/RoutePath.java +++ b/src/main/java/org/broadinstitute/dsm/statics/RoutePath.java @@ -109,6 +109,7 @@ public static final class GAE { public static final String EDIT_PARTICIPANT = "editParticipant"; public static final String EDIT_PARTICIPANT_MESSAGE = "editParticipantMessageStatus"; public static final String ADD_FAMILY_MEMBER = "familyMember"; + public static final String GoogleAnalytics = "googleAnalytics"; public static String getRealm(Request request) { QueryParamsMap queryParams = request.queryMap();