{"id":1823,"date":"2014-02-21T10:54:14","date_gmt":"2014-02-21T10:54:14","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudioalm\/2014\/02\/21\/usage-monitoring-with-application-insights-javascript-sdk-update\/"},"modified":"2022-07-18T02:45:50","modified_gmt":"2022-07-18T10:45:50","slug":"usage-monitoring-with-application-insights-javascript-sdk-update","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/devops\/usage-monitoring-with-application-insights-javascript-sdk-update\/","title":{"rendered":"Usage monitoring with Application Insights JavaScript SDK Update"},"content":{"rendered":"<p>Posting on the behalf of Bret Grinslade.\u00a0 If you want to know more or meet Bret he will also be doing a talk on this topic at <a href=\"http:\/\/northamerica.msteched.com\">TechED 2014<\/a>.<\/p>\n<p>&#42;****************************<\/p>\n<p>\u00a0<\/p>\n<p>We have posted an update to the JavaScript SDK for Usage.\u00a0 Going forward, any time you get the <strong>JavaScript snippet from the Keys &amp; Downloads<\/strong> page it will be with the new API.\u00a0 This change went out on Feb 19th 2014 Wednesday morning.<\/p>\n<p>Your existing JavaScript snippet and code will continue to work as before. However, we would like you to upgrade to the new version when you can as this new version is this is the one we will support going forward for bug fixes.<\/p>\n<p>For more information about the JavaScript SDK please see: <a href=\"http:\/\/msdn.microsoft.com\/library\/dn481098.aspx\">http:\/\/msdn.microsoft.com\/library\/dn481098.aspx<\/a><\/p>\n<p>\u00a0<\/p>\n<p>A few notes on porting:<\/p>\n<ul>\n<li>\n<p>The root object for the AI JavaScript SDK is now <strong>appInsights<\/strong> and no longer <strong>_da<u><\/u><\/strong><\/p>\n<\/li>\n<li>\n<p>The API names have changed to align with the Windows Store and Windows Phone SDKs<\/p>\n<\/li>\n<li>\n<p>appInsights.logPagView to log Page Views<\/p>\n<\/li>\n<li>appInsights.logEvent to log Events<\/li>\n<li>appInsights.start to Initialize with your instrumentation key<\/li>\n<li>appInsights.appUserId (now a property and not a function) to set your custom user id (typically used for logged in users)<\/li>\n<li>\n<p>appInsights.accountId (now a property and not a function) to set your customers account or tenant id<\/p>\n<\/li>\n<li>\n<p>The first parameter of logEvent now includes the path &#8211;\u00a0 so your will need to convert your code from passing two parameters to passing one where event name is appended to the path and separated by a slash<\/p>\n<\/li>\n<li>\n<p>Your old code like __da.trackEvent(\u201cEventNameHere\u201d, \u201cMy\/Path\/Here\u201d);<\/p>\n<\/li>\n<li>Would now be appInsights.logEvent(\u201cMy\/Path\/Here\/EventNameHere\u201d);<\/li>\n<li>The whole signature would look like the following: <\/li>\n<\/ul>\n<blockquote>\n<p><font color=\"#800080\" face=\"Consolas\">if (appInsights) { appInsights.logEvent( <\/font><\/p>\n<p><font color=\"#800080\" face=\"Consolas\">&#8220;open\/buy&#8221;, \/\/ event name <\/font><\/p>\n<p><font color=\"#800080\" face=\"Consolas\">\/\/ Optional properties and metric:<\/font><\/p>\n<p><font color=\"#800080\" face=\"Consolas\">\u00a0\u00a0\u00a0 {Stock : &#8220;Msft&#8221;, Property2: &#8220;Value 2&#8221;}, \/\/ Any number of string properties<\/font><\/p>\n<p><font color=\"#800080\" face=\"Consolas\">\u00a0\u00a0\u00a0 {Price: 42} \/\/At most one numeric metric, and right now has to be an INT <\/font><\/p>\n<p><font color=\"#800080\" face=\"Consolas\">);}<\/font><\/p>\n<\/blockquote>\n<ul>\n<li>You can also now log properties and a metric for page views.\u00a0 However, in the Pages Report you can only report on the metric and not the properties at this time.\u00a0 <\/li>\n<\/ul>\n<p>The metric data (avg, min, max per hour) is found on the <strong>Details<\/strong> tab for the <strong>Pages<\/strong> report as it is for <strong>Events<\/strong> report.<\/p>\n<p><img decoding=\"async\" title=\"image\" style=\"border-top: 0px;border-right: 0px;border-bottom: 0px;border-left: 0px\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/devops\/wp-content\/uploads\/sites\/6\/2014\/02\/3757.image_thumb_09A04C81.png\" width=\"396\" height=\"228\" \/><\/p>\n<p>If you have any question please post them at:<\/p>\n<p><a href=\"https:\/\/aka.ms\/aiforum\">https:\/\/aka.ms\/aiforum<\/a><\/p>\n<p>Thanks. -Bret<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Posting on the behalf of Bret Grinslade.\u00a0 If you want to know more or meet Bret he will also be doing a talk on this topic at TechED 2014. &#42;**************************** \u00a0 We have posted an update to the JavaScript SDK for Usage.\u00a0 Going forward, any time you get the JavaScript snippet from the Keys &amp; [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":45953,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[224,1],"tags":[],"class_list":["post-1823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azure","category-devops"],"acf":[],"blog_post_summary":"<p>Posting on the behalf of Bret Grinslade.\u00a0 If you want to know more or meet Bret he will also be doing a talk on this topic at TechED 2014. &#42;**************************** \u00a0 We have posted an update to the JavaScript SDK for Usage.\u00a0 Going forward, any time you get the JavaScript snippet from the Keys &amp; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/1823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/comments?post=1823"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/posts\/1823\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media\/45953"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/media?parent=1823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/categories?post=1823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/devops\/wp-json\/wp\/v2\/tags?post=1823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}