Skip to main content
This guide will walk you through using the BugByBug Angular SDK in your project.
1

Install the SDK

You can install the BugByBug Angular SDK via npm.
npm install @bugbybug/angular
2

Initialization for Standalone Applications (Angular 15+)

Before you can use the SDK, you need to initialize it with your BugByBug project key.Import and initialize the SDK in your app.config.ts file:
import { ApplicationConfig } from '@angular/core';
import { provideBugByBug } from '@bugbybug/angular';

export const appConfig: ApplicationConfig = {
  providers: [
    provideBugByBug({
      apiKey: 'YOUR_PROJECT_API_KEY', // Starts with bbb_
      environment: 'production'
    })
    // ... other providers
  ]
};
3

Initialization for Module-based Applications

Before you can use the SDK, you need to initialize it with your BugByBug project key.Import and initialize the SDK in your app.module.ts file:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { provideBugByBug } from '@bugbybug/angular';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [
    provideBugByBug({
      apiKey: 'YOUR_PROJECT_API_KEY',
      environment: 'production'
    })
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Basic Usage

Once initialized, you can start using the SDK to capture bugs and errors.

Manually capturing an Error

The SDK automatically captures errors within your projects, although, you still have the choose to capture or catch these errors manually like this:
try {
  this.doSomethingRisky();
} catch (error) {
  this.bugByBug.captureException(error, { component: 'LoginComponent' });
}

Identifying users within your authentication

You can use BugByBugService in your authentication component to set the user context.
import { Component } from '@angular/core';
import { BugByBugService } from '@bugbybug/angular';

@Component({ ... })
export class LoginComponent {
  constructor(private bugByBug: BugByBugService) {}

  onLoginSuccess(user: any) {
    this.bugByBug.setUser(user.id, user.email);
  }
}
For more detailed information on other framework integrations, refer to their dedicated guides:

API Reference

For a complete list of available methods and their signatures, refer to the API Reference.