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

angular-applicationinsights

v0.3.1

Published

An angularJS module for sending application telemetry to Microsoft Application Insights

Downloads

806

Readme

angular-applicationinsights

npm version license Build Status Dependency Status Coverage Status Code Climate

An implementation of Microsoft Application Insights as a 100% AngularJS module. This module does not utilize the offical Application Insights Javascript SDK, in order to avoid depending on global code outside of the AngularJS platform scope.

Getting Started

Prerequisites

###Installation

####Via Package

Bower
bower install angular-applicationinsights
NPM
npm i angular-applicationinsights
Nuget
Install-Package angular-applicationinsights

####From Source

> git clone https://github.com/VladimirRybalko/angular-applicationinsights.git
> cd angular-applicationinsights
> npm install
> grunt

Note: the angular-applicationinsights.js file will be in the build/ folder after running grunt.

###Setup

Add a reference to the angular-applicationinsights.js file in your main html file:

   <!-- load angular and angular routes via CDN -->
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.js"></script>
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular-route.js"></script>
	<!-- load application insights after the angular script, but before your main application module -->
   <script src="build/angular-applicationinsights.js"></script>
   <script language="javascript">
		var amazingApp = angular.module('amazingApp', ['ApplicationInsightsModule']);
   </script>

Configure the provider during your application module's config phase:

<script language="javascript">
	var amazingApp = angular.module('amazingApp', ['ApplicationInsightsModule']);

	amazingApp.config(function(applicationInsightsServiceProvider){
		var options = { applicationName:'amazingApp' };
		// Configuration options are described below 	 
        applicationInsightsServiceProvider.configure('<PUT YOUR APPLICATION INSIGHTS KEY HERE', options );
    });
 </script>

Basic automatic telemetry will be gathered out of the box, but for a direct reference inject the applicationInsightsService into your code:

	amazingApp.controller('mainController',['applicationInsightsService',function(applicationInsightsService){
	applicationInsightsService.trackEvent('An amazing Event happened');
}]);

###Configuration The options object passed to the configure( iKey, options ) has a number of valid settings. Their names and default values are as follows:

var options = {
	// applicationName: used as a 'friendly name' prefix to url paths
	// ex: myAmazingapp/mainView
	applicationName:'',
	// autoPageViewTracking: enables the sending a event to Application Insights when 
	// ever the $locationChangeSuccess event is fired on the rootScope
	autoPageViewTracking: true,
	// autoStateChangeTracking: enables the sending a event to Application Insights when 
	// ever the $stateChangeSuccess event is fired on the rootScope. To enable 'autoPageViewTracking' option should be set too. 
	autoStateChangeTracking: false,
	// autoLogTracking: enables the interception of calls to the $log service and have the trace 
	// data sent to Application Insights.
	autoLogTracking: true,
	// autoExceptionTracking: enables calls to the $exceptionHandler service, usually unhandled exceptions, to have the error and stack data sent to Application Insights.
	autoExceptionTracking: true,
	// sessionInactivityTimeout: The time (in milliseconds) that a user session can be inactive, before a new session will be created (on the next api call). Default is 30mins.
	sessionInactivityTimeout: 1800000,
	// developerMode: Makes the service not post anything to AI but print it to the console instead
	developerMode: false
	};
	

API Reference

trackEvent

Sends a custom event to Application Insights.

// name(String) : Required - the name of the event to be shown in reports.
// properties (Hash) : Optional - a String/String hash object of properties to associate with this event.
// metrics (Hash) : Optional - a String/Number hash object of metrics to associate with this event.

 applicationInsightsService.trackEvent( name, properties, metrics );

trackException

Sends error data to Application Insights.

// exception (Error) : Required - the error object to be processed.
// properties (Hash): Optional - a String/String hash object of properties to associate with this exception

 applicationInsightsService.trackException(exception, properties);

Note: if the autoTrackExceptions option is enabled, this method will be called any time the $exceptionHandler is invoked.

	try
	{
		// z is undefined.
		1 + z;
	}
	catch(e)
	{
		// this will call trackException. Unhandled exceptions will be caught by angularJS and directed to the $exceptionHandler.
		$exceptionHandler(e);
	}

trackMetric

Sends a metric consisting of a name/value pair to Application Insights

// name(String) : Required - the name of the Metric.
// value (Number) : Required -  the value of the metric.
// properties (Hash) : Optional - a String/String hash object of properties to associate with this metric.


 applicationInsightsService.trackMetric( name, value, properties );

trackPageView

Sends telemetry data to Application Insights signifying a view change has occured.

// viewName (String) : Optional - the name of the Page/View to be shown in reports. Defaults to the url path, prefixed with the app name (ex: amazingApp/view2).
// url (String) : Optional - The full url to associate with this view. Defaults to $location.absUrl();
// properties (Hash) : Optional - a String/String hash object of properties to associate with this event.
// metrics (Hash) : Optional - a String/Number hash object of metrics to associate with this event.

 applicationInsightsService.trackPageView( viewName , url, properties, metrics );

This method is invoked automatically any time the $locationChangeSuccess event is fired, and the autoTrackPageviews configuration option is enabled.

trackTraceMessage

Sends a trace log message to Application Insights.

// message (String) : Required - The log message to send to Application Insights.
// severity (String) : Optional - The message severity Level (debug,info,warn, error). Defaults to 'info'. 
// properties (Hash) : Optional - a String/String hash object of properties to associate with this event.

 applicationInsightsService.trackTraceMessage( message, severity, properties);

If the autoLogTracking option is enabled, trackTraceMessage will be called any time one of the $log service methods are called.

// trackTraceMessage will be invoked with a value of 'message' and 'info' as the parameters.
 $log.info('message');

defineUser

Define a new user metadata.

// userId (Guid) : Required - The user unique identifier.
 applicationInsightsService.defineUser( userId );

defineSession

Define a new session identifier of Application Insights.

// sessionId (Guid) : Required - The session identifier.
 applicationInsightsService.defineSession( sessionId );

defineDevice

Define a new device metadata.

// id (Guid) : Required - The device unique identifier.
// type (String) : Required - The device type.
 applicationInsightsService.defineDevice( id, type );