{"action":"created","comment":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/46718046","id":46718046,"diff_hunk":"@@ -0,0 +1,100 @@\n+/**\n+ * Copyright 2015 The AMP HTML Authors. All Rights Reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *      http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS-IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+import {getService} from '../../../src/service';\n+import {documentInfoFor} from '../../../src/document-info';\n+import {parseUrl, removeFragment} from '../../../src/url';\n+\n+export function platformVariablesFor(window) {\n+  return getService(window, 'amp-analytics-platform-variables', () => {\n+    return platformVariables(window);\n+  });\n+}\n+\n+export function platformVariablesExpressionFor(window) {\n+  const vars = platformVariablesFor(window);\n+  return new RegExp('\\{(' + Object.keys(vars).join('|') + ')\\}', 'g');\n+}\n+\n+function platformVariables(win) {\n+  return {\n+    /**\n+     * Returns a random value for cache busters.\n+     */\n+    'random': () => {","path":"extensions/amp-analytics/0.1/platform-variables.js","position":null,"original_position":37,"commit_id":"2d9a235f6da90eb4cc0087c17b4ebc3d817a8601","original_commit_id":"7b250cb5d997151f8f7c79445ee8eec6630f5d48","user":{"login":"btownsend","id":700318,"avatar_url":"https://avatars.githubusercontent.com/u/700318?v=3","gravatar_id":"","url":"https://api.github.com/users/btownsend","html_url":"https://github.com/btownsend","followers_url":"https://api.github.com/users/btownsend/followers","following_url":"https://api.github.com/users/btownsend/following{/other_user}","gists_url":"https://api.github.com/users/btownsend/gists{/gist_id}","starred_url":"https://api.github.com/users/btownsend/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/btownsend/subscriptions","organizations_url":"https://api.github.com/users/btownsend/orgs","repos_url":"https://api.github.com/users/btownsend/repos","events_url":"https://api.github.com/users/btownsend/events{/privacy}","received_events_url":"https://api.github.com/users/btownsend/received_events","type":"User","site_admin":false},"body":"Although url-replacements is extensible, a design where tokens are simply uppercase strings will run into problems if one token identifier contains a substring of any other token identifier. Since we allow publishers to specify their own tokens (in the amp-analytics config / trigger config) we're going to run into that case eventually.\r\n\r\nI haven't thought this through very deeply, but on the surface it seems easier to implement a system where tokens can be identified in a template string without knowledge of all possible token identifiers. E.g., if tokens are contained within curly braces, you can do something like this:\r\n\r\n  templateString.replace(/{([^}]*)}/g, (m) => { return dataModel.get(m) });\r\n\r\n(vs. the concatenation of all identifiers approach in url-replacement.)\r\n\r\n\r\n\r\n","created_at":"2015-12-04T18:59:58Z","updated_at":"2015-12-04T18:59:58Z","html_url":"https://github.com/ampproject/amphtml/pull/982#discussion_r46718046","pull_request_url":"https://api.github.com/repos/ampproject/amphtml/pulls/982","_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/46718046"},"html":{"href":"https://github.com/ampproject/amphtml/pull/982#discussion_r46718046"},"pull_request":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/982"}}},"pull_request":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/982","id":51314023,"html_url":"https://github.com/ampproject/amphtml/pull/982","diff_url":"https://github.com/ampproject/amphtml/pull/982.diff","patch_url":"https://github.com/ampproject/amphtml/pull/982.patch","issue_url":"https://api.github.com/repos/ampproject/amphtml/issues/982","number":982,"state":"open","locked":false,"title":"Added a very basic version of analytics for AMP.","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":"This is the first PR in a series of PRs to implement the spec  outlined in #871.\r\n\r\nIn this commit, the tag parses the inline config and uses one builtin type to listen for\r\ndocument.load events and sends a GET request when that happens. There is\r\nprimitive support for request templates and platform variables.\r\n\r\nThings that are still to come:\r\n- Support for more platform variables (future PR)\r\n- Better instrumentation class (future PR)\r\n- User specified variables (future PR)\r\n- Readme.md (Future PR)","created_at":"2015-11-20T03:28:29Z","updated_at":"2015-12-04T18:59:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9602837563ccf5883b28e377199233562e376512","assignee":{"login":"dvoytenko","id":726049,"avatar_url":"https://avatars.githubusercontent.com/u/726049?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoytenko","html_url":"https://github.com/dvoytenko","followers_url":"https://api.github.com/users/dvoytenko/followers","following_url":"https://api.github.com/users/dvoytenko/following{/other_user}","gists_url":"https://api.github.com/users/dvoytenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoytenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoytenko/subscriptions","organizations_url":"https://api.github.com/users/dvoytenko/orgs","repos_url":"https://api.github.com/users/dvoytenko/repos","events_url":"https://api.github.com/users/dvoytenko/events{/privacy}","received_events_url":"https://api.github.com/users/dvoytenko/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/ampproject/amphtml/pulls/982/commits","review_comments_url":"https://api.github.com/repos/ampproject/amphtml/pulls/982/comments","review_comment_url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ampproject/amphtml/issues/982/comments","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/2d9a235f6da90eb4cc0087c17b4ebc3d817a8601","head":{"label":"avimehta:master","ref":"master","sha":"2d9a235f6da90eb4cc0087c17b4ebc3d817a8601","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}","created_at":"2015-10-15T17:06:23Z","updated_at":"2015-10-28T18:43:37Z","pushed_at":"2015-12-02T23:06:34Z","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":13639,"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":"f7c5bd999e65e63a7b9a6831ffbcb8d27bb88a87","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}","created_at":"2015-09-01T22:10:53Z","updated_at":"2015-12-04T17:53:16Z","pushed_at":"2015-12-04T18:48:49Z","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":14940,"stargazers_count":4836,"watchers_count":4836,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":456,"mirror_url":null,"open_issues_count":158,"forks":456,"open_issues":158,"watchers":4836,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/982"},"html":{"href":"https://github.com/ampproject/amphtml/pull/982"},"issue":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/982"},"comments":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/982/comments"},"review_comments":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/982/comments"},"review_comment":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/982/commits"},"statuses":{"href":"https://api.github.com/repos/ampproject/amphtml/statuses/2d9a235f6da90eb4cc0087c17b4ebc3d817a8601"}}}}