{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/comments/137341622","pull_request_review_id":60995901,"id":137341622,"diff_hunk":"@@ -0,0 +1,245 @@\n+/* This Source Code Form is subject to the terms of the Mozilla Public\n+ * License, v. 2.0. If a copy of the MPL was not distributed with this\n+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n+\n+// This module contains mappings from content server event names to\n+// amplitude event definitions. The intention is for the returned\n+// `receiveEvent` function to be invoked for every event and the\n+// mappings determine which of those will be transformed into an\n+// amplitude event.\n+//\n+// You can read more about the amplitude event\n+// structure here:\n+//\n+// https://amplitude.zendesk.com/hc/en-us/articles/204771828-HTTP-API\n+//\n+// You can see the event taxonomy here:\n+//\n+// https://docs.google.com/spreadsheets/d/1G_8OJGOxeWXdGJ1Ugmykk33Zsl-qAQL05CONSeD4Uz4\n+\n+/* eslint-disable sorting/sort-object-props, camelcase */\n+\n+'use strict';\n+\n+const APP_VERSION = /^[0-9]+\\.([0-9]+)\\./.exec(require('../../package.json').version)[1];\n+\n+const GROUPS = {\n+  email: 'fxa_email',\n+  login: 'fxa_login',\n+  registration: 'fxa_reg',\n+  settings: 'fxa_pref',\n+  sms: 'fxa_sms'\n+};\n+\n+const ENGAGE_SUBMIT_EVENT_GROUPS = {\n+  'force-auth': GROUPS.login,\n+  signin: GROUPS.login,\n+  signup: GROUPS.registration\n+};\n+\n+const VIEW_EVENT_GROUPS = {\n+  'force-auth': GROUPS.login,\n+  settings: GROUPS.settings,\n+  signin: GROUPS.login,\n+  signup: GROUPS.registration,\n+  sms: GROUPS.sms\n+};\n+\n+const EMAIL_TYPES = {\n+  'complete-reset-password': 'reset_password',\n+  'complete-signin': 'login',\n+  'verify-email': 'registration'\n+};\n+\n+const NEWSLETTER_STATES = {\n+  optIn: 'subscribed',\n+  optOut: 'unsubscribed',\n+};\n+\n+const EVENTS = {\n+  'flow.reset-password.submit': {\n+    group: GROUPS.login,\n+    event: 'forgot_submit'\n+  },\n+  'settings.change-password.success': {\n+    group: GROUPS.settings,\n+    event: 'password'\n+  },\n+  'settings.clients.disconnect.submit': {\n+    group: GROUPS.settings,\n+    event: 'disconnect_device'\n+  },\n+  'settings.signout.success': {\n+    group: GROUPS.settings,\n+    event: 'logout'\n+  },\n+};\n+\n+const FUZZY_EVENTS = new Map([\n+  [ /^flow\\.([\\w-]+)\\.engage$/, {\n+    isDynamicGroup: true,\n+    group: eventCategory => ENGAGE_SUBMIT_EVENT_GROUPS[eventCategory],\n+    event: 'engage'\n+  } ],\n+  [ /^flow\\.[\\w-]+\\.forgot-password$/, {\n+    group: GROUPS.login,\n+    event: 'forgot_pwd'\n+  } ],\n+  [ /^flow\\.[\\w-]+\\.have-account$/, {\n+    group: GROUPS.registration,\n+    event: 'have_account'\n+  } ],\n+  [ /^flow\\.([\\w-]+)\\.submit$/, {\n+    isDynamicGroup: true,\n+    group: eventCategory => ENGAGE_SUBMIT_EVENT_GROUPS[eventCategory],\n+    event: 'submit'\n+  } ],\n+  [ /^screen\\.([\\w-]+)$/, {\n+    isDynamicGroup: true,\n+    group: eventCategory => VIEW_EVENT_GROUPS[eventCategory],\n+    event: 'view'\n+  } ],\n+  [ /^settings\\.communication-preferences\\.(optIn|optOut)\\.success$/, {\n+    group: GROUPS.settings,\n+    event: 'newsletter'\n+  } ],\n+  [ /^([\\w-]+).verification.success$/, {\n+    isDynamicGroup: true,\n+    group: eventCategory => eventCategory in EMAIL_TYPES ? GROUPS.email : null,\n+    event: 'click'\n+  } ]\n+]);\n+\n+const NOP = () => {};\n+\n+const EVENT_PROPERTIES = {\n+  [GROUPS.email]: mixProperties(mapEmailType, mapService),\n+  [GROUPS.login]: mixProperties(mapEntrypoint, mapService),\n+  [GROUPS.registration]: mixProperties(mapEntrypoint, mapService),\n+  [GROUPS.settings]: mapEntrypoint,\n+  [GROUPS.sms]: NOP\n+};\n+\n+const USER_PROPERTIES = {\n+  [GROUPS.email]: NOP,\n+  [GROUPS.login]: mixProperties(mapUid, mapUtmProperties),\n+  [GROUPS.registration]: mixProperties(mapUid, mapUtmProperties),\n+  [GROUPS.settings]: mixProperties(mapUid, mapNewsletterState),\n+  [GROUPS.sms]: NOP\n+};\n+\n+module.exports = receiveEvent;\n+\n+function receiveEvent (event, data) {\n+  if (! event || ! data) {\n+    return;\n+  }\n+\n+  const eventType = event.type;\n+  let mapping = EVENTS[eventType];\n+  let eventCategory;\n+\n+  if (! mapping) {\n+    for (const [ key, value ] of FUZZY_EVENTS.entries()) {\n+      const match = key.exec(eventType);\n+      if (match) {\n+        mapping = value;\n+        if (match.length === 2) {\n+          eventCategory = match[1];\n+        }\n+        break;\n+      }\n+    }\n+  }\n+\n+  if (mapping) {\n+    let group = mapping.group;\n+    if (mapping.isDynamicGroup) {","path":"server/lib/amplitude.js","position":157,"original_position":157,"commit_id":"9e6e52981fc51ce1a23e0db18e70597d55753d60","original_commit_id":"f2a1c37fb3c568a2f3c9b36d1313d61de64564cc","user":{"login":"vladikoff","id":128755,"avatar_url":"https://avatars3.githubusercontent.com/u/128755?v=4","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},"body":"Can be refactored later if needed","created_at":"2017-09-06T17:50:47Z","updated_at":"2017-09-06T17:50:47Z","html_url":"https://github.com/mozilla/fxa-content-server/pull/5412#discussion_r137341622","pull_request_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/5412","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/comments/137341622"},"html":{"href":"https://github.com/mozilla/fxa-content-server/pull/5412#discussion_r137341622"},"pull_request":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/5412"}},"in_reply_to_id":137290878},"pull_request":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/5412","id":138679183,"html_url":"https://github.com/mozilla/fxa-content-server/pull/5412","diff_url":"https://github.com/mozilla/fxa-content-server/pull/5412.diff","patch_url":"https://github.com/mozilla/fxa-content-server/pull/5412.patch","issue_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/5412","number":5412,"state":"open","locked":false,"title":"feat(metrics): send amplitude events to the logs","user":{"login":"philbooth","id":64367,"avatar_url":"https://avatars2.githubusercontent.com/u/64367?v=4","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},"body":"Fixes #5346.\r\n\r\nOpening this as a WIP PR before I go away in case anybody wants to pass comment in the interim. My aim is to mop up the outstanding issues, fix failing tests and write new tests on Monday, with a view to getting this in to train 95.\r\n\r\nThe approach taken is to try and stay fairly close to the auth server implementation (see mozilla/fxa-auth-server#2069), so that the refactoring to `fxa-shared` (see mozilla/fxa-shared#11) eliminates most of the imperative stuff from both. Ideally we'll just be left with the mapping definitions in each repo, with common code responsible for processing events.\r\n","created_at":"2017-08-31T14:18:39Z","updated_at":"2017-09-06T17:50:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1346c14434c5b0b02cfe7c996019c4c2384841f7","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/5412/commits","review_comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/5412/comments","review_comment_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/5412/comments","statuses_url":"https://api.github.com/repos/mozilla/fxa-content-server/statuses/9e6e52981fc51ce1a23e0db18e70597d55753d60","head":{"label":"mozilla:phil/5346","ref":"phil/5346","sha":"9e6e52981fc51ce1a23e0db18e70597d55753d60","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars2.githubusercontent.com/u/131524?v=4","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":11778024,"name":"fxa-content-server","full_name":"mozilla/fxa-content-server","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars2.githubusercontent.com/u/131524?v=4","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/fxa-content-server","description":"Firefox Accounts Content Server","fork":false,"url":"https://api.github.com/repos/mozilla/fxa-content-server","forks_url":"https://api.github.com/repos/mozilla/fxa-content-server/forks","keys_url":"https://api.github.com/repos/mozilla/fxa-content-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/fxa-content-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/fxa-content-server/teams","hooks_url":"https://api.github.com/repos/mozilla/fxa-content-server/hooks","issue_events_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/fxa-content-server/events","assignees_url":"https://api.github.com/repos/mozilla/fxa-content-server/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/fxa-content-server/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/fxa-content-server/tags","blobs_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/fxa-content-server/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/fxa-content-server/languages","stargazers_url":"https://api.github.com/repos/mozilla/fxa-content-server/stargazers","contributors_url":"https://api.github.com/repos/mozilla/fxa-content-server/contributors","subscribers_url":"https://api.github.com/repos/mozilla/fxa-content-server/subscribers","subscription_url":"https://api.github.com/repos/mozilla/fxa-content-server/subscription","commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/fxa-content-server/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/fxa-content-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/fxa-content-server/merges","archive_url":"https://api.github.com/repos/mozilla/fxa-content-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/fxa-content-server/downloads","issues_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/fxa-content-server/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/fxa-content-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/fxa-content-server/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/fxa-content-server/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla/fxa-content-server/deployments","created_at":"2013-07-30T23:35:35Z","updated_at":"2017-09-03T09:05:00Z","pushed_at":"2017-09-06T15:23:17Z","git_url":"git://github.com/mozilla/fxa-content-server.git","ssh_url":"git@github.com:mozilla/fxa-content-server.git","clone_url":"https://github.com/mozilla/fxa-content-server.git","svn_url":"https://github.com/mozilla/fxa-content-server","homepage":"","size":16641,"stargazers_count":117,"watchers_count":117,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":91,"mirror_url":null,"open_issues_count":115,"forks":91,"open_issues":115,"watchers":117,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"5eea74110c86aadc2ee37fd043e612aea7572c3a","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars2.githubusercontent.com/u/131524?v=4","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":11778024,"name":"fxa-content-server","full_name":"mozilla/fxa-content-server","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars2.githubusercontent.com/u/131524?v=4","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/fxa-content-server","description":"Firefox Accounts Content Server","fork":false,"url":"https://api.github.com/repos/mozilla/fxa-content-server","forks_url":"https://api.github.com/repos/mozilla/fxa-content-server/forks","keys_url":"https://api.github.com/repos/mozilla/fxa-content-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/fxa-content-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/fxa-content-server/teams","hooks_url":"https://api.github.com/repos/mozilla/fxa-content-server/hooks","issue_events_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/fxa-content-server/events","assignees_url":"https://api.github.com/repos/mozilla/fxa-content-server/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/fxa-content-server/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/fxa-content-server/tags","blobs_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/fxa-content-server/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/fxa-content-server/languages","stargazers_url":"https://api.github.com/repos/mozilla/fxa-content-server/stargazers","contributors_url":"https://api.github.com/repos/mozilla/fxa-content-server/contributors","subscribers_url":"https://api.github.com/repos/mozilla/fxa-content-server/subscribers","subscription_url":"https://api.github.com/repos/mozilla/fxa-content-server/subscription","commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/fxa-content-server/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/fxa-content-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/fxa-content-server/merges","archive_url":"https://api.github.com/repos/mozilla/fxa-content-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/fxa-content-server/downloads","issues_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/fxa-content-server/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/fxa-content-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/fxa-content-server/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/fxa-content-server/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla/fxa-content-server/deployments","created_at":"2013-07-30T23:35:35Z","updated_at":"2017-09-03T09:05:00Z","pushed_at":"2017-09-06T15:23:17Z","git_url":"git://github.com/mozilla/fxa-content-server.git","ssh_url":"git@github.com:mozilla/fxa-content-server.git","clone_url":"https://github.com/mozilla/fxa-content-server.git","svn_url":"https://github.com/mozilla/fxa-content-server","homepage":"","size":16641,"stargazers_count":117,"watchers_count":117,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":91,"mirror_url":null,"open_issues_count":115,"forks":91,"open_issues":115,"watchers":117,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/5412"},"html":{"href":"https://github.com/mozilla/fxa-content-server/pull/5412"},"issue":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/issues/5412"},"comments":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/issues/5412/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/5412/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/5412/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/statuses/9e6e52981fc51ce1a23e0db18e70597d55753d60"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"vladikoff"}}