One possible approach is to run the script in a useEffect call (with an empty dependency array) in the _app.tsx page. This creates some issues in development if React Strict Mode is on because useEffect fires twice, but it seems okay with React Strict Mode turned off.
Thanks, @jpsirois! I ended up going this route, although I omitted the link tags shown in lines 7, 8, and 9 of the example.
1 Like