-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DDP-6891_GoogleAnalyitics #316
Open
pegahtah
wants to merge
9
commits into
develop
Choose a base branch
from
DDP-6891_GoogleAnalyitics
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c549896
Added GA to dependencies and metrics to the `PatchRoue.java`
pegahtah c2a2c43
Merge remote-tracking branch 'origin/develop' into DDP-6891_GoogleAna…
pegahtah 35805e7
added gender from onc history
pegahtah f49d86d
added GoogleAnalyticsMetricsTracker and GoogleAnalyticsMetrics for sp…
pegahtah 50958b4
Merge remote-tracking branch 'origin/develop' into DDP-6891_GoogleAna…
pegahtah 85a72ca
added more loggings
pegahtah 03751e3
fixed the event sending by adding users
pegahtah 3630653
fiixed events in PatchRoute.java
pegahtah 723550b
added events in participant and tissue list.
pegahtah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.broadinstitute.dsm.analytics; | ||
|
||
public class GoogleAnalyticsMetrics { | ||
|
||
// public static final String EVENT_CATEGORY_USER_REGISTRATION = "user-registration"; | ||
// 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_ACTION_PARTICIPANT_LIST = "participant-list-load-time"; | ||
public static final String EVENT_LABEL_PARTICIPANT_LIST = "participant-list-load-time";//studyGuid appended | ||
|
||
public static final String EVENT_CATEGORY_SERVER_START= "server-start"; | ||
public static final String EVENT_ACTION_SERVER_START = "server-start"; | ||
public static final String EVENT_LABEL_SERVER_START = "server-start"; | ||
|
||
public static final String EVENT_CATEGORY_PATCH_DATA = "patch-data"; | ||
public static final String EVENT_ACTION_PATCH_DATA = "patch-data-answers"; | ||
public static final String EVENT_LABEL_PATCH_DATA = "patch-answers"; //studyGuid & original page appended | ||
|
||
public static final String EVENT_CATEGORY_TISSUE_LIST = "tissue-list"; | ||
public static final String EVENT_ACTION_TISSUE_LIST = "tissue-list-loaded"; | ||
public static final String EVENT_LABEL_TISSUE_LIST = "tissue-list-loaded";//studyGuid appended | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/org/broadinstitute/dsm/analytics/GoogleAnalyticsMetricsTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.broadinstitute.dsm.analytics; | ||
|
||
import com.brsanthu.googleanalytics.GoogleAnalytics; | ||
import com.brsanthu.googleanalytics.GoogleAnalyticsConfig; | ||
import com.brsanthu.googleanalytics.request.EventHit; | ||
import com.brsanthu.googleanalytics.request.GoogleAnalyticsResponse; | ||
import com.typesafe.config.Config; | ||
import lombok.NonNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class GoogleAnalyticsMetricsTracker { | ||
private static final Logger logger = LoggerFactory.getLogger(GoogleAnalyticsMetricsTracker.class); | ||
private static final String GA_TOKEN_PATH = "GoogleAnalytics.trackingId"; | ||
private static GoogleAnalytics googleAnalyticsTrackers; | ||
private static volatile GoogleAnalyticsMetricsTracker instance; | ||
private static Object lockGA = new Object(); | ||
private static Config CONFIG; | ||
|
||
private GoogleAnalyticsMetricsTracker() { | ||
initStudyMetricTracker(); | ||
} | ||
|
||
public static void setConfig(@NonNull Config config){ | ||
CONFIG = config; | ||
} | ||
|
||
public static GoogleAnalyticsMetricsTracker getInstance() { | ||
if (instance == null) { | ||
synchronized (lockGA) { | ||
if (instance == null) { | ||
instance = new GoogleAnalyticsMetricsTracker(); | ||
} | ||
} | ||
} | ||
return instance; | ||
} | ||
|
||
private GoogleAnalytics getMetricTracker() { | ||
if (googleAnalyticsTrackers == null) { | ||
|
||
initStudyMetricTracker(); | ||
} | ||
return googleAnalyticsTrackers; | ||
} | ||
|
||
private synchronized void initStudyMetricTracker() { | ||
GoogleAnalytics metricTracker = GoogleAnalytics.builder() | ||
.withConfig(new GoogleAnalyticsConfig().setGatherStats(true).setUserAgent("Custom User Agent")) | ||
.withTrackingId(getAnalyticsToken(CONFIG)) | ||
.build(); | ||
googleAnalyticsTrackers = metricTracker; | ||
logger.info("Initialized GA Metrics Tracker for DSM "); | ||
} | ||
|
||
|
||
private void sendEventMetrics(EventHit eventHit) { | ||
GoogleAnalytics metricTracker = getMetricTracker(); | ||
if (metricTracker != null) { | ||
GoogleAnalyticsResponse response = metricTracker.event().eventCategory(eventHit.eventCategory()) | ||
.eventAction(eventHit.eventAction()) | ||
.eventLabel(eventHit.eventLabel()) | ||
.eventValue(eventHit.eventValue()) | ||
.trackingId(getAnalyticsToken(CONFIG)) | ||
.send(); | ||
|
||
logger.info(response.toString()); | ||
logger.info(response.getStatusCode()+""); | ||
logger.info(metricTracker.getStats().getEventHits()+""); | ||
|
||
} | ||
} | ||
|
||
public void sendAnalyticsMetrics(String studyGuid, String category, String action, String label, int value) { | ||
String gaEventLabel = String.join(":", label, | ||
studyGuid); | ||
EventHit eventHit = new EventHit(category, action, gaEventLabel, value); | ||
logger.info(eventHit.toString()); | ||
sendEventMetrics(eventHit); | ||
|
||
} | ||
|
||
public void flushOutMetrics() { | ||
//lookup all Metrics Trackers and flush out any pending events | ||
logger.info("Flushing out all pending GA events"); | ||
googleAnalyticsTrackers.flush(); | ||
googleAnalyticsTrackers.resetStats(); | ||
} | ||
|
||
public String getAnalyticsToken(@NonNull Config config) { | ||
if (config.hasPath(GA_TOKEN_PATH)) { | ||
return config.getString(GA_TOKEN_PATH); | ||
} | ||
throw new RuntimeException("There is no secret in the SM for the Google Analytics"); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't added these events to the code yet, it wasn't in the ticket, so I wasn't sure