etr2460 commented on a change in pull request #9733:
URL: 
https://github.com/apache/incubator-superset/pull/9733#discussion_r419777938



##########
File path: superset-frontend/src/logger/LogUtils.js
##########
@@ -19,6 +19,7 @@
 // Log event names ------------------------------------------------------------
 export const LOG_ACTIONS_LOAD_CHART = 'load_chart';
 export const LOG_ACTIONS_RENDER_CHART = 'render_chart';
+export const LOG_ACTIONS_HIDDEN_BROWSER_TAB = 'hidden_browser_tab';

Review comment:
       almost all these event names use a verb to start them, although this 
event isn't really an action and instead is logging the duration of a state.
   
   Maybe this should be `LOG_DURATION_BROWSER_TAB_HIDDEN = 
'duration_browser_tab_hidden'`? I'm not really sure what a good name is here, 
maybe @john-bodley has thoughts? 

##########
File path: superset-frontend/src/dashboard/components/Dashboard.jsx
##########
@@ -158,6 +173,27 @@ class Dashboard extends React.PureComponent {
     }
   }
 
+  componentWillUnmount() {
+    window.removeEventListener('visibilitychange', this.onVisibilityChange);
+  }
+
+  onVisibilityChange() {
+    if (document.visibilityState === 'hidden') {
+      // from visible to hidden
+      this.visibilityEventData = {
+        start_offset: Logger.getTimestamp(),
+        ts: new Date().getTime(),
+      };
+    } else {
+      // from hidden to visible
+      const logStart = this.visibilityEventData.start_offset;
+      this.props.actions.logEvent(LOG_ACTIONS_HIDDEN_BROWSER_TAB, {
+        ...this.visibilityEventData.start_offset,

Review comment:
       `start_offset` is a number i think, so wouldn't this fail when trying to 
spread a number?
   
   I assume this should be `...this.visibilityEventData`

##########
File path: superset-frontend/src/dashboard/components/Dashboard.jsx
##########
@@ -158,6 +173,27 @@ class Dashboard extends React.PureComponent {
     }
   }
 
+  componentWillUnmount() {
+    window.removeEventListener('visibilitychange', this.onVisibilityChange);
+  }
+
+  onVisibilityChange() {
+    if (document.visibilityState === 'hidden') {
+      // from visible to hidden
+      this.visibilityEventData = {
+        start_offset: Logger.getTimestamp(),
+        ts: new Date().getTime(),
+      };
+    } else {

Review comment:
       could we explicitly check if `visibilityState === 'visible'` here? I see 
some documentation talking about the `prerender` state which we probably want 
to ignore




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to