Guides

How to Integrate SnagRelay Widget into an Angular Application

Add visual bug reporting to Angular apps with the element, requests, session replay and error capture. Works with Angular 14+ and standalone components.

How to Integrate SnagRelay Widget into an Angular Application

Overview

Integrate SnagRelay into your Angular application to capture bug reports with full context. The widget configuration is managed in your dashboard, so the code integration is minimal.

Prerequisites

  • A SnagRelay account (sign up free)
  • Your SnagRelay API key
  • An Angular application (Angular 14+ recommended)

Installation

Option 1: AppComponent (Recommended)

Add the widget initialization to your root AppComponent:

// app.component.ts
import { Component, OnInit } from '@angular/core';

declare global {
  interface Window {
    onSnagRelayLoad: (api: { init: () => void }) => void;
  }
}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent implements OnInit {
  ngOnInit() {
    window.onSnagRelayLoad = function (api) {
      api.init();
    };

    const script = document.createElement('script');
    script.defer = true;
    script.src = 'https://app.snagrelay.com/widget/load/YOUR_API_KEY?onload=onSnagRelayLoad';
    document.head.appendChild(script);
  }
}

Replace YOUR_API_KEY with your actual API key.

Option 2: Angular Service

For a cleaner approach using Angular services:

// snagrelay.service.ts
import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root',
})
export class SnagRelayService {
  private loaded = false;

  init(apiKey: string): void {
    if (this.loaded) return;
    this.loaded = true;

    (window as any).onSnagRelayLoad = function (api: { init: () => void }) {
      api.init();
    };

    const script = document.createElement('script');
    script.defer = true;
    script.src = `https://app.snagrelay.com/widget/load/${apiKey}?onload=onSnagRelayLoad`;
    document.head.appendChild(script);
  }
}

Then inject and call it in AppComponent:

// app.component.ts
import { Component, OnInit } from '@angular/core';
import { SnagRelayService } from './snagrelay.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent implements OnInit {
  constructor(private snagRelay: SnagRelayService) {}

  ngOnInit() {
    this.snagRelay.init('YOUR_API_KEY');
  }
}

Option 3: index.html (Simplest)

The simplest approach: add the script directly to src/index.html:

<!-- src/index.html -->
<!DOCTYPE html>
<html>
  <head>
    ...
  </head>
  <body>
    <app-root></app-root>
    <script>
      window.onSnagRelayLoad = function(api) { api.init(); };
    </script>
    <script
      defer
      src="https://app.snagrelay.com/widget/load/YOUR_API_KEY?onload=onSnagRelayLoad"
    ></script>
  </body>
</html>

Using Environment Variables

Store your API key in Angular's environment files:

// src/environments/environment.ts
export const environment = {
  production: false,
  snagRelayKey: 'your_api_key_here'
};
// In your component
import { environment } from '../environments/environment';

this.snagRelay.init(environment.snagRelayKey);

That's It!

The widget configuration (position, colors, button text, session replay settings, etc.) is managed in your SnagRelay dashboard. Any changes you make there will automatically apply to your widget.

Best Practices

  • Initialize once — Use the service approach with a loaded guard to prevent double-loading
  • Use environment variables — Keep your API key out of source control
  • Production-only loading — Check environment.production before initializing if you only want the widget in production

Next Steps

  • Customize the widget in your dashboard
  • Set up integrations with your issue tracker
  • Configure team members and permissions

Further Reading

After install

What you get after install

Every report arrives in your inbox or tracker with the evidence already attached:

  • The element

    What the reporter pointed at: label, component and selector. Errors tied to it are outlined in red.

  • Console and JS errors

    With file and line, captured up to the moment of the report.

  • Network requests

    Status, URL and request and response bodies, failed and successful.

  • Session replay

    The moments leading up to the bug, with repro steps.

  • Environment

    URL, browser, OS and viewport, plus the screenshot. On paid plans, also video.

Optional

Connect your agent

Add the SnagRelay MCP server once, then paste a prompt that tells your agent to call get_issue_context. After you review the fix, mark_issue_resolved emails the reporter. MCP is on every plan.

https://mcp.snagrelay.com/v1

Add this URL as a remote MCP server, then click Allow. Paste a prompt that tells the agent to call get_issue_context, then mark_issue_resolved only after you have reviewed the fix.

More articles

For teams shipping with AI agents

Let your users find the bugs. Let your agent fix them.

Free to start, no card. One script tag, then your agent reads every report over MCP.

Start free