-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,34 @@ | |
| window.document.head.appendChild(script); | ||
| window.document.body.classList.add('show-hypothesis'); | ||
| hypothesisLoaded = true; | ||
| }); | ||
|
|
||
| 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 | ||
| var wbLink = window.DEFAULT_URL; | ||
| var preprintGuid; | ||
| if (wbLink.split('/').length >= 6) { | ||
| preprintGuid = wbLink.split('/')[5]; | ||
| } else { | ||
| preprintGuid = 'preprint-guid-unknown'; | ||
| } | ||
| var sendAnalyticsIfExpanded = function (expanded) { | ||
| if (expanded && !sidePanelOpened) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably a dumb question about
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| sidePanelOpened = expanded; | ||
| ga('send', 'event', { | ||
| eventCategory: 'Hypothesis', | ||
| eventAction: 'Open Hypothesis Panel', | ||
| //`eventLabel` is the guid of the preprint to which the file belongs | ||
| eventLabel: preprintGuid, | ||
| }); | ||
| } | ||
| }; | ||
| window.hypothesisConfig = function () { | ||
| return { | ||
| "onLayoutChange": function (layout) { return sendAnalyticsIfExpanded(layout.expanded); } | ||
| }; | ||
| }; | ||
| }); | ||
| }; | ||
| })(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,3 +170,4 @@ def child(key): | |
|
|
||
|
|
||
| SENTRY_DSN = config.get_nullable('SENTRY_DSN', None) | ||
| GOOGLE_ANALYTICS_TRACKING_ID = config.get_nullable('GOOGLE_ANALYTICS_TRACKING_ID', None) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can GA script handle
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure. It'll probably throw an error.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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
splityou 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.