ApplicationInsights-JS/README.md

89 строки
5.2 KiB
Markdown
Исходник Обычный вид История

2015-04-15 23:40:58 +03:00
# Microsoft Application Insights JavaScript SDK
2015-08-18 16:10:32 +03:00
[Application Insights](https://azure.microsoft.com/services/application-insights/) tells you about your app's performance and usage. By adding a few lines of code to your web pages, you get data about how many users you have, which pages are most popular, how fast pages load, whether they throw exceptions, and more. And you can add code to track more detailed user activity.
## Try Application Insights with JavaScript SDK - no Azure subscription required
2015-08-18 16:10:32 +03:00
If you don't have an Azure subscription and would like to try Application Insights on one of your own web pages, visit [Try Application Insights Now](http://aka.ms/ainow).
## Get started
2016-05-24 19:14:20 +03:00
To use this SDK, you'll need a subscription to [Microsoft Azure](https://azure.com). Application Insights has a free subscription option.
2016-05-24 19:04:05 +03:00
In the [Azure Preview Portal](https://portal.azure.com), create new or open an existing Application Insights resource.
2016-05-30 10:45:10 +03:00
### Use JS `snippet` and initialize dynamically (download full Application Insights script from CDN)
2016-05-30 10:32:33 +03:00
Use this method for an MVC application. Get "code to monitor my web pages" from the Quick Start page,
and insert it in the head of your web pages. Application Insights script will be downloaded
2016-05-30 10:45:10 +03:00
from CDN or you can override the script hosting location by specifying `url` parameter in the config.
```
<script type="text/javascript">
var appInsights = window.appInsights || function (config) {
function s(config) { t[config] = function () { var i = arguments; t.queue.push(function () { t[config].apply(t, i) }) } } var t = { config: config }, r = document, f = window, e = "script", o = r.createElement(e), i, u; for (o.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", r.getElementsByTagName(e)[0].parentNode.appendChild(o), t.cookie = r.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) s("track" + i.pop()); return config.disableExceptionTracking || (i = "onerror", s("_" + i), u = f[i], f[i] = function (config, r, f, e, o) { var s = u && u(config, r, f, e, o); return s !== !0 && t["_" + i](config, r, f, e, o), s }), t
}({
instrumentationKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
});
window.appInsights = appInsights;
appInsights.trackPageView();
```
2016-05-24 19:14:20 +03:00
[Learn more.](https://azure.microsoft.com/documentation/articles/app-insights-javascript/)
2016-05-24 19:04:05 +03:00
2016-05-30 10:45:10 +03:00
### Import as a module and initialize dynamically (download full Application Insights script from CDN)
2016-05-30 10:32:33 +03:00
Use this method for a modern JS application that is using modules. Just like in `snippet` scenario the full script will be downloaded from CDN.
2016-05-24 19:04:05 +03:00
* Obtain instrumentation key from your Application Insights resource
2016-05-24 19:14:20 +03:00
* Install applicationinsights-js with npm
2016-05-24 19:04:05 +03:00
`npm install applicationinsights-js`
2016-05-30 10:32:33 +03:00
* Import and call `downloadAndSetup` to initialize it. You can override the script hosting location by specifying `url` parameter in the config
2016-05-24 19:14:20 +03:00
```
/* import AppInsights */
2016-05-30 10:17:58 +03:00
import {AppInsights} from "applicationinsights-js"
2016-05-24 19:14:20 +03:00
2016-05-30 10:17:58 +03:00
/* Call downloadAndSetup to download full ApplicationInsights script from CDN and initialize it with instrumentation key */
2016-05-30 10:45:10 +03:00
AppInsights.downloadAndSetup({ instrumentationKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" });
2016-05-24 19:14:20 +03:00
/* example: track page view */
AppInsights.trackPageView(
"FirstPage", /* (optional) page name */
null, /* (optional) page url if available */
{ prop1: "prop1", prop2: "prop2" }, /* (optional) dimension dictionary */
{ measurement1: 1 }, /* (optional) metric dictionary */
123 /* page view duration in milliseconds */
);
/* example: track event */
AppInsights.trackEvent("TestEvent", { prop1: "prop1", prop2: "prop2" }, { measurement1: 1 });
```
2015-04-10 01:48:47 +03:00
2015-07-22 01:51:05 +03:00
## API reference
2015-08-18 16:10:32 +03:00
Data on users, page views, and exceptions are provided out of the box. You can write your own code to track specific events and metrics.
See:
* [JavaScript API reference](https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md)
* [API overview with portal examples](https://azure.microsoft.com/documentation/articles/app-insights-api-custom-events-metrics/)
2015-07-22 01:51:05 +03:00
2015-04-10 01:48:47 +03:00
## To build:
* Visual Studio 2013 Ultimate with Update 4 or later
2015-04-10 01:48:47 +03:00
* Clone the Git repository
2015-04-15 23:45:18 +03:00
* Open Visual Studio solution (devenv JavaScript\Microsoft.ApplicationInsights.JavaScript.sln)
* Build solution in Visual Studio
## To run check-in tests
2015-08-03 23:18:33 +03:00
* `powershell "& .\RunTestsInBrowser.ps1"` to run `Tests.html` in a browser (you might need to call Set-ExecutionPolicy to be able to execute the script)
* Don't forget to build the solution after changing TypeScript files
* Refresh Tests.html in the browser to re-run tests
2015-08-03 23:45:25 +03:00
## Check out the Wiki for other useful info
2015-08-03 23:45:25 +03:00
https://github.com/Microsoft/ApplicationInsights-JS/wiki
## Contributing
We strongly welcome and encourage contributions to this project. Please read the [contributor's guide][ContribGuide] located in the ApplicationInsights-Home repository. If making a large change we request that you open an [issue][GitHubIssue] first. We follow the [Git Flow][GitFlow] approach to branching.
2016-01-05 21:31:40 +03:00
[ContribGuide]: https://github.com/Microsoft/ApplicationInsights-Home/blob/master/CONTRIBUTING.md
[GitFlow]: http://nvie.com/posts/a-successful-git-branching-model/
[GitHubIssue]: https://github.com/Microsoft/ApplicationInsights-JS/issues