Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Don't register a visit if page returns a non-successful HTTP status code #4032

Merged
merged 3 commits into from
Sep 17, 2016
Merged

Don't register a visit if page returns a non-successful HTTP status code #4032

merged 3 commits into from
Sep 17, 2016

Conversation

bsclifton
Copy link
Member

@bsclifton bsclifton commented Sep 15, 2016

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).

Don't register a visit if page returns a non-successful HTTP status code

Fixes #3759
Auditors:
@mrose17, @bridiver

Test Plan:

  1. Visit https://clifton.io
  2. Stay on page for a while
  3. Confirm time spent is incremented
  4. Visit https://clifton.io/404
  5. Stay on page for a while
  6. Confirm time spent is not incremented

@@ -965,6 +965,11 @@ class Frame extends ImmutableComponent {
}))
}
})
this.webview.addEventListener('did-get-response-details', (details) => {
if (getSetting(settings.PAYMENTS_ENABLED) && details.originalURL === this.props.location) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are other places we want this so it should always fire regardless of ledger settings. Also, we don't really need to send frameProps for all window actions now that we have tabId so I think you only only need to send the tabId and the details

@@ -128,6 +139,9 @@ const doAction = (action) => {
// retains all past pages, not really sure that's needed... [MTR]
eventState = eventState.set('page_info', eventState.get('page_info').push(action.pageInfo))
break
case WindowConstants.WINDOW_GOT_RESPONSE_DETAILS:
addResponseDetails(action.frameProps.get('location'), action.frameProps.get('tabId'), action.details)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url is also in the response details

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we discussed, I think we should just use this for the load event and add the details to it

@@ -17,7 +17,8 @@ const BrowserWindow = electron.BrowserWindow
let eventState = Immutable.fromJS({
page_load: [],
page_view: [],
page_info: []
page_info: [],
page_response: []
Copy link
Collaborator

@bridiver bridiver Sep 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe page_load_details?

* @param {number} responseCode - HTTP response code to be evaluated
* @return {boolean} true if the page should be excluded, false if not
*/
module.exports.IsValidResponseCode = (responseCode) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsValidResponseCode => isValidResponseCode

* @param {number} responseCode - HTTP response code to be evaluated
* @return {boolean} true if the page should be excluded, false if not
*/
module.exports.IsValidResponseCode = (responseCode) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback about the method for checking (and what codes to include) is very much appreciated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you probably want to check for errors vs positive responses because there are other potential successful responses. You also want to ignore things like redirects

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I take that back. We need to further restrict 2xx to 200, 203 and 206 I think

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also might be better as either a general utility method vs ledger. shouldTrackView looks ledger-specific so that's ok

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call- typically REST APIs will use 201 and 202, which shouldn't be returned for regular content 👍

@@ -965,6 +965,11 @@ class Frame extends ImmutableComponent {
}))
}
})
this.webview.addEventListener('did-get-response-details', (details) => {
if (getSetting(settings.PAYMENTS_ENABLED) && details.originalURL === this.props.location) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: this event will only get sent if payments is enabled (to prevent unneeded overhead)

Fixes #3759
Auditors:
@mrose17, @bridiver

Test Plan:
1. Visit https://clifton.io
2. Stay on page for a while
3. Confirm time spent is incremented
4. Visit https://clifton.io/404
5. Stay on page for a while
6. Confirm time spent is not incremented

Udpated w/ review feedback from @bridiver
it('returns false for non-content success codes (used for REST apis, etc)', function () {
assert.equal(httpUtil.responseHasContent(201), false) // created
assert.equal(httpUtil.responseHasContent(202), false) // accepted
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4xx? Don't necessarily need an exhaustive list, but the list isn't that long https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
can be done in a followup too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

@bridiver
Copy link
Collaborator

++

@alexwykoff
Copy link
Contributor

Did not work as expected for 0.12.2 RC2 on OS X
screen shot 2016-09-22 at 6 30 42 pm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants