{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/comments/36781099","id":36781099,"diff_hunk":"@@ -0,0 +1,118 @@\n+﻿/// <reference path=\"../AppInsights.ts\" />\n+\n+module Microsoft.ApplicationInsights.Telemetry {\n+    \"use strict\";\n+\n+    /**\n+     * Used to track page visit durations\n+     */\n+    export class PageVisitTimeManager {\n+\n+        private prevPageVisitDataKeyName: string = \"prevPageVisitData\";\n+        private pageVisitTimeTrackingHandler: (pageName: string, pageUrl: string, pageVisitTime: number) => void;\n+\n+        /**\n+         * Creates a new instance of PageVisitTimeManager\n+         * @param pageVisitTimeTrackingHandler Delegate that will be called to send telemetry data to AI (when trackPreviousPageVisit is called)\n+         * @returns {} \n+         */\n+        constructor(pageVisitTimeTrackingHandler: (pageName: string, pageUrl: string, pageVisitTime: number) => void) {\n+            this.pageVisitTimeTrackingHandler = pageVisitTimeTrackingHandler;\n+        }\n+\n+         /**\n+         * Tracks the previous page visit time telemetry (if exists) and starts timing of new page visit time\n+         * @param currentPageName Name of page to begin timing for visit duration\n+         * @param currentPageUrl Url of page to begin timing for visit duration\n+         */\n+        public trackPreviousPageVisit(currentPageName: string, currentPageUrl: string) {\n+            \n+            try {\n+                // Restart timer for new page view\n+                var prevPageVisitTimeData = this.restartPageVisitTimer(currentPageName, currentPageUrl);\n+                \n+                // If there was a page already being timed, track the visit time for it now.\n+                if (prevPageVisitTimeData) {\n+                    this.pageVisitTimeTrackingHandler(prevPageVisitTimeData.pageName, prevPageVisitTimeData.pageUrl, prevPageVisitTimeData.pageVisitTime);\n+                }\n+            } catch (e) {\n+                _InternalLogging.warnToConsole(\"Auto track page visit time failed, metric will not be collected: \" + Util.dump(e));\n+            }\n+        }\n+\n+        /**\n+         * Stops timing of current page (if exists) and starts timing for duration of visit to pageName\n+         * @param pageName Name of page to begin timing visit duration\n+         * @returns {PageVisitData} Page visit data (including duration) of pageName from last call to start or restart, if exists. Null if not. \n+         */\n+        public restartPageVisitTimer(pageName: string, pageUrl: string) {\n+\n+            var prevPageVisitData = this.stopPageVisitTimer();\n+            this.startPageVisitTimer(pageName, pageUrl);\n+\n+            return prevPageVisitData;\n+        }\n+\n+        /**\n+         * Starts timing visit duration of pageName\n+         * @param pageName \n+         * @returns {} \n+         */\n+        public startPageVisitTimer(pageName: string, pageUrl: string) {\n+            if (Util.canUseSessionStorage()) {","path":"JavaScript/JavaScriptSDK/Telemetry/PageVisitTimeManager.ts","position":62,"original_position":62,"commit_id":"fd69304be654e480af08bb60c903fb257591bfb4","original_commit_id":"fd69304be654e480af08bb60c903fb257591bfb4","user":{"login":"MaxShehovtsov","id":10049593,"avatar_url":"https://avatars.githubusercontent.com/u/10049593?v=3","gravatar_id":"","url":"https://api.github.com/users/MaxShehovtsov","html_url":"https://github.com/MaxShehovtsov","followers_url":"https://api.github.com/users/MaxShehovtsov/followers","following_url":"https://api.github.com/users/MaxShehovtsov/following{/other_user}","gists_url":"https://api.github.com/users/MaxShehovtsov/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxShehovtsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxShehovtsov/subscriptions","organizations_url":"https://api.github.com/users/MaxShehovtsov/orgs","repos_url":"https://api.github.com/users/MaxShehovtsov/repos","events_url":"https://api.github.com/users/MaxShehovtsov/events{/privacy}","received_events_url":"https://api.github.com/users/MaxShehovtsov/received_events","type":"User","site_admin":false},"body":"add try/catch to all publics","created_at":"2015-08-11T18:33:13Z","updated_at":"2015-08-11T18:33:13Z","html_url":"https://github.com/Microsoft/ApplicationInsights-JS/pull/47#discussion_r36781099","pull_request_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/47","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/comments/36781099"},"html":{"href":"https://github.com/Microsoft/ApplicationInsights-JS/pull/47#discussion_r36781099"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/47"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/47","id":41516095,"html_url":"https://github.com/Microsoft/ApplicationInsights-JS/pull/47","diff_url":"https://github.com/Microsoft/ApplicationInsights-JS/pull/47.diff","patch_url":"https://github.com/Microsoft/ApplicationInsights-JS/pull/47.patch","issue_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues/47","number":47,"state":"open","locked":false,"title":"Features/page visit time","user":{"login":"giladsu","id":13339944,"avatar_url":"https://avatars.githubusercontent.com/u/13339944?v=3","gravatar_id":"","url":"https://api.github.com/users/giladsu","html_url":"https://github.com/giladsu","followers_url":"https://api.github.com/users/giladsu/followers","following_url":"https://api.github.com/users/giladsu/following{/other_user}","gists_url":"https://api.github.com/users/giladsu/gists{/gist_id}","starred_url":"https://api.github.com/users/giladsu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giladsu/subscriptions","organizations_url":"https://api.github.com/users/giladsu/orgs","repos_url":"https://api.github.com/users/giladsu/repos","events_url":"https://api.github.com/users/giladsu/events{/privacy}","received_events_url":"https://api.github.com/users/giladsu/received_events","type":"User","site_admin":false},"body":"Initial page visit time feature implementation.\r\nFirst time \"typescripting\" so want to get initial feedback before adding tests.\r\n\r\nSpec for feature can be found here: https://microsoft-my.sharepoint.com/personal/yossiy_microsoft_com/Documents/Functional Spec - Page visit time.docx?d=w088104dc384f4ac8b944948f5dc3d1c3 \r\n\r\nChanges include:\r\n\r\n1. Added trackPageVisitTime() method to send metric of time spent viewing a page.  Currently sending a CustomMetric, but will send a dedicated metric in next phases.\r\n\r\n2. Added ability to auto-track page visit time. If auto-track is enabled (for phase 1 default is disabled):\r\n    a. When trackPageView() is called, the SDK also calls trackPageVisitTime() for the previous page visited (if exists).\r\n\r\n     b. Added PageVisitTimeManager class which is in charge of storing pages visited using session storage in order to achieve 2a.\r\n\r\n      c. PageVisitTimeManager exposes 3 methods: restart, stop, and start.  Stop returns previous page viewed (if exists in session storage) and clears storage.  Start adds page passed in to session storage (along with current time for start time).  Restart calls stop, stores return value, calls start, and returns the value stop returned.\r\n\r\n","created_at":"2015-08-03T22:18:19Z","updated_at":"2015-08-11T18:33:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f4987696eb3c4e296e15500078d05f3c0f3f4f57","assignee":{"login":"MaxShehovtsov","id":10049593,"avatar_url":"https://avatars.githubusercontent.com/u/10049593?v=3","gravatar_id":"","url":"https://api.github.com/users/MaxShehovtsov","html_url":"https://github.com/MaxShehovtsov","followers_url":"https://api.github.com/users/MaxShehovtsov/followers","following_url":"https://api.github.com/users/MaxShehovtsov/following{/other_user}","gists_url":"https://api.github.com/users/MaxShehovtsov/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxShehovtsov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxShehovtsov/subscriptions","organizations_url":"https://api.github.com/users/MaxShehovtsov/orgs","repos_url":"https://api.github.com/users/MaxShehovtsov/repos","events_url":"https://api.github.com/users/MaxShehovtsov/events{/privacy}","received_events_url":"https://api.github.com/users/MaxShehovtsov/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/47/commits","review_comments_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/47/comments","review_comment_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues/47/comments","statuses_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/statuses/fd69304be654e480af08bb60c903fb257591bfb4","head":{"label":"Microsoft:features/page_visit_time","ref":"features/page_visit_time","sha":"fd69304be654e480af08bb60c903fb257591bfb4","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":33373292,"name":"ApplicationInsights-JS","full_name":"Microsoft/ApplicationInsights-JS","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/ApplicationInsights-JS","description":"Microsoft Application Insights SDK for JavaScript","fork":false,"url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS","forks_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/forks","keys_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/teams","hooks_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/events","assignees_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/tags","blobs_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/languages","stargazers_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/subscription","commits_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/merges","archive_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/downloads","issues_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/releases{/id}","created_at":"2015-04-03T17:01:17Z","updated_at":"2015-06-18T22:17:09Z","pushed_at":"2015-08-11T00:10:13Z","git_url":"git://github.com/Microsoft/ApplicationInsights-JS.git","ssh_url":"git@github.com:Microsoft/ApplicationInsights-JS.git","clone_url":"https://github.com/Microsoft/ApplicationInsights-JS.git","svn_url":"https://github.com/Microsoft/ApplicationInsights-JS","homepage":null,"size":5624,"stargazers_count":13,"watchers_count":13,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":14,"forks":5,"open_issues":14,"watchers":13,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"97c791b52dc97bff263f44445d46ee1412712902","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":33373292,"name":"ApplicationInsights-JS","full_name":"Microsoft/ApplicationInsights-JS","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/ApplicationInsights-JS","description":"Microsoft Application Insights SDK for JavaScript","fork":false,"url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS","forks_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/forks","keys_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/teams","hooks_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/events","assignees_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/tags","blobs_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/languages","stargazers_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/subscription","commits_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/merges","archive_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/downloads","issues_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/releases{/id}","created_at":"2015-04-03T17:01:17Z","updated_at":"2015-06-18T22:17:09Z","pushed_at":"2015-08-11T00:10:13Z","git_url":"git://github.com/Microsoft/ApplicationInsights-JS.git","ssh_url":"git@github.com:Microsoft/ApplicationInsights-JS.git","clone_url":"https://github.com/Microsoft/ApplicationInsights-JS.git","svn_url":"https://github.com/Microsoft/ApplicationInsights-JS","homepage":null,"size":5624,"stargazers_count":13,"watchers_count":13,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":14,"forks":5,"open_issues":14,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/47"},"html":{"href":"https://github.com/Microsoft/ApplicationInsights-JS/pull/47"},"issue":{"href":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues/47"},"comments":{"href":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/issues/47/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/47/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/pulls/47/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/ApplicationInsights-JS/statuses/fd69304be654e480af08bb60c903fb257591bfb4"}}}}