npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chinchilla-software/angularjs-application-insights-web

v2.0.1

Published

AngularJS module for Microsoft Application Insights Javascript v2 SDK

Downloads

8

Readme

Angular JS Azure Application Insights implementation for JS SDK V2

Connect your AngularJS client-side to Microsofts Application Insights with this easy-to-use Module.

Application Insights is an extensible Application Performance Management (APM) service for web developers on multiple platforms. Use it to monitor your live web application. It will automatically detect performance anomalies. It includes powerful analytics tools to help you diagnose issues and to understand what users actually do with your app.

npm NPM Downloads MIT License


Installation

NPM Setup

Install & save the library to your package.json:

$ npm install --save angularjs-application-insights-v2

Including javascript file in the script tag

  • Copy the angularjs-appinsights-v2.min.js from dist folder to your project scripts folder
  • Include this script file into your application shell html file
<script type="text/javascript" src="scripts/angularjs-appinsights-v2.min.js"></script>

Initialization Setup

  • Include ApplicationInsightsModule in your application module dependency
var app = angular.module('<appname>', [....,'ApplicationInsightsModule']);
  • Add the following snippet into your app.js
app.config([
    'applicationInsightsServiceProvider', function (applicationInsightsServiceProvider) {
        applicationInsightsServiceProvider.configure({
            instrumentationKey: 'INSTRUMENTATION_KEY',
            applicationName: '<app name>'
        });
    }
]);

API Specficiations

Once you add the angularjs-appinsights-v2.min.js into your application, it will load necessary sdk files and initialize the Application Insights instance. The initialized instance located by default at window.appInsights. ApplicationInsightsService is an angular service which provides the wrapper the Application Insights instance and it has following API functions.

applicationInsightsService.trackEvent(event: Microsoft.ApplicationInsights.IEventTelemetry, customProperties:object);
applicationInsightsService.startTrackEvent(name: string);
applicationInsightsService.stopTrackEvent(name: string, properties?: object, measurements?:object);
applicationInsightsService.trackPageView(pageView: Microsoft.ApplicationInsights.IPageViewTelemetry, customProperties?:object);
applicationInsightsService.startTrackPage(name?: string);
applicationInsightsService.stopTrackPage(name?: string, url?: string, customProperties?: object);
applicationInsightsService.trackMetric(metric: Microsoft.ApplicationInsights.IMetricTelemetry, customProperties?:object);
applicationInsightsService.trackException(exception: Microsoft.ApplicationInsights.IExceptionTelemetry, customProperties?:object);
applicationInsightsService.trackTrace(trace: Microsoft.ApplicationInsights.ITraceTelemetry, customProperties?: object);
applicationInsightsService.flush();
applicationInsightsService.setAuthenticatedUserContext(authenticatedUserId: string, accountId?: string, storeInCookie?: boolean);
applicationInsightsService.clearAuthenticatedUserContext();
applicationInsightsService._onerror(exception: Microsoft.ApplicationInsights.IAutoExceptionTelemetry);
applicationInsightsService.trackPageViewPerformance(pageViewPerformance: Microsoft.ApplicationInsights.IPageViewPerformanceTelemetry, customProperties?: object});
applicationInsightsService.addTelemetryInitializer(telemetryInitializer: (item: Microsoft.ApplicationInsights.ITelemetryItem) => boolean | void);

Example:

applicationInsightsService.trackEvent({name: 'some event'});
applicationInsightsService.trackPageView({name: 'some page'});
applicationInsightsService.trackPageViewPerformance({name : 'some page', url: 'some url'});
applicationInsightsService.trackException({exception: new Error('some error')});
applicationInsightsService.trackTrace({message: 'some trace'});
applicationInsightsService.trackMetric({name: 'some metric', average: 42});
applicationInsightsService.trackDependencyData({absoluteUrl: 'some url', responseCode: 200, method: 'GET', id: 'some id'});
applicationInsightsService.startTrackPage("pageName");
applicationInsightsService.stopTrackPage("pageName", {customProp1: "some value"});
applicationInsightsService.startTrackEvent("event");
applicationInsightsService.stopTrackEvent("event", {customProp1: "some value"});
applicationInsightsService.setAuthenticatedUserContext('ddd-ddd-dddd-dddd');
applicationInsightsService.clearAuthenticatedUserContext();
applicationInsightsService.flush();

How to send custom events to Application Insights?

  • Inject the ApplicationInsightsService service into a controller
app.controller('testController', function ($scope, .... , $log, applicationInsightsService) {
  • Use the following snippet to send the custom events to your application insights instance
 applicationInsightsService.trackEvent({
            name: "PageLoaded",
            properties:
            {
                "appId": "ddd-fff-ddd-ff-ddfdd-45454",
                "timeStamp": new Date().toDateString(),
                "page": "Explorer Page",
                "action": "page loaded"
            },
            measurements: {
                duration: 567
            }
        });

How to send application traces to Application Insights?

You can send the application traces to application insights to add additional infomration to your telemetry data.

  • Enable the autoLogTracking:true in application insights config inside app.js
app.config([
    'applicationInsightsServiceProvider', function (applicationInsightsServiceProvider) {
        applicationInsightsServiceProvider.configure({
            instrumentationKey: 'INSTRUMENTATION_KEY',
            applicationName: '<app name>',
            autoLogTracking:true
        });
    }
]);
  • Inject the ApplicationInsightsService service into a controller/service
app.controller('testController', function ($scope, .... , $log, applicationInsightsService) {
  • Add the following snippet where you want to add the trace inside your controller or service
$log.info("About page loaded", {name:'about page'});

How to add the telemetry initializer to application insights

Use can use the telemetry intializer to customize the global data which sending to applicaiton insights apart from the custom data. You can use this to set custom role name, operation name, user id, session id, etc. Use the following snippets to add your telemery insitializer

 app.run(["$rootScope", "$location", "applicationInsightsService",
        function ($rootScope, $location, applicationInsightsService) {
             var customTelemetryInitializer = function (envelope) {
                envelope.tags["ai.cloud.role"] = "your role name";
                envelope.tags["ai.cloud.roleInstance"] = "your role instance";
                envelope.tags["ai.operation.name"] = "customized operation name"
             }
             applicationInsightsService.addTelemetryInitializer(customTelemetryInitializer);
        }
 ]);

How to build from the Source?

To build from source follow the following instructions,

  • Download the source to your local computer
  • Install all required packages
$ npm install
  • Build the source with gulp
$ gulp build

Credits

This project inspired by the following projects,

Test porject used from this tjoudeh/FoursquareAngularJS repository.

License

MIT License


Follow online:

Twitter: @tamvasan