{"action":"created","comment":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/54112736","id":54112736,"diff_hunk":"@@ -0,0 +1,115 @@\n+'use strict';\n+\n+var keen = require('keen-js');\n+var oop = require('js/oop');\n+var $ = require('jquery');\n+var uuid = require('uuid');\n+\n+var KeenTracker = oop.defclass({\n+    constructor: function(keenProjectId, keenWriteKey) {\n+        this.keenClient = new keen({\n+            projectId: keenProjectId,\n+            writeKey: keenWriteKey\n+        });\n+        this.init();\n+    },\n+\n+    createOrUpdateKeenSession: function() {\n+        var date = new Date();\n+        var expiresInMinutes = 25;\n+        var expDate = date.setTime(date.getTime() + (expiresInMinutes*60*1000));\n+        if(!$.cookie('keenSessionId')){\n+            $.cookie('keenSessionId', uuid.v1(), {expires: expDate, path: '/'});\n+        } else {\n+            var sessionId = $.cookie('keenSessionId');\n+            $.cookie('keenSessionId', sessionId, {expires: expDate, path: '/'});\n+        }\n+    },\n+\n+    getOrCreateKeenId: function() {\n+        if(!$.cookie('keenUserId')){\n+            $.cookie('keenUserId', uuid.v1(), {expires: 365, path: '/'});\n+        }\n+\n+        return $.cookie('keenUserId');\n+    },\n+\n+    trackPageView: function(){\n+        this.createOrUpdateKeenSession();\n+        var ctx = window.contextVars;","path":"website/static/js/keen.js","position":39,"original_position":39,"commit_id":"ec6f834d521eb27c4fc2a6d6fd02d912c63235a5","original_commit_id":"ec6f834d521eb27c4fc2a6d6fd02d912c63235a5","user":{"login":"sloria","id":2379650,"avatar_url":"https://avatars.githubusercontent.com/u/2379650?v=3","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"body":"`contextVars` should not be used in re-usable modules. Instead, any data this class depends on should be passed in the constructor.","created_at":"2016-02-25T15:34:57Z","updated_at":"2016-02-25T15:34:57Z","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/5049#discussion_r54112736","pull_request_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5049","_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/54112736"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/5049#discussion_r54112736"},"pull_request":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5049"}}},"pull_request":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5049","id":60010262,"html_url":"https://github.com/CenterForOpenScience/osf.io/pull/5049","diff_url":"https://github.com/CenterForOpenScience/osf.io/pull/5049.diff","patch_url":"https://github.com/CenterForOpenScience/osf.io/pull/5049.patch","issue_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5049","number":5049,"state":"open","locked":false,"title":"[WIP][Feature] Analytics migration to Keen IO","user":{"login":"GageGaskins","id":7023074,"avatar_url":"https://avatars.githubusercontent.com/u/7023074?v=3","gravatar_id":"","url":"https://api.github.com/users/GageGaskins","html_url":"https://github.com/GageGaskins","followers_url":"https://api.github.com/users/GageGaskins/followers","following_url":"https://api.github.com/users/GageGaskins/following{/other_user}","gists_url":"https://api.github.com/users/GageGaskins/gists{/gist_id}","starred_url":"https://api.github.com/users/GageGaskins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GageGaskins/subscriptions","organizations_url":"https://api.github.com/users/GageGaskins/orgs","repos_url":"https://api.github.com/users/GageGaskins/repos","events_url":"https://api.github.com/users/GageGaskins/events{/privacy}","received_events_url":"https://api.github.com/users/GageGaskins/received_events","type":"User","site_admin":false},"body":"# Purpose\r\nThis PR will be used as the base PR for migrating all analytics to KeenIO from Piwik.\r\n\r\n# Side Effects\r\nCurrently, Piwik will still be primary analytics for customer facing statistics until all of KeenIO capabilities have been researched. This PR just establishes base event tracking to be used later in the migration.","created_at":"2016-02-19T21:30:47Z","updated_at":"2016-02-25T15:34:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ee222b01b999be44ec268ceedbdecd09f9c812cb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5049/commits","review_comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5049/comments","review_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5049/comments","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/ec6f834d521eb27c4fc2a6d6fd02d912c63235a5","head":{"label":"GageGaskins:feature/keen","ref":"feature/keen","sha":"ec6f834d521eb27c4fc2a6d6fd02d912c63235a5","user":{"login":"GageGaskins","id":7023074,"avatar_url":"https://avatars.githubusercontent.com/u/7023074?v=3","gravatar_id":"","url":"https://api.github.com/users/GageGaskins","html_url":"https://github.com/GageGaskins","followers_url":"https://api.github.com/users/GageGaskins/followers","following_url":"https://api.github.com/users/GageGaskins/following{/other_user}","gists_url":"https://api.github.com/users/GageGaskins/gists{/gist_id}","starred_url":"https://api.github.com/users/GageGaskins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GageGaskins/subscriptions","organizations_url":"https://api.github.com/users/GageGaskins/orgs","repos_url":"https://api.github.com/users/GageGaskins/repos","events_url":"https://api.github.com/users/GageGaskins/events{/privacy}","received_events_url":"https://api.github.com/users/GageGaskins/received_events","type":"User","site_admin":false},"repo":{"id":35901245,"name":"osf.io","full_name":"GageGaskins/osf.io","owner":{"login":"GageGaskins","id":7023074,"avatar_url":"https://avatars.githubusercontent.com/u/7023074?v=3","gravatar_id":"","url":"https://api.github.com/users/GageGaskins","html_url":"https://github.com/GageGaskins","followers_url":"https://api.github.com/users/GageGaskins/followers","following_url":"https://api.github.com/users/GageGaskins/following{/other_user}","gists_url":"https://api.github.com/users/GageGaskins/gists{/gist_id}","starred_url":"https://api.github.com/users/GageGaskins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GageGaskins/subscriptions","organizations_url":"https://api.github.com/users/GageGaskins/orgs","repos_url":"https://api.github.com/users/GageGaskins/repos","events_url":"https://api.github.com/users/GageGaskins/events{/privacy}","received_events_url":"https://api.github.com/users/GageGaskins/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/GageGaskins/osf.io","description":"Facilitating Open Science","fork":true,"url":"https://api.github.com/repos/GageGaskins/osf.io","forks_url":"https://api.github.com/repos/GageGaskins/osf.io/forks","keys_url":"https://api.github.com/repos/GageGaskins/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GageGaskins/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GageGaskins/osf.io/teams","hooks_url":"https://api.github.com/repos/GageGaskins/osf.io/hooks","issue_events_url":"https://api.github.com/repos/GageGaskins/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/GageGaskins/osf.io/events","assignees_url":"https://api.github.com/repos/GageGaskins/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/GageGaskins/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/GageGaskins/osf.io/tags","blobs_url":"https://api.github.com/repos/GageGaskins/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GageGaskins/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GageGaskins/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/GageGaskins/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GageGaskins/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/GageGaskins/osf.io/languages","stargazers_url":"https://api.github.com/repos/GageGaskins/osf.io/stargazers","contributors_url":"https://api.github.com/repos/GageGaskins/osf.io/contributors","subscribers_url":"https://api.github.com/repos/GageGaskins/osf.io/subscribers","subscription_url":"https://api.github.com/repos/GageGaskins/osf.io/subscription","commits_url":"https://api.github.com/repos/GageGaskins/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/GageGaskins/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/GageGaskins/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/GageGaskins/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/GageGaskins/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/GageGaskins/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GageGaskins/osf.io/merges","archive_url":"https://api.github.com/repos/GageGaskins/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GageGaskins/osf.io/downloads","issues_url":"https://api.github.com/repos/GageGaskins/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/GageGaskins/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/GageGaskins/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/GageGaskins/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GageGaskins/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/GageGaskins/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/GageGaskins/osf.io/deployments","created_at":"2015-05-19T18:40:10Z","updated_at":"2015-05-19T18:40:14Z","pushed_at":"2016-02-23T21:10:55Z","git_url":"git://github.com/GageGaskins/osf.io.git","ssh_url":"git@github.com:GageGaskins/osf.io.git","clone_url":"https://github.com/GageGaskins/osf.io.git","svn_url":"https://github.com/GageGaskins/osf.io","homepage":"http://osf.io","size":120590,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"CenterForOpenScience:develop","ref":"develop","sha":"87ea6ae76ed8ff02e5c6450bdd7b869b28523b08","user":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"repo":{"id":10199599,"name":"osf.io","full_name":"CenterForOpenScience/osf.io","owner":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CenterForOpenScience/osf.io","description":"Facilitating Open Science","fork":false,"url":"https://api.github.com/repos/CenterForOpenScience/osf.io","forks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/forks","keys_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/teams","hooks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/hooks","issue_events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/events","assignees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/tags","blobs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/languages","stargazers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/stargazers","contributors_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contributors","subscribers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscribers","subscription_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscription","commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/merges","archive_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/downloads","issues_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/deployments","created_at":"2013-05-21T15:53:37Z","updated_at":"2016-02-25T04:17:58Z","pushed_at":"2016-02-25T15:32:21Z","git_url":"git://github.com/CenterForOpenScience/osf.io.git","ssh_url":"git@github.com:CenterForOpenScience/osf.io.git","clone_url":"https://github.com/CenterForOpenScience/osf.io.git","svn_url":"https://github.com/CenterForOpenScience/osf.io","homepage":"http://osf.io","size":266186,"stargazers_count":192,"watchers_count":192,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":148,"mirror_url":null,"open_issues_count":324,"forks":148,"open_issues":324,"watchers":192,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5049"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/5049"},"issue":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5049"},"comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/5049/comments"},"review_comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5049/comments"},"review_comment":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/5049/commits"},"statuses":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/ec6f834d521eb27c4fc2a6d6fd02d912c63235a5"}}}}