-
Notifications
You must be signed in to change notification settings - Fork 76
[ENG-44] Add google analytics tracking for when hypothesis side panel is opened #355
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
[ENG-44] Add google analytics tracking for when hypothesis side panel is opened #355
Conversation
cslzchen
left a comment
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.
|
|
||
| var sidePanelOpened = false; | ||
| var sendAnalyticsIfExpanded = function (expanded) { | ||
| if (expanded && !sidePanelOpened) { |
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.
Probably a dumb question about hypothesis configuration. What is expanded (or layout.expanded a few lines below more specifically)?
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.
layout.expanded denotes whether the hypothesis side panel is expanded when onLayoutChanged() is called.
|
|
||
|
|
||
| SENTRY_DSN = config.get_nullable('SENTRY_DSN', None) | ||
| GOOGLE_ANALYTICS_TRACKING_ID = config.get_nullable('GOOGLE_ANALYTICS_TRACKING_ID', None) |
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.
Can GA script handle None tracking ID? I guess so but just want to double check with you.
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 am not sure. It'll probably throw an error.
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.
@cslzchen Confirmed that it would not cause an error when tracking ID is None.
cslzchen
left a comment
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.
LG and RTM
| ga('send', 'event', { | ||
| eventCategory: 'Hypothesis', | ||
| eventAction: 'Open Hypothesis Panel', | ||
| eventLabel: window.DEFAULT_URL.split('/')[5], |
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.
What is this value? Could you add a comment saying what this is expected to be?
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.
eventLabel should be the preprint guid.
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.
A follow-up question, is it guaranteed that the GUID is always at index 5? Can we add some extra check before ga to parse window.DEFAULT_URL.split('/')[5] and handle unexpected URL format. In addition, having a comment on what the expected URL looks like will be very helpful as well.
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.
There is no guarantee that window.DEFAULT_URL.split('/')[5] always return the preprint guid. However, if the rendered file is a preprint's primary file, window.DEFAULT_URL should be the WB link to the file on OSFStorage (e.g. https://files.us.staging2.osf.io/v1/resources/twq6d/providers/osfstorage/5c9cd1e3c8f5970017ed07d3?direct=&mode=render), and from which we can extract the guid of the preprint.
And since hypothesis is only enabled on a preprint's primary file, it should be fine.
I'll add some checks for unexpected URL and log to sentry when that happens.
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.
Sounds good! Thanks for the explanation. This WB API rarely changes. If it ever changed, we would be informed right away.
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.
@cslzchen PR updated.
|
@felliott Comment is added. |
56fb047 to
f72d3fa
Compare
More specifically, this GA event tracks when users click open the Hypothesis side panel for each preprints.
f72d3fa to
111430d
Compare
The preprints GUID used by the GA tracking event is retreived from window.DEFAULT_URL, which is the third segment of the URL path.
111430d to
3df7593
Compare
| var sidePanelOpened = false; | ||
| // window.DEFAULT_URL should be the wb link in this format: | ||
| // https://<wb-domain>/v1/resources/<preprint-guid>/providers/osfstorage/<file-id>?direct=&mode=render | ||
| // TODO: parse and validate the WB URL before retrieving the preprints GUID |
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 added a TODO comment to your code. Although the split you use here is unaware of the HTTP protocol, URL domain and path, I think for now it is good enough. A better way (probably a future improvement) is to fully parse and validate the URL.
Ticket
https://openscience.atlassian.net/browse/ENG-44
Purpose
To add GA tracking to MFR to track when users click open the Hypothesis panel.
Changes
mfr/extensions/pdf/templates/viewer.mako, we add GA tracking imports.mfr/server/static/js/mfr.child.hypothesis.js, we setwindow.hypothesisConfigto use theonLayoutChange()callback provided by hypothesis to watch for opening of annotation panel.Side effects
None
QA Notes
To test this, you'll need access to Google Analytics panel for staging server.
Check to make sure the event is only tracked when users open the panel for the first time on that page. Page refresh counts as a new page. User is counted by browser, not OSF User. So if the same OSFUser opens two browser and opens the panel in both, it counts as two events.
Deployment Notes
Add GOOGLE_ANALYTICS_TRACKING_ID for to staging/prod settings.