Next.js applications need a deliberate place for third-party scripts because their pages can combine server rendering, hydration and client navigation. AddFreeChat should have one stable document-level owner. The goal is a support widget that loads for the intended website and remains usable between routes, without adding a script from every page component.
Next.js provides its Script component for external scripts. This guide shows the shape of an App Router installation in a shared layout and the tests needed around it. Projects using a different router or release should follow the matching current Next.js documentation rather than assuming every layout file and loading strategy is interchangeable.
1. Prepare the verified website and public identifier
Create an AddFreeChat account and save the one-time access key in a password manager. Add the public HTTPS origin, complete the supplied DNS ownership verification and select the website in the dashboard. A preview-deployment host is not automatically the same origin as your production custom domain.
Copy the embed from Installation and identify its public data-site-id. This is the value the browser needs. The private account key, authenticator seed and recovery tokens do not belong in a Next.js client bundle or a public environment variable. Public installation configuration and dashboard authentication serve different purposes.
Use Widget Designer for colours, welcome text, enabled channels and supported path visibility. Save the settings and begin with text. Do not make the framework integration responsible for duplicating those settings in several application components; the widget already obtains its selected website configuration from AddFreeChat.

2. Place Script in the appropriate shared layout
In an App Router application, consider the layout that covers the pages where support should be available. A root layout is suitable for site-wide support; a narrower layout may be appropriate for a deliberately limited area. Check the actual route tree before editing, especially when the project has several root layouts or separate applications.
Keep the existing html, body and children structure intact. Add only the external Script element at the intended integration point. The following is a reading example, not a replacement for the rest of your layout:
import Script from 'next/script'
// Inside the existing shared layout's returned body:
<Script
id="addfreechat-widget"
src="https://addfreechat.com/widget.js"
data-site-id="YOUR_PUBLIC_SITE_ID"
strategy="afterInteractive"
/>
Replace the placeholder with the public identifier from your own dashboard. Preserve the complete source URL. Do not put the account access key there. Keep one installation owner rather than adding this element in every page and also loading the script through a tag manager.
3. Choose a loading strategy for the actual task
The example uses afterInteractive to make support available after the page begins becoming interactive. Review the current Script documentation and the needs of your site before choosing another strategy. A widget does not normally need to block the initial document before the page can render.
A later strategy can reduce competition with initial work but also delay when a visitor can ask for help. Treat that as a product decision and measure it on a representative mobile device. A loading strategy alone does not guarantee a performance score or eliminate the integration’s network and processing cost.
Avoid moving the script into a repeatedly mounted client effect unless you have a specific, tested reason. Adding the element after every route transition creates unclear ownership. AddFreeChat defensively suppresses repeated execution for the same website identifier, but a clean integration should still load it through one supported framework path.
If your deployment uses a nonce-based content policy, integrate the widget with the project’s existing supported nonce flow. Do not hard-code a reusable nonce from a tutorial or weaken the policy globally. Have the developer responsible for the security headers review the actual script, frame and connection requirements.
4. Build and inspect the production result
Run the project’s normal build and publish through its established deployment process. A development server can behave differently from the production build, especially around remounting and caching. Test the deployed public domain rather than relying solely on local rendering or the presence of JSX in source control.
Open a public page as an ordinary visitor and confirm the widget loads for the expected website. Inspect the rendered script if necessary. If it is absent, verify that the active route actually uses the layout you edited. If it is present but blocked, read the browser’s resource-policy message before changing application code.
Keep preview and production origins distinct in your notes. A generated deployment address may fail the website-origin checks even when the layout is correct. Do not bypass ownership verification just to make a preview green; use a deliberately verified test environment or complete acceptance on the authorised public origin.
5. Test hydration and route transitions
Keep Live Inbox open for the selected website. Send a harmless unique message from the visitor widget and reply from the dashboard. Confirm the visitor receives the answer. This establishes the actual support connection before you investigate navigation behaviour.
Follow client-side links to several pages without manually refreshing. Minimize and reopen the widget. Use back and forward navigation and check that only one launcher is present. If you use supported show or hide path rules, test entry to an excluded path and return to an included one; the short route check reapplies those rules after pathname changes.
Do not treat a hidden widget as an authorisation control. Sensitive application routes still need their normal server and account permissions. The basic embed also does not automatically read your application’s authenticated user or private records. Any deeper connector needs separate design, permissions and tests.
6. Check mobile and consent states
Test a narrow mobile screen with the keyboard open and with any fixed navigation or purchase controls visible. The widget’s supported position and offsets should leave those controls usable. A layout that looks balanced on a desktop can still place a floating support button over a critical mobile action.
Exercise the consent manager’s relevant choices. If the loader is deliberately withheld, make that behaviour understandable and keep the integration in one governed path. Do not add an unconditional second snippet as a workaround. Describe the actual storage purposes and follow the consent treatment appropriate to the deployed service.
For calls, HTTPS, frame policy and device permissions remain separate requirements. A successful Script load and text exchange do not prove microphone audio, camera selection or another network’s connectivity. Test those with consenting participants and keep text available when a visitor cannot or does not want to start a call.
What to repeat after upgrades
After a Next.js upgrade, router change, root-layout refactor or security-header change, repeat the production-build and route tests. Record the layout location, strategy, public domain and acceptance date. Check loading, duplicate suppression, path visibility and the two-way message exchange rather than relying on one screenshot of a launcher.
Keep remote widget appearance changes in AddFreeChat. When an issue appears, identify whether it belongs to document ownership, resource policy, website verification, team availability or device capture. That separation gives your developer a concrete problem to fix without rebuilding the support integration from scratch.
A practical review exercise
Include one direct page load and one client-side transition to the same route in the release checklist. If the results differ, compare layout ownership and navigation behaviour before changing the widget account. Keep the test route and expected visible state documented so the next framework upgrade has a concrete regression check.
References and review notes
Platform instructions reviewed on 27 November 2026. Builder-specific steps follow the linked official documentation and still require testing on your own published site.