Installation

How to install the Sophonz Browser SDK in your web frontend project via CDN or NPM.

The Sophonz Browser SDK is built on OpenTelemetry Native. This guide covers installation and configuration for collecting web performance metrics across frontend frameworks including VanillaJS, React, Vue, and Next.js.

Installing and initializing the Browser SDK

Quick Start

Enter your values below and pick a framework tab (CDN · VanillaJS · React · Vue · Next.js) to generate the initialization code. Copy it with the copy button. The SDK must be initialized before other features to capture all relevant data.

TIP — Package name and app key

Sign in to the Sophonz console, add an app to a project with Add App, and use the app key issued on the app's App Management page.

<!-- index.html <head> -->
<script src="https://cdn.sophonz.com/release/npm/@browser-sdk/latest/index.js"></script>
<script>
  window.Sophonz.init({
  collectorUrl: 'https://in.sophonz.ai',
  project: 'sophonz',
  appName: 'next-sample',
  appVersion: '1.0.0',
  appKey: 'sk_tYtJUa4WweXXedj6lxjSqoPW5O0DnbXz',
  });
</script>

Opens a detail screen in a sample app. The browser SDK captures an action, its duration, Fetch and XHR, console and application logs, and a handled exception.

Both modes deliberately record one handled exception. Navigation is recorded in the session. Web Vitals depend on what the browser observes. Replay and sockets are outside this sample.

  • collectorUrl Sophonz Collector URL details
  • appName App name (the package name used when registering the app) details
  • appVersion App version details
  • appKey App key details
  • project Project details
  • deploymentEnvironment Deployment environment details
  • For additional configuration options beyond these, refer to the configuration options section.

CAUTION — Package name configuration

appName must match the package name entered when registering the app. Package names may only contain a-z, A-Z, 0-9, -, _, and ..

Pinning a Specific Version (CDN)

To pin a specific version via CDN, add the following inside your <head></head> tags. Replace {{VERSION}} with the version you want, and verify integrity with the integrity value.

<script
  src="https://cdn.sophonz.com/release/npm/@browser-sdk/{{VERSION}}/index.js"
  integrity="{{VERSION_SRI_HASH_INTEGRITY}}"
  crossorigin="anonymous">
</script>
<script>
  window.Sophonz.init({
    collectorUrl: '{{SOPHONZ_TRACES_COLLECTOR_URL}}',
    appName: '{{YOUR_APP_NAME}}',
    appVersion: '{{YOUR_APP_VERSION}}',
    appKey: '{{YOUR_APP_KEY}}',
    project: '{{YOUR_PROJECT}}',
    deploymentEnvironment: '{{DEPLOYMENT_ENVIRONMENT}}',
  });
</script>

NPM

https://www.npmjs.com/package/@sophonz/browser-sdk

NPM Version NPM Last Update NPM Unpacked Size npm bundle size NPM Downloads NPM Type Definitions

To bundle and initialize the library inside your project, run npm install @sophonz/browser-sdk in your project directory.

import SophonzSDK from '@sophonz/browser-sdk';
 
SophonzSDK.init({
  collectorUrl: '{{SOPHONZ_TRACES_COLLECTOR_URL}}',
  appName: '{{YOUR_APP_NAME}}',
  appVersion: '{{YOUR_APP_VERSION}}',
  appKey: '{{YOUR_APP_KEY}}',
  project: '{{YOUR_PROJECT}}',
  deploymentEnvironment: '{{DEPLOYMENT_ENVIRONMENT}}',
});

TIP — This is just the beginning

Now ship your app. Sophonz surfaces the problems real users hit — so your app evolves on its own.