Smart triggers
Show a modal after a delay, at a chosen scroll depth, or when a visitor is about to leave.
Magnet is a small, dependency-free JavaScript library for timely, on-brand lead capture modals.
One script. No framework, no account, no fuss.

Magnet handles the small details so you can focus on making a useful offer and a clear next step.
Show a modal after a delay, at a chosen scroll depth, or when a visitor is about to leave.
Pure JavaScript with no framework lock-in. Add one script tag and you’re ready to go.
Control the copy, colors, images, placement, layout, and backdrop so it looks at home.
Email validation and friendly, configurable errors are included from the first interaction.
Run independent campaigns on one page, each with its own audience, trigger, and goal.
Send FormData or JSON to any webhook or API, with custom fields for campaign context.
Reach readers who have spent a little time getting to know your content.
Offer the next step when visitors are actively exploring what you have to say.
Leave a thoughtful final invitation when a desktop visitor is ready to move on.
// A useful offer, right before they leave new Magnet({ trigger: { type: 'exit' }, submit: { url: 'https://hooks.example.com', format: 'json' }, design: { imageUrl: '/guide-cover.jpg', layout: 'left', ctaColor: '#d84c3e' }, content: { title: 'Take the guide with you', buttonText: 'Send me a copy' } });
Use npm or add the script directly. Either way, Magnet stays out of your way.
<!-- 1. Include the script --> <script src="https://cdn.jsdelivr.net/npm/@aldoalfaro/magnet@latest/dist/magnet.min.js"></script> <!-- 2. Choose a moment and endpoint --> <script> new Magnet({ trigger: { type: 'time', value: 3 }, submit: { url: 'https://your-webhook-url.com' } }); </script>
Start with a trigger and an endpoint, then shape the rest around your campaign.
| Parameter | Values | Default | What it controls |
|---|---|---|---|
| trigger.type | 'time' | 'scroll' | 'exit' | 'time' | When to show the modal |
| trigger.value | Number | 3 | Seconds for time, or a percentage for scroll |
| submit.url | String | '' | The webhook or API endpoint for submissions |
| submit.format | 'formdata' | 'json' | 'formdata' | The submission payload format |
| design.position | 'centered' | 'bottom-right' | … | 'centered' | Where the modal appears on the screen |
| design.backdrop | true | false | true | Whether a backdrop appears behind the modal |
| design.imageUrl | String (URL) | '' | An optional image in the modal |
| design.layout | 'top' | 'left' | 'right' | 'top' | Image placement relative to the content |
| design.ctaColor | Hex color | '#007bff' | The submit button color |
| content.title | String | '' | The main message |
| content.buttonText | String | 'Submit' | The label on the submit button |
| customFields | Object | {} | Extra fields sent with every submission |
Use Magnet to give the right people a simple, well-timed next step.
View on GitHub