Skip to main content

Plugin API Reference

Glue provides framework plugins for Next.js and Vite that enable compile-time JSX instrumentation.

Installation

npm install --save-dev @getglue/next-plugin @getglue/jsx-runtime
These are devDependencies. Glue only runs in development when GLUE_INSTRUMENT=1 is set.

Basic Usage

next.config.js
const { withGlue } = require('@getglue/next-plugin');

module.exports = withGlue({
  reactStrictMode: true,
  // your config
});
TypeScript:
next.config.ts
import { withGlue } from '@getglue/next-plugin';

export default withGlue({
  reactStrictMode: true,
});

Configuration Options

enabled

Type: boolean Default: process.env.NODE_ENV === 'development' (Next.js) / process.env.GLUE_INSTRUMENT === '1' (Vite)
// Next.js
withGlue(config, { enabled: true })

// Vite
glue({ enabled: true })

attributePrefix

Type: string Default: 'data-agent' Customize the prefix for injected attributes (e.g., data-agent-id becomes data-glue-id).
// Next.js
withGlue(config, { attributePrefix: 'data-glue' })

// Vite
glue({ attributePrefix: 'data-glue' })

debugMode (Next.js only)

Type: boolean Default: false Enable debug logging for the Next.js plugin.

Compatibility

  • Next.js: 14.0.0+ (including 16+)
  • React: 17.0.0+
  • Node.js: 18.0.0+
Next.js 16+ requires webpack mode. Use glue run which forces this automatically.

Examples

Composing with Other Plugins

next.config.js
const { withGlue } = require('@getglue/next-plugin');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
});

module.exports = withBundleAnalyzer(withGlue({
  reactStrictMode: true,
}));
Glue should typically be the innermost wrapper.

Conditional Enabling

next.config.js
const { withGlue } = require('@getglue/next-plugin');
const config = { reactStrictMode: true };

module.exports = process.env.ENABLE_GLUE === 'true'
  ? withGlue(config)
  : config;