Skip to content

Commit

Permalink
DDP-6981_GoogleAnalyticsFrontend_prod (#327)
Browse files Browse the repository at this point in the history
* * Added endpoint for the GoogleAnalytics to send analytics from frontend in FrontendAnalyticsRoute
*changed the way we calculate the time difference to get the ceiling
*corrected old ways of getting GA

* * Added calculation for empty list
  • Loading branch information
pegahtah authored Dec 15, 2021
1 parent 4ac1d69 commit 6ee0190
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/broadinstitute/dsm/DSMServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,6 +80,7 @@ public JsonObject getDataAsJson() {
public static List<ParticipantWrapper> getFilteredList(@NonNull DDPInstance instance, Map<String, String> 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());
Expand Down Expand Up @@ -115,6 +118,9 @@ public static List<ParticipantWrapper> getFilteredList(@NonNull DDPInstance inst
List<ParticipantWrapper> 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 {
Expand Down Expand Up @@ -256,6 +262,8 @@ else if (ElasticSearchUtil.PROXY.equals(source)) {
List<ParticipantWrapper> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ protected List<ParticipantWrapper> filterParticipantList(Filter[] filters, Map<S
}

logger.info("Found query conditions for " + mergeConditions.size() + " tables");
//search bar ptL
List<ParticipantWrapper> 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<ParticipantWrapper> 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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public List<TissueListWrapper> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6ee0190

Please sign in to comment.