0.1.1 • Published 7 years ago

angular4-appinsights v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Azure Application Insights for Angular 4.x.x

npm version Known Vulnerabilities CircleCI

This library provides an implementation of Microsoft Azure Application Insights for Angular 4.x.x applications. This library is not dependent on the Node.js SDK for Azure Application Insights, but obtains the script dynamically. For general information please refer to the official Application Insights for Node.js project.

Requirements

Installation

npm install angular4-appinsights

Getting started

  1. Create an Application Insights resource in Azure by following these instructions.
  2. Obtain the Instrumentation Key (aka "ikey") from the resource you created in step 1. Later, you will use it in your scripts.
  3. Add the package as a dependency to your Angular 4.x.x application by installing the package.
  4. Initialize the service as described in the following section.

Usage

There are multiple ways to initialize the service, the following steps describe how to create a singleton service within the core module of your angular app. You can use the configured service in any other module of your app after initialization.

core.module.ts

import { NgModule, Optional, SkipSelf } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AppInsightsService } from 'angular4-appinsights';

@NgModule({
    imports: [CommonModule],
    providers: [AppInsightsService]
})
export class CoreModule {
    constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
        throwIfAlreadyLoaded(parentModule, 'CoreModule');
    }
}

app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent }  from './app.component';
import { CoreModule }    from './core/core.module';

@NgModule({
  imports:      [ BrowserModule, CoreModule]
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';
import { AppInsightsService } from 'angular4-appinsights';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.scss']
})
export class AppComponent implements OnInit {
    constructor(private aiService: AppInsightsService) { }

    ngOnInit() {
        // Initialize the App Insights Service
        this.aiService.init({ instrumentationKey: <ikey> });
    }
}

Help and Issues

Please use GitHub issues if you need help or have issues using the library. We welcome your feedback to continuously improve this library. :+1:

Open an issue on GitHub.

License

This project is licensed under MIT. See LICENSE for details.

Dependencies