{"action":"created","issue":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/3619","repository_url":"https://api.github.com/repos/mozilla/fxa-content-server","labels_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/3619/labels{/name}","comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/3619/comments","events_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/3619/events","html_url":"https://github.com/mozilla/fxa-content-server/pull/3619","id":143042318,"number":3619,"title":"feat(metrics): emit flow.begin activity event from metrics endpoint","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:active","name":"waffle:active","color":"ededed"}],"state":"open","locked":false,"assignee":{"login":"vladikoff","id":128755,"avatar_url":"https://avatars.githubusercontent.com/u/128755?v=3","gravatar_id":"","url":"https://api.github.com/users/vladikoff","html_url":"https://github.com/vladikoff","followers_url":"https://api.github.com/users/vladikoff/followers","following_url":"https://api.github.com/users/vladikoff/following{/other_user}","gists_url":"https://api.github.com/users/vladikoff/gists{/gist_id}","starred_url":"https://api.github.com/users/vladikoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vladikoff/subscriptions","organizations_url":"https://api.github.com/users/vladikoff/orgs","repos_url":"https://api.github.com/users/vladikoff/repos","events_url":"https://api.github.com/users/vladikoff/events{/privacy}","received_events_url":"https://api.github.com/users/vladikoff/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2016-03-23T18:25:39Z","updated_at":"2016-03-24T15:59:21Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/3619","html_url":"https://github.com/mozilla/fxa-content-server/pull/3619","diff_url":"https://github.com/mozilla/fxa-content-server/pull/3619.diff","patch_url":"https://github.com/mozilla/fxa-content-server/pull/3619.patch"},"body":"Fixes #3608.\r\n\r\nLogic for emitting the event is:\r\n\r\n1. Server records the request time in the `GET /` handler and passes it to the client in the `data-flow-begin` attribute.\r\n2. In the client, the user model sets its own `flowId`. If there's one in the resume token, it uses that, otherwise it creates a new one.\r\n3. During `afterRender` for the `signUp` and `signIn` views, if that `flowId` is not already set on the metrics object, it and `flowBeginTime` are set and `flow.begin` is added to the array of metrics events. The conditional aspect of this is to prevent multiple events being emitted when a user switches between views.\r\n4. Back on the server, the handler for `POST /metrics` emits `flow.begin` activity events as indicated.\r\n\r\nThere is one thing I was particularly unsure about and would like to hear opinions about: **Should the user model unset its `flowId` in `signOutAccount`?**\r\n\r\nI'm not doing that at the moment but I can see the case for doing so; it would mean that extra `flow.begin` events are emitted for users that sign in, then sign out, then sign in again. Is that something we should handle?\r\n\r\nThe reason I wasn't sure is because it gets more complicated when resume tokens are involved. We'd need a way to signal that the resume token should be ignored when the user sets `flowId`, otherwise we'll end up with duplicate `flow.begin` events in the data. That seems like a can of worms, especially as I'm supposed to have all this finished by the end of the quarter. So maybe we could leave this bit for a follow-up? :grin:\r\n\r\n@shane-tomlinson, r?\r\n"},"comment":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/comments/200900580","html_url":"https://github.com/mozilla/fxa-content-server/pull/3619#issuecomment-200900580","issue_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/3619","id":200900580,"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":"2016-03-24T15:59:21Z","updated_at":"2016-03-24T15:59:21Z","body":"> In my testing I noticed that a get a new flow id if I open a new tab of the content server. Do we want to save the flowId in localstorage or not? See https://github.com/mozilla/fxa-content-server/blob/3b40424c1ccbce9dc142f6c0302811c422c697fa/app/scripts/models/user.js#L36 we do it for the uniqueuserid\r\n\r\nI've gone back and forth on this question, changing my mind each time. I'm happy to do it, and it means we could re-open https://github.com/mozilla/fxa-content-server/issues/3592 if we do. The only problem with storing it is that users who sign in/out of multiple accounts would not generate fresh `flow.begin` events. But perhaps we could mitigate that by assoiciating the `flowId` with a `uid` when we store it."}}