Main Header

JavaScript capture

Updated on July 30, 2026

Use SignalPress.capture() or the alias sp_capture() in JavaScript when something happens in the browser and you want to send a signal through the same server-side routing as PHP sp_capture() — for example, send a signal to Slack or send a signal to PostHog from a button click.

PHP capture is covered in Capturing Events with sp_capture(). Compose sample calls in wp-admin with sp_capture Builder. For vendor browser SDKs and automatic page analytics, see Client-side analytics.

Client API

When SignalPress event delivery is enabled, the frontend loads a small client that POSTs to WordPress:

JavaScript

SignalPress.capture(
	'checkout_started',
	{
		order_id: 123,
		total: 49.95,
	},
	{
		source: 'checkout-ui',
		services: [ 'posthog', 'slack' ],
	}
);

sp_capture() is an alias for the same function.

The third argument accepts the same options as PHP, including services, source, identity fields, and environment overrides. See Event Context and Options and Service Targeting.

Behavior

JavaScript capture:

  • POSTs to /wp-json/signalpress/v1/capture with a REST nonce from the page
  • Runs sp_capture() on the server with your event name, data, and options
  • Returns a Promise that resolves to { event, results, notices }
  • Creates normal delivery-ledger rows and respects routing, targeting, and hub operation mode
  • Can trigger Capture toasts through the REST response and X-SignalPress-Capture-Notices header

Validation mirrors PHP: normalized event names, JSON-serializable payloads, and a 1 MB encoded limit.

Requirements

  1. SignalPress → Settings — event delivery enabled
  2. The page must load signalpress-client.js (automatic on public pages when delivery is enabled)
  3. The browser must send the X-WP-Nonce header (handled automatically by the client)
  4. Capture requests are rate limited per IP

Use PHP or authenticated theme AJAX when you need to capture from contexts that cannot load the SignalPress client.

Example: button click to Slack

JavaScript

document.querySelector('#notify-team').addEventListener('click', function () {
	SignalPress.capture(
		'hero_cta_clicked',
		{ button: 'notify-team' },
		{ source: 'marketing-theme', services: [ 'slack' ] }
	);
});