{"action":"created","comment":{"url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/comments/58467035","id":58467035,"diff_hunk":"@@ -13,83 +14,53 @@ var UUID = require('./uuid');\n var version = require('./version');\n var DEFAULT_OPTIONS = require('./options');\n \n-var IDENTIFY_EVENT = '$identify';\n-var API_VERSION = 2;\n-var MAX_STRING_LENGTH = 1024;\n-var LocalStorageKeys = {\n-  LAST_EVENT_ID: 'amplitude_lastEventId',\n-  LAST_EVENT_TIME: 'amplitude_lastEventTime',\n-  LAST_IDENTIFY_ID: 'amplitude_lastIdentifyId',\n-  LAST_SEQUENCE_NUMBER: 'amplitude_lastSequenceNumber',\n-  REFERRER: 'amplitude_referrer',\n-  SESSION_ID: 'amplitude_sessionId',\n-\n-  // Used in cookie as well\n-  DEVICE_ID: 'amplitude_deviceId',\n-  OPT_OUT: 'amplitude_optOut',\n-  USER_ID: 'amplitude_userId'\n-};\n-\n-/*\n- * Amplitude API\n+/**\n+ * Amplitude SDK API - instance constructor.\n+ * @constructor Amplitude\n+ * @public\n+ * @example var amplitude = new Amplitude();\n  */\n-var Amplitude = function() {\n+var Amplitude = function Amplitude() {\n   this._unsentEvents = [];\n   this._unsentIdentifys = [];\n   this._ua = new UAParser(navigator.userAgent).getResult();\n   this.options = object.merge({}, DEFAULT_OPTIONS);\n   this.cookieStorage = new cookieStorage().getStorage();\n   this._q = []; // queue for proxied functions before script load\n-};\n+  this._sending = false;\n+  this._updateScheduled = false;\n \n-Amplitude.prototype._eventId = 0;\n-Amplitude.prototype._identifyId = 0;\n-Amplitude.prototype._sequenceNumber = 0;\n-Amplitude.prototype._sending = false;\n-Amplitude.prototype._lastEventTime = null;\n-Amplitude.prototype._sessionId = null;\n-Amplitude.prototype._newSession = false;\n-Amplitude.prototype._updateScheduled = false;\n+  // event meta data\n+  this._eventId = 0;\n+  this._identifyId = 0;\n+  this._lastEventTime = null;\n+  this._newSession = false;\n+  this._sequenceNumber = 0;\n+  this._sessionId = null;\n+};\n \n Amplitude.prototype.Identify = Identify;\n \n /**\n- * Initializes Amplitude.\n- * apiKey The API Key for your app\n- * opt_userId An identifier for this user\n- * opt_config Configuration options\n- *   - saveEvents (boolean) Whether to save events to local storage. Defaults to true.\n- *   - includeUtm (boolean) Whether to send utm parameters with events. Defaults to false.\n- *   - includeReferrer (boolean) Whether to send referrer info with events. Defaults to false.\n+ * Initializes the Amplitude Javascript SDK with your apiKey and any optional configurations.\n+ * This is required before any other methods can be called.\n+ * @public\n+ * @param {string} apiKey - The API key for your app.\n+ * @param {string} opt_userId - (optional) An identifier for this user.\n+ * @param {object} opt_config - (optional) Configuration options.\n+ * See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#configuration-options} for list of options and default values.\n+ * @param {function} opt_callback - (optional) Provide a callback function to run after initialization is complete.\n+ * @example amplitude.init('API_KEY', 'USER_ID', {includeReferrer: true, includeUtm: true}, function() { alert('init complete'); });\n  */\n-Amplitude.prototype.init = function(apiKey, opt_userId, opt_config, callback) {\n+Amplitude.prototype.init = function init(apiKey, opt_userId, opt_config, opt_callback) {\n+  if (type(apiKey) !== 'string' || utils.isEmptyString(apiKey)) {","path":"src/amplitude.js","position":85,"original_position":85,"commit_id":"b9dbacd3617910695bb3b7ec4c8365f9dd43116c","original_commit_id":"b9dbacd3617910695bb3b7ec4c8365f9dd43116c","user":{"login":"djih","id":4776584,"avatar_url":"https://avatars.githubusercontent.com/u/4776584?v=3","gravatar_id":"","url":"https://api.github.com/users/djih","html_url":"https://github.com/djih","followers_url":"https://api.github.com/users/djih/followers","following_url":"https://api.github.com/users/djih/following{/other_user}","gists_url":"https://api.github.com/users/djih/gists{/gist_id}","starred_url":"https://api.github.com/users/djih/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djih/subscriptions","organizations_url":"https://api.github.com/users/djih/orgs","repos_url":"https://api.github.com/users/djih/repos","events_url":"https://api.github.com/users/djih/events{/privacy}","received_events_url":"https://api.github.com/users/djih/received_events","type":"User","site_admin":false},"body":"Aggressively validate input. This includes checking the type, as well as for empty strings","created_at":"2016-04-04T23:36:07Z","updated_at":"2016-04-04T23:36:07Z","html_url":"https://github.com/amplitude/Amplitude-Javascript/pull/64#discussion_r58467035","pull_request_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/64","_links":{"self":{"href":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/comments/58467035"},"html":{"href":"https://github.com/amplitude/Amplitude-Javascript/pull/64#discussion_r58467035"},"pull_request":{"href":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/64"}}},"pull_request":{"url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/64","id":65022696,"html_url":"https://github.com/amplitude/Amplitude-Javascript/pull/64","diff_url":"https://github.com/amplitude/Amplitude-Javascript/pull/64.diff","patch_url":"https://github.com/amplitude/Amplitude-Javascript/pull/64.patch","issue_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues/64","number":64,"state":"open","locked":false,"title":"Defensive cleanup","user":{"login":"djih","id":4776584,"avatar_url":"https://avatars.githubusercontent.com/u/4776584?v=3","gravatar_id":"","url":"https://api.github.com/users/djih","html_url":"https://github.com/djih","followers_url":"https://api.github.com/users/djih/followers","following_url":"https://api.github.com/users/djih/following{/other_user}","gists_url":"https://api.github.com/users/djih/gists{/gist_id}","starred_url":"https://api.github.com/users/djih/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djih/subscriptions","organizations_url":"https://api.github.com/users/djih/orgs","repos_url":"https://api.github.com/users/djih/repos","events_url":"https://api.github.com/users/djih/events{/privacy}","received_events_url":"https://api.github.com/users/djih/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-02T00:52:45Z","updated_at":"2016-04-04T23:36:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"80f11378b258994ce5de53fe4adf92b31c5a6735","assignee":{"login":"djih","id":4776584,"avatar_url":"https://avatars.githubusercontent.com/u/4776584?v=3","gravatar_id":"","url":"https://api.github.com/users/djih","html_url":"https://github.com/djih","followers_url":"https://api.github.com/users/djih/followers","following_url":"https://api.github.com/users/djih/following{/other_user}","gists_url":"https://api.github.com/users/djih/gists{/gist_id}","starred_url":"https://api.github.com/users/djih/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djih/subscriptions","organizations_url":"https://api.github.com/users/djih/orgs","repos_url":"https://api.github.com/users/djih/repos","events_url":"https://api.github.com/users/djih/events{/privacy}","received_events_url":"https://api.github.com/users/djih/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/64/commits","review_comments_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/64/comments","review_comment_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues/64/comments","statuses_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/statuses/b9dbacd3617910695bb3b7ec4c8365f9dd43116c","head":{"label":"amplitude:defensive_cleanup","ref":"defensive_cleanup","sha":"b9dbacd3617910695bb3b7ec4c8365f9dd43116c","user":{"login":"amplitude","id":2291562,"avatar_url":"https://avatars.githubusercontent.com/u/2291562?v=3","gravatar_id":"","url":"https://api.github.com/users/amplitude","html_url":"https://github.com/amplitude","followers_url":"https://api.github.com/users/amplitude/followers","following_url":"https://api.github.com/users/amplitude/following{/other_user}","gists_url":"https://api.github.com/users/amplitude/gists{/gist_id}","starred_url":"https://api.github.com/users/amplitude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplitude/subscriptions","organizations_url":"https://api.github.com/users/amplitude/orgs","repos_url":"https://api.github.com/users/amplitude/repos","events_url":"https://api.github.com/users/amplitude/events{/privacy}","received_events_url":"https://api.github.com/users/amplitude/received_events","type":"Organization","site_admin":false},"repo":{"id":7568671,"name":"Amplitude-Javascript","full_name":"amplitude/Amplitude-Javascript","owner":{"login":"amplitude","id":2291562,"avatar_url":"https://avatars.githubusercontent.com/u/2291562?v=3","gravatar_id":"","url":"https://api.github.com/users/amplitude","html_url":"https://github.com/amplitude","followers_url":"https://api.github.com/users/amplitude/followers","following_url":"https://api.github.com/users/amplitude/following{/other_user}","gists_url":"https://api.github.com/users/amplitude/gists{/gist_id}","starred_url":"https://api.github.com/users/amplitude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplitude/subscriptions","organizations_url":"https://api.github.com/users/amplitude/orgs","repos_url":"https://api.github.com/users/amplitude/repos","events_url":"https://api.github.com/users/amplitude/events{/privacy}","received_events_url":"https://api.github.com/users/amplitude/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/amplitude/Amplitude-Javascript","description":"Javascript SDK for Amplitude","fork":false,"url":"https://api.github.com/repos/amplitude/Amplitude-Javascript","forks_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/forks","keys_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/teams","hooks_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/hooks","issue_events_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues/events{/number}","events_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/events","assignees_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/assignees{/user}","branches_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/branches{/branch}","tags_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/tags","blobs_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/refs{/sha}","trees_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/statuses/{sha}","languages_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/languages","stargazers_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/stargazers","contributors_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/contributors","subscribers_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/subscribers","subscription_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/subscription","commits_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/commits{/sha}","git_commits_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/commits{/sha}","comments_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/comments{/number}","issue_comment_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues/comments{/number}","contents_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/contents/{+path}","compare_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/merges","archive_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/downloads","issues_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues{/number}","pulls_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls{/number}","milestones_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/milestones{/number}","notifications_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/labels{/name}","releases_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/releases{/id}","deployments_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/deployments","created_at":"2013-01-11T23:04:28Z","updated_at":"2016-03-30T10:31:55Z","pushed_at":"2016-04-04T23:27:55Z","git_url":"git://github.com/amplitude/Amplitude-Javascript.git","ssh_url":"git@github.com:amplitude/Amplitude-Javascript.git","clone_url":"https://github.com/amplitude/Amplitude-Javascript.git","svn_url":"https://github.com/amplitude/Amplitude-Javascript","homepage":null,"size":2033,"stargazers_count":35,"watchers_count":35,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":7,"forks":8,"open_issues":7,"watchers":35,"default_branch":"master"}},"base":{"label":"amplitude:master","ref":"master","sha":"b79a5a524936b7d8adbf4f249b20cde829c84ee2","user":{"login":"amplitude","id":2291562,"avatar_url":"https://avatars.githubusercontent.com/u/2291562?v=3","gravatar_id":"","url":"https://api.github.com/users/amplitude","html_url":"https://github.com/amplitude","followers_url":"https://api.github.com/users/amplitude/followers","following_url":"https://api.github.com/users/amplitude/following{/other_user}","gists_url":"https://api.github.com/users/amplitude/gists{/gist_id}","starred_url":"https://api.github.com/users/amplitude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplitude/subscriptions","organizations_url":"https://api.github.com/users/amplitude/orgs","repos_url":"https://api.github.com/users/amplitude/repos","events_url":"https://api.github.com/users/amplitude/events{/privacy}","received_events_url":"https://api.github.com/users/amplitude/received_events","type":"Organization","site_admin":false},"repo":{"id":7568671,"name":"Amplitude-Javascript","full_name":"amplitude/Amplitude-Javascript","owner":{"login":"amplitude","id":2291562,"avatar_url":"https://avatars.githubusercontent.com/u/2291562?v=3","gravatar_id":"","url":"https://api.github.com/users/amplitude","html_url":"https://github.com/amplitude","followers_url":"https://api.github.com/users/amplitude/followers","following_url":"https://api.github.com/users/amplitude/following{/other_user}","gists_url":"https://api.github.com/users/amplitude/gists{/gist_id}","starred_url":"https://api.github.com/users/amplitude/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amplitude/subscriptions","organizations_url":"https://api.github.com/users/amplitude/orgs","repos_url":"https://api.github.com/users/amplitude/repos","events_url":"https://api.github.com/users/amplitude/events{/privacy}","received_events_url":"https://api.github.com/users/amplitude/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/amplitude/Amplitude-Javascript","description":"Javascript SDK for Amplitude","fork":false,"url":"https://api.github.com/repos/amplitude/Amplitude-Javascript","forks_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/forks","keys_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/teams","hooks_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/hooks","issue_events_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues/events{/number}","events_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/events","assignees_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/assignees{/user}","branches_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/branches{/branch}","tags_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/tags","blobs_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/refs{/sha}","trees_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/statuses/{sha}","languages_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/languages","stargazers_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/stargazers","contributors_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/contributors","subscribers_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/subscribers","subscription_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/subscription","commits_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/commits{/sha}","git_commits_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/git/commits{/sha}","comments_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/comments{/number}","issue_comment_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues/comments{/number}","contents_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/contents/{+path}","compare_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/merges","archive_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/downloads","issues_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues{/number}","pulls_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls{/number}","milestones_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/milestones{/number}","notifications_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/labels{/name}","releases_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/releases{/id}","deployments_url":"https://api.github.com/repos/amplitude/Amplitude-Javascript/deployments","created_at":"2013-01-11T23:04:28Z","updated_at":"2016-03-30T10:31:55Z","pushed_at":"2016-04-04T23:27:55Z","git_url":"git://github.com/amplitude/Amplitude-Javascript.git","ssh_url":"git@github.com:amplitude/Amplitude-Javascript.git","clone_url":"https://github.com/amplitude/Amplitude-Javascript.git","svn_url":"https://github.com/amplitude/Amplitude-Javascript","homepage":null,"size":2033,"stargazers_count":35,"watchers_count":35,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":7,"forks":8,"open_issues":7,"watchers":35,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/64"},"html":{"href":"https://github.com/amplitude/Amplitude-Javascript/pull/64"},"issue":{"href":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues/64"},"comments":{"href":"https://api.github.com/repos/amplitude/Amplitude-Javascript/issues/64/comments"},"review_comments":{"href":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/64/comments"},"review_comment":{"href":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amplitude/Amplitude-Javascript/pulls/64/commits"},"statuses":{"href":"https://api.github.com/repos/amplitude/Amplitude-Javascript/statuses/b9dbacd3617910695bb3b7ec4c8365f9dd43116c"}}}}