Add Widgetjoy to Next.js
Add the Script component to your root layout, then deploy.
import Script from "next/script"
<Script src="https://widgetjoy.com/s/your-site.js" strategy="afterInteractive" crossOrigin="anonymous" />
Your Dashboard shows this line with your own site in it.
Three steps in Next.js
-
Open the root layout
app/layout.tsx, or pages/_document.tsx on the pages router.
-
Add the Script inside the body
After the page is interactive is soon enough.
-
Deploy and load a page
Your Dashboard's Install screen turns green once your site has loaded Widgetjoy.
How to check it works
- Load any page of your published site.
- Your Dashboard’s Install screen turns green once your site has loaded Widgetjoy.
Load it once, when the page is ready
The Script component does this for you. If your own code loads the line, do it in a client component the root layout mounts: the load starts after the page is ready, so a bar shows without anybody clicking, and whatever asks for it later is given the same load.
Use this or the Script component, not both: a second copy of the line does nothing. The address is a stand-in; your Dashboard shows yours.
"use client"
import { useEffect } from "react"
let loading: Promise<void> | undefined
/** Loads Widgetjoy once, however many parts of the page ask. */
export function loadWidgetjoy() {
loading ??= new Promise<void>((resolve, reject) => {
const script = document.createElement("script")
script.src = "https://widgetjoy.com/s/your-site.js"
script.async = true
script.onload = () => resolve()
script.onerror = () => reject(new Error("Widgetjoy did not load"))
document.body.append(script)
})
return loading
}
/** Mount this once, in app/layout.tsx. */
export function Widgetjoy() {
useEffect(() => {
loadWidgetjoy().catch(() => undefined)
}, [])
return null
}
A spot in a panel that is closed
Leave the spot in the panel and the panel closed. The widget is placed in it and its space held, but it is fetched and drawn only when the spot comes near the screen, so the panel opens on a finished form and nothing is loaded on the click.
Give the widget the spot #wj-contact under Where it shows.
<aside id="contact-panel" hidden={!open}>
<div id="wj-contact" />
</aside>
Then add a widget
- Announcement Bar
Say one thing at the top or bottom of every page, and let visitors dismiss it.
- Contact Form
Let visitors send you a message, with the fields you choose, straight to your Inbox.
- Countdown Timer
Show the time left until a moment you choose, and what happens when it runs out.
- Chat Button
Hand visitors to a chat on WhatsApp or Telegram, from a corner or your page.
- Popup
Interrupt deliberately, on a trigger you choose and a cadence visitors can bear.
- Newsletter Signup
Grow a mailing list, with consent evidence recorded against every signup.
- FAQ
Answer the questions that would otherwise become support tickets.
- Review Us
Ask every customer for a review, with one button to your review page.
- Pricing Table
Lay out plans side by side, with the emphasis where it earns its keep.
Questions
Something else? Write to us.
Why isn’t it on my site yet?
Deploy the change, then load a page of the deployed site.
Where in the page does it go?
Anywhere works. The line loads after your page, so it never holds it up.
My site sets a security policy.
Allow https://widgetjoy.com in script-src and connect-src. If your policy uses a nonce with 'strict-dynamic', which ignores addresses in script-src, give the line your page’s nonce as its nonce attribute instead, and keep https://widgetjoy.com in connect-src.
My site turns its scripts into modules, as Astro does.
Keep the line as it is, with async. In Astro, add is:inline to the tag, so Astro leaves it as written. Made a module (type="module"), the script cannot find its own tag, and no Widget shows.
Can the line be pinned to a version, with an integrity value?
Not yet. The line has no version so that every fix reaches your pages the day it ships, with nothing for you to change; a pinned copy would stay as it was, and an integrity value checks the loader alone, not the widgets it then loads. If your security policy asks for one, write to us.
My site uses a cookie consent tool.
Widgetjoy sets no cookies. A visitor's browser keeps up to four notes on your site's own address, and nothing about the visitor: widgetjoy:dismissed:…, so a bar, a countdown or a popup they closed stays closed for its time; widgetjoy:started:…, so a countdown that gives each visitor their own time does not start again on every page; widgetjoy:kept, the list of those notes, so the ones of a widget your site no longer shows can be forgotten; and widgetjoy:shown:…, which leaves with the tab, so a popup opens once a visit. If your tool lists browser storage, list all four as strictly necessary.
My site has a header fixed to the top.
Give it top: var(--widgetjoy-top-offset, 0px), and give html scroll-padding-top: var(--widgetjoy-top-offset, 0px). The offset is the height of every bar at the top, 0px when there is none, so the header stays whole under a bar and a link or field the keyboard moves to is never hidden behind it. A bar at the foot has --widgetjoy-bottom-offset.