Event Tracking
JavaScript event tracking and monitoring
Event Tracking Setup
Choose an Installation Method
Each browser telemetry project has an API key and collector endpoint. Use the WordPress plugin for WordPress sites, or add the JavaScript browser beacon to your application layout for Laravel, React, and other sites.
Simple Hosted JavaScript Snippet
This catch-all snippet works on most sites. Replace YOUR_API_KEY with the API key from your project page, and set environment to match where the site is running. Managed-service project pages also provide this simple snippet with the API key, endpoints, and package-safe telemetry settings already filled in.
<script src="https://metricpoints.com/js/metric-points-browser-beacon.min.js" data-metric-points-browser-beacon="1" crossorigin="anonymous"></script>
<script>
if (window.MetricPointsBrowserBeacon && window.MetricPointsBrowserBeaconConfig) {
window.MetricPointsBrowserBeacon.init(new window.MetricPointsBrowserBeaconConfig({
apiKey: 'YOUR_API_KEY',
endpoint: 'https://metricpoints.com/api/error-reports',
performanceEndpoint: 'https://metricpoints.com/api/performance-sessions',
environment: 'production',
autoStart: true
}));
}
</script>
Common Use Cases
Production Error Monitoring
Capture uncaught JavaScript events and promise rejections from public pages after deploys.
Release Verification
Tag reports with release or buildId so regressions can be tied back to a deploy.
Performance and Web Vitals
Collect Core Web Vitals and browser performance sessions alongside frontend events.
Client Site Handoffs
Create one project per client site, copy the generated snippet, and confirm reports after launch.
Platform Procedures
WordPress
WordPress can be connected with the MetricPoints plugin or by inserting the JavaScript snippet into the site header. Use the plugin when you want a WordPress admin screen; use script insert when you already manage snippets centrally or cannot install another plugin.
Option 1: Plugin
- Create an Event Tracking project in MetricPoints for the WordPress site's domain.
- Download the MetricPoints Browser Beacon plugin.
- Upload it in WordPress under Plugins → Add New → Upload Plugin.
- Activate the plugin, then open Settings → MetricPoints Browser Beacon.
- Paste the project API key, enable browser beacon tracking, and save the settings.
- Load the public site and use the plugin test action or a temporary test error to confirm reports arrive.
Option 2: Script Insert
- Create an Event Tracking project in MetricPoints for the WordPress site's domain.
- Copy the generated project snippet from the MetricPoints project page.
- Open your snippets, header/footer, or custom-code plugin in WordPress.
- Add the snippet to the site-wide header so it loads before
</head>. - Save, clear page cache/CDN cache, then load the public site in a normal browser session.
- Trigger a controlled test error and confirm the report appears in MetricPoints.
This works with common WordPress code-snippet or header-injection plugins, and with themes that provide a site-wide head/script field.
Laravel Site
- Create an Event Tracking project for the Laravel application's public domain.
- Add the hosted snippet to the main Blade layout, usually
resources/views/layouts/app.blade.php, before</head>. - Put the API key in an environment variable such as
VITE_METRICPOINTS_API_KEYor paste the project snippet directly if the layout is private. - Set
environmenttoproduction,staging, or the current Laravel environment. - Deploy, clear cached views/config if needed, then trigger a controlled browser-side test error.
<!-- resources/views/layouts/app.blade.php -->
<script src="https://metricpoints.com/js/metric-points-browser-beacon.min.js" defer></script>
<script>
window.addEventListener('load', function () {
window.MetricPointsBrowserBeacon.init(new MetricPointsBrowserBeaconConfig({
apiKey: 'YOUR_API_KEY',
environment: 'production',
autoStart: true
}));
});
</script>
React
- Create an Event Tracking project for the deployed React app domain.
- Add the tracker script to
public/index.htmlfor Create React App, orindex.htmlfor Vite. - Initialize the tracker once before rendering the app, typically in
src/main.jsxorsrc/index.jsx. - Use environment variables for the API key and release/build metadata.
- Deploy and verify by checking the browser network tab for posts to
/api/error-reports.
// src/main.jsx
window.MetricPointsBrowserBeacon?.init(new window.MetricPointsBrowserBeaconConfig({
apiKey: import.meta.env.VITE_METRICPOINTS_API_KEY || 'YOUR_API_KEY',
environment: import.meta.env.MODE || 'production',
release: import.meta.env.VITE_APP_VERSION || null,
autoStart: true
}));
Generic or Catch-All Website
- Create one MetricPoints project for each production domain you want to monitor.
- Use the hosted script from MetricPoints or download
metric-points-browser-beacon.min.jsand serve it with your other assets. - Paste the generated project snippet into the shared page header, template, tag manager, or CMS custom code area.
- Keep the collector endpoint set to
https://metricpoints.com/api/error-reportsunless support tells you otherwise. - Open a page, trigger a test browser event, and confirm the report appears in the MetricPoints project.
Use the simple generated snippet on the project page when possible. It contains the correct API key, collector endpoints, and package-safe telemetry defaults for that project. Use the advanced snippet only when an implementer needs every resolved telemetry control inline.
Configuration Options
Event Tracking
Monitor JavaScript events with detailed stack traces
Performance Tracking
Track Core Web Vitals and performance metrics
User Tracking
Monitor user sessions and behavior patterns
Custom Events
Track custom events and user interactions