Naar hoofdinhoud gaan

AppSignal instellen

Om AppSignal te configureren voor front-end JavaScript raden we aan om een appsignal.js-bestand met de AppSignal-configuratie te maken in de hoofdmap van uw project of in de src-map. Importeer vervolgens het configuratiebestand vanuit de code van uw app voordat er andere pakketten worden geladen of geïmporteerd. In het onderstaande voorbeeld staat er een appsignal.js-bestand in de hoofdmap van de applicatie. Op regel 8 hebben we de configuratieoptie namespace toegevoegd.
// For ES Module via npm/yarn, or with import maps
import Appsignal from "@appsignal/javascript";
// For CommonJS module via npm/yarn
const Appsignal = require("@appsignal/javascript").default;
// With the JSPM.dev CDN
import Appsignal from "https://jspm.dev/@appsignal/javascript";

const appsignal = new Appsignal({
  key: "<YOUR FRONTEND API KEY>",
});

module.exports = { appsignal };

De configuratie aanpassen

U kunt de foutrapportage vanuit uw applicatie aanpassen met de configuratieopties voor front-end. Hier is een voorbeeld van hoe de namespace-optie wordt aangepast.
 const appsignal = new Appsignal({
   key: "<YOUR FRONTEND API KEY>",
+  namespace: "frontend", // Configure the AppSignal namespace for front-end errors in this app
 });

De AppSignal-configuratie laden

Wanneer u klaar bent met de configuratie van uw applicatie, laadt u het appsignal.js-bestand bovenaan het hoofdbestand van uw applicatie, zoals in het voorbeeld hieronder:
// Place this at the top
// Import the file created in the previous step
const { appsignal } = require("./appsignal"); // Update to the location used in the previous step

// Place your app code below this
Nadat uw applicatie de AppSignal JavaScript-library heeft geladen, volgt u alle stappen in de installatiehandleiding, voegt u integraties en plug-ins toe en past u uw configuratie aan.