{"action":"created","comment":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/51824644","id":51824644,"diff_hunk":"@@ -148,6 +187,71 @@ class InstrumentationService {\n   }\n \n   /**\n+   * Register for a listener to be called when the boundaries specified in\n+   * config are reached.\n+   * @param {!JSONObject} config the config that specifies the boundaries.\n+   * @param {Function} listener\n+   * @private\n+   */\n+  registerScrollTrigger_(config, listener) {\n+    if (!Array.isArray(config['vertical-boundaries']) &&\n+        !Array.isArray(config['horizontal-boundaries'])) {\n+      return;\n+    }\n+\n+    // Ensure that the scroll events are being listened to.\n+    if (!this.scrollHandlerRegistered_) {\n+      this.scrollHandlerRegistered_ = true;\n+      this.viewport_.onChanged(this.onScroll_.bind(this));\n+    }\n+\n+    const triggerScrollEvents = function(bounds, scrollPos) {\n+      if (!scrollPos) {\n+        return;\n+      }\n+      for (const b in bounds) {\n+        if (b > scrollPos || bounds[b]) {\n+          continue;\n+        }\n+        bounds[b] = true;\n+        listener(new AnalyticsEvent(AnalyticsEventType.SCROLL));\n+      }\n+    };\n+\n+    const boundsV = this.normalizeBoundaries_(config['vertical-boundaries']);\n+    const boundsH = this.normalizeBoundaries_(config['horizontal-boundaries']);\n+    this.scrollObservable_.add(e => {\n+      triggerScrollEvents(boundsV,\n+          (e.top + e.height) * 100 / this.viewport_.getScrollHeight());\n+      triggerScrollEvents(boundsH,\n+          (e.left + e.width) * 100 / this.viewport_.getScrollWidth());\n+    });\n+  }\n+\n+  /**","path":"extensions/amp-analytics/0.1/instrumentation.js","position":176,"original_position":176,"commit_id":"2f845a43d908ab21367e4f956af730e0a26875b1","original_commit_id":"2f845a43d908ab21367e4f956af730e0a26875b1","user":{"login":"cramforce","id":89679,"avatar_url":"https://avatars.githubusercontent.com/u/89679?v=3","gravatar_id":"","url":"https://api.github.com/users/cramforce","html_url":"https://github.com/cramforce","followers_url":"https://api.github.com/users/cramforce/followers","following_url":"https://api.github.com/users/cramforce/following{/other_user}","gists_url":"https://api.github.com/users/cramforce/gists{/gist_id}","starred_url":"https://api.github.com/users/cramforce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cramforce/subscriptions","organizations_url":"https://api.github.com/users/cramforce/orgs","repos_url":"https://api.github.com/users/cramforce/repos","events_url":"https://api.github.com/users/cramforce/events{/privacy}","received_events_url":"https://api.github.com/users/cramforce/received_events","type":"User","site_admin":false},"body":"Please describe algorithm.","created_at":"2016-02-04T03:16:31Z","updated_at":"2016-02-04T03:16:31Z","html_url":"https://github.com/ampproject/amphtml/pull/1767#discussion_r51824644","pull_request_url":"https://api.github.com/repos/ampproject/amphtml/pulls/1767","_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/51824644"},"html":{"href":"https://github.com/ampproject/amphtml/pull/1767#discussion_r51824644"},"pull_request":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/1767"}}},"pull_request":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/1767","id":58209870,"html_url":"https://github.com/ampproject/amphtml/pull/1767","diff_url":"https://github.com/ampproject/amphtml/pull/1767.diff","patch_url":"https://github.com/ampproject/amphtml/pull/1767.patch","issue_url":"https://api.github.com/repos/ampproject/amphtml/issues/1767","number":1767,"state":"open","locked":false,"title":"Added scroll trigger.","user":{"login":"avimehta","id":179359,"avatar_url":"https://avatars.githubusercontent.com/u/179359?v=3","gravatar_id":"","url":"https://api.github.com/users/avimehta","html_url":"https://github.com/avimehta","followers_url":"https://api.github.com/users/avimehta/followers","following_url":"https://api.github.com/users/avimehta/following{/other_user}","gists_url":"https://api.github.com/users/avimehta/gists{/gist_id}","starred_url":"https://api.github.com/users/avimehta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avimehta/subscriptions","organizations_url":"https://api.github.com/users/avimehta/orgs","repos_url":"https://api.github.com/users/avimehta/repos","events_url":"https://api.github.com/users/avimehta/events{/privacy}","received_events_url":"https://api.github.com/users/avimehta/received_events","type":"User","site_admin":false},"body":"- Updated the example file to have more content so that scroll events can be changed.\r\n- Instead of passing individual config params, pass in whole config into `addListener`.\r\n- Added `scrollWidth`\r\n- Added `scroll` event\r\n- Updated `test-amp-analytics` to use an actual `window` object instead of a fake. As functionality increases, mocking all the properties of window will become painful.\r\n- Updated documentation.\r\n\r\nFixes #1490 \r\n\r\ncc @rudygalfi ","created_at":"2016-02-03T22:16:35Z","updated_at":"2016-02-04T03:16:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7953b09096cb1b1601d80ef0d4a458419a4e54b8","assignee":{"login":"cramforce","id":89679,"avatar_url":"https://avatars.githubusercontent.com/u/89679?v=3","gravatar_id":"","url":"https://api.github.com/users/cramforce","html_url":"https://github.com/cramforce","followers_url":"https://api.github.com/users/cramforce/followers","following_url":"https://api.github.com/users/cramforce/following{/other_user}","gists_url":"https://api.github.com/users/cramforce/gists{/gist_id}","starred_url":"https://api.github.com/users/cramforce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cramforce/subscriptions","organizations_url":"https://api.github.com/users/cramforce/orgs","repos_url":"https://api.github.com/users/cramforce/repos","events_url":"https://api.github.com/users/cramforce/events{/privacy}","received_events_url":"https://api.github.com/users/cramforce/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/ampproject/amphtml/pulls/1767/commits","review_comments_url":"https://api.github.com/repos/ampproject/amphtml/pulls/1767/comments","review_comment_url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ampproject/amphtml/issues/1767/comments","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/2f845a43d908ab21367e4f956af730e0a26875b1","head":{"label":"avimehta:scroll","ref":"scroll","sha":"2f845a43d908ab21367e4f956af730e0a26875b1","user":{"login":"avimehta","id":179359,"avatar_url":"https://avatars.githubusercontent.com/u/179359?v=3","gravatar_id":"","url":"https://api.github.com/users/avimehta","html_url":"https://github.com/avimehta","followers_url":"https://api.github.com/users/avimehta/followers","following_url":"https://api.github.com/users/avimehta/following{/other_user}","gists_url":"https://api.github.com/users/avimehta/gists{/gist_id}","starred_url":"https://api.github.com/users/avimehta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avimehta/subscriptions","organizations_url":"https://api.github.com/users/avimehta/orgs","repos_url":"https://api.github.com/users/avimehta/repos","events_url":"https://api.github.com/users/avimehta/events{/privacy}","received_events_url":"https://api.github.com/users/avimehta/received_events","type":"User","site_admin":false},"repo":{"id":44332738,"name":"amphtml","full_name":"avimehta/amphtml","owner":{"login":"avimehta","id":179359,"avatar_url":"https://avatars.githubusercontent.com/u/179359?v=3","gravatar_id":"","url":"https://api.github.com/users/avimehta","html_url":"https://github.com/avimehta","followers_url":"https://api.github.com/users/avimehta/followers","following_url":"https://api.github.com/users/avimehta/following{/other_user}","gists_url":"https://api.github.com/users/avimehta/gists{/gist_id}","starred_url":"https://api.github.com/users/avimehta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avimehta/subscriptions","organizations_url":"https://api.github.com/users/avimehta/orgs","repos_url":"https://api.github.com/users/avimehta/repos","events_url":"https://api.github.com/users/avimehta/events{/privacy}","received_events_url":"https://api.github.com/users/avimehta/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/avimehta/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":true,"url":"https://api.github.com/repos/avimehta/amphtml","forks_url":"https://api.github.com/repos/avimehta/amphtml/forks","keys_url":"https://api.github.com/repos/avimehta/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/avimehta/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/avimehta/amphtml/teams","hooks_url":"https://api.github.com/repos/avimehta/amphtml/hooks","issue_events_url":"https://api.github.com/repos/avimehta/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/avimehta/amphtml/events","assignees_url":"https://api.github.com/repos/avimehta/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/avimehta/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/avimehta/amphtml/tags","blobs_url":"https://api.github.com/repos/avimehta/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/avimehta/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/avimehta/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/avimehta/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/avimehta/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/avimehta/amphtml/languages","stargazers_url":"https://api.github.com/repos/avimehta/amphtml/stargazers","contributors_url":"https://api.github.com/repos/avimehta/amphtml/contributors","subscribers_url":"https://api.github.com/repos/avimehta/amphtml/subscribers","subscription_url":"https://api.github.com/repos/avimehta/amphtml/subscription","commits_url":"https://api.github.com/repos/avimehta/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/avimehta/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/avimehta/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/avimehta/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/avimehta/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/avimehta/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/avimehta/amphtml/merges","archive_url":"https://api.github.com/repos/avimehta/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/avimehta/amphtml/downloads","issues_url":"https://api.github.com/repos/avimehta/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/avimehta/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/avimehta/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/avimehta/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/avimehta/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/avimehta/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/avimehta/amphtml/deployments","created_at":"2015-10-15T17:06:23Z","updated_at":"2016-01-11T23:25:41Z","pushed_at":"2016-02-03T22:10:53Z","git_url":"git://github.com/avimehta/amphtml.git","ssh_url":"git@github.com:avimehta/amphtml.git","clone_url":"https://github.com/avimehta/amphtml.git","svn_url":"https://github.com/avimehta/amphtml","homepage":"https://ampproject.org","size":23511,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"ampproject:master","ref":"master","sha":"14d9a2e659fa186f674126039e6899eb439e8b2e","user":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"repo":{"id":41766002,"name":"amphtml","full_name":"ampproject/amphtml","owner":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ampproject/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":false,"url":"https://api.github.com/repos/ampproject/amphtml","forks_url":"https://api.github.com/repos/ampproject/amphtml/forks","keys_url":"https://api.github.com/repos/ampproject/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ampproject/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ampproject/amphtml/teams","hooks_url":"https://api.github.com/repos/ampproject/amphtml/hooks","issue_events_url":"https://api.github.com/repos/ampproject/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/ampproject/amphtml/events","assignees_url":"https://api.github.com/repos/ampproject/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/ampproject/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/ampproject/amphtml/tags","blobs_url":"https://api.github.com/repos/ampproject/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ampproject/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ampproject/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/ampproject/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/ampproject/amphtml/languages","stargazers_url":"https://api.github.com/repos/ampproject/amphtml/stargazers","contributors_url":"https://api.github.com/repos/ampproject/amphtml/contributors","subscribers_url":"https://api.github.com/repos/ampproject/amphtml/subscribers","subscription_url":"https://api.github.com/repos/ampproject/amphtml/subscription","commits_url":"https://api.github.com/repos/ampproject/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/ampproject/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/ampproject/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/ampproject/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/ampproject/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/ampproject/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ampproject/amphtml/merges","archive_url":"https://api.github.com/repos/ampproject/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ampproject/amphtml/downloads","issues_url":"https://api.github.com/repos/ampproject/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/ampproject/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/ampproject/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/ampproject/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ampproject/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/ampproject/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/ampproject/amphtml/deployments","created_at":"2015-09-01T22:10:53Z","updated_at":"2016-02-04T03:11:55Z","pushed_at":"2016-02-04T02:25:42Z","git_url":"git://github.com/ampproject/amphtml.git","ssh_url":"git@github.com:ampproject/amphtml.git","clone_url":"https://github.com/ampproject/amphtml.git","svn_url":"https://github.com/ampproject/amphtml","homepage":"https://ampproject.org","size":26892,"stargazers_count":5617,"watchers_count":5617,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":596,"mirror_url":null,"open_issues_count":278,"forks":596,"open_issues":278,"watchers":5617,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/1767"},"html":{"href":"https://github.com/ampproject/amphtml/pull/1767"},"issue":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/1767"},"comments":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/1767/comments"},"review_comments":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/1767/comments"},"review_comment":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/1767/commits"},"statuses":{"href":"https://api.github.com/repos/ampproject/amphtml/statuses/2f845a43d908ab21367e4f956af730e0a26875b1"}}}}