{"action":"created","issue":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/2737","labels_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/2737/labels{/name}","comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/2737/comments","events_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/2737/events","html_url":"https://github.com/mozilla/fxa-content-server/pull/2737","id":94749207,"number":2737,"title":"fix(metrics): use sendBeacon where available","user":{"login":"philbooth","id":64367,"avatar_url":"https://avatars.githubusercontent.com/u/64367?v=3","gravatar_id":"","url":"https://api.github.com/users/philbooth","html_url":"https://github.com/philbooth","followers_url":"https://api.github.com/users/philbooth/followers","following_url":"https://api.github.com/users/philbooth/following{/other_user}","gists_url":"https://api.github.com/users/philbooth/gists{/gist_id}","starred_url":"https://api.github.com/users/philbooth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philbooth/subscriptions","organizations_url":"https://api.github.com/users/philbooth/orgs","repos_url":"https://api.github.com/users/philbooth/repos","events_url":"https://api.github.com/users/philbooth/events{/privacy}","received_events_url":"https://api.github.com/users/philbooth/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mozilla/fxa-content-server/labels/waffle:needs%20review","name":"waffle:needs review","color":"ededed"},{"url":"https://api.github.com/repos/mozilla/fxa-content-server/labels/waffle:progress","name":"waffle:progress","color":"ededed"},{"url":"https://api.github.com/repos/mozilla/fxa-content-server/labels/waffle:review","name":"waffle:review","color":"ededed"}],"state":"open","locked":false,"assignee":{"login":"philbooth","id":64367,"avatar_url":"https://avatars.githubusercontent.com/u/64367?v=3","gravatar_id":"","url":"https://api.github.com/users/philbooth","html_url":"https://github.com/philbooth","followers_url":"https://api.github.com/users/philbooth/followers","following_url":"https://api.github.com/users/philbooth/following{/other_user}","gists_url":"https://api.github.com/users/philbooth/gists{/gist_id}","starred_url":"https://api.github.com/users/philbooth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philbooth/subscriptions","organizations_url":"https://api.github.com/users/philbooth/orgs","repos_url":"https://api.github.com/users/philbooth/repos","events_url":"https://api.github.com/users/philbooth/events{/privacy}","received_events_url":"https://api.github.com/users/philbooth/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/milestones/54","html_url":"https://github.com/mozilla/fxa-content-server/milestones/train%2043","labels_url":"https://api.github.com/repos/mozilla/fxa-content-server/milestones/54/labels","id":1191538,"number":54,"title":"train 43","description":"Train 43 - July 20-Aug 3","creator":{"login":"shane-tomlinson","id":848085,"avatar_url":"https://avatars.githubusercontent.com/u/848085?v=3","gravatar_id":"","url":"https://api.github.com/users/shane-tomlinson","html_url":"https://github.com/shane-tomlinson","followers_url":"https://api.github.com/users/shane-tomlinson/followers","following_url":"https://api.github.com/users/shane-tomlinson/following{/other_user}","gists_url":"https://api.github.com/users/shane-tomlinson/gists{/gist_id}","starred_url":"https://api.github.com/users/shane-tomlinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shane-tomlinson/subscriptions","organizations_url":"https://api.github.com/users/shane-tomlinson/orgs","repos_url":"https://api.github.com/users/shane-tomlinson/repos","events_url":"https://api.github.com/users/shane-tomlinson/events{/privacy}","received_events_url":"https://api.github.com/users/shane-tomlinson/received_events","type":"User","site_admin":false},"open_issues":23,"closed_issues":0,"state":"open","created_at":"2015-07-02T20:42:56Z","updated_at":"2015-07-22T13:59:31Z","due_on":"2015-08-02T23:00:00Z","closed_at":null},"comments":6,"created_at":"2015-07-13T15:34:07Z","updated_at":"2015-07-22T14:28:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/2737","html_url":"https://github.com/mozilla/fxa-content-server/pull/2737","diff_url":"https://github.com/mozilla/fxa-content-server/pull/2737.diff","patch_url":"https://github.com/mozilla/fxa-content-server/pull/2737.patch"},"body":"This changeset partially addresses the problem from #2493, that synchronous XHR has been deprecated by the WHATWG. The approach taken is to use `sendBeacon` if it is implemented, otherwise it falls back to the current behaviour of synchronous XHR.\r\n\r\nBecause `sendBeacon` returns a boolean, the XHR condition has been modified to do likewise for the benefit of calling code. Doing this also meant reworking the tests because previously they relied on comparing the result of `metrics.flush()` to the data that was passed in, rather than actually interrogating test spies for any assertions. I think they're better tests for it.\r\n\r\nThere is one behavioural difference, in so much as events and timers are no longer cleared if the beacon request fails. It was [pointed out](https://github.com/mozilla/fxa-content-server/issues/2493#issuecomment-120425102) that such an occurrence would be extremely improbable anyway but, as I was rewriting the tests, it felt wrong to knowingly write bad assertions.\r\n\r\nThere is another, related change that could be made in addition to these, [suggested in the issue](https://github.com/mozilla/fxa-content-server/issues/2493#issuecomment-109809007):\r\n\r\n> I'd be curious how frequently we navigate ourselves away from the page (e.g. when completing an oauth redirect) versus how frequently we get unload by user action. In the former case we could do an async XHR and ensure it completes before proceeding.\r\n\r\nThat fix didn't seem predicated on the existence of this one, so I thought it correct to get them reviewed separately. But I'm also happy to roll them up and submit them together, if people would prefer it that way."},"comment":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/comments/123740690","html_url":"https://github.com/mozilla/fxa-content-server/pull/2737#issuecomment-123740690","issue_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/2737","id":123740690,"user":{"login":"philbooth","id":64367,"avatar_url":"https://avatars.githubusercontent.com/u/64367?v=3","gravatar_id":"","url":"https://api.github.com/users/philbooth","html_url":"https://github.com/philbooth","followers_url":"https://api.github.com/users/philbooth/followers","following_url":"https://api.github.com/users/philbooth/following{/other_user}","gists_url":"https://api.github.com/users/philbooth/gists{/gist_id}","starred_url":"https://api.github.com/users/philbooth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philbooth/subscriptions","organizations_url":"https://api.github.com/users/philbooth/orgs","repos_url":"https://api.github.com/users/philbooth/repos","events_url":"https://api.github.com/users/philbooth/events{/privacy}","received_events_url":"https://api.github.com/users/philbooth/received_events","type":"User","site_admin":false},"created_at":"2015-07-22T14:28:30Z","updated_at":"2015-07-22T14:28:30Z","body":"Apologies for taking so long to address your comments @shane-tomlinson, but they're all done now.\r\n\r\n@vladikoff, you probably also want to review this."}}