1- " use client" ;
1+ ' use client' ;
22
3- import inEU from " @segment/in-eu" ;
4- import { usePathname , useSearchParams } from " next/navigation" ;
5- import { Router } from " next/router" ;
6- import Script from " next/script" ;
7- import posthog from " posthog-js" ;
8- import { Suspense , useEffect , useState } from " react" ;
3+ import inEU from ' @segment/in-eu' ;
4+ import { usePathname , useSearchParams } from ' next/navigation' ;
5+ import { Router } from ' next/router' ;
6+ import Script from ' next/script' ;
7+ import posthog from ' posthog-js' ;
8+ import { Suspense , useEffect , useState } from ' react' ;
99
10- const isProd = process . env . NEXT_PUBLIC_VERCEL_ENV === "production" ;
11- const baseDir = process . env . NEXT_PUBLIC_BASE_DIR || "" ;
12-
13- function Reo ( ) {
14- const reoClientId = process . env . NEXT_PUBLIC_REO_CLIENT_ID ;
15- const [ loadReo , setLoadReo ] = useState ( false ) ;
16- const [ afterLoad , setAfterLoad ] = useState ( false ) ;
17-
18- useEffect ( ( ) => {
19- if ( window ) {
20- setLoadReo ( ! inEU ( ) ) ;
21- }
22- } , [ loadReo ] ) ;
23-
24- useEffect ( ( ) => {
25- // @ts -ignore
26- if ( afterLoad && window . Reo ) {
27- // @ts -ignore
28- window . Reo . init ( { clientID : reoClientId } ) ;
29- }
30- } , [ afterLoad ] ) ;
31-
32- return (
33- < div >
34- { reoClientId && isProd && loadReo && (
35- < Script
36- src = { `https://static.reo.dev/${ reoClientId } /reo.js` }
37- onLoad = { ( ) => setAfterLoad ( true ) }
38- defer
39- > </ Script >
40- ) }
41- </ div >
42- ) ;
43- }
10+ const isProd = process . env . NEXT_PUBLIC_VERCEL_ENV === 'production' ;
11+ const baseDir = process . env . NEXT_PUBLIC_BASE_DIR || '' ;
4412
4513function HubSpot ( ) {
4614 const hsId = process . env . NEXT_PUBLIC_HUBSPOT_ID ;
@@ -63,8 +31,8 @@ function HubSpot() {
6331 if ( searchParams && searchParams . toString ( ) ) {
6432 path = path + `?${ searchParams . toString ( ) } ` ;
6533 }
66- hs . push ( [ " setPath" , path ] ) ;
67- hs . push ( [ " trackPageView" ] ) ;
34+ hs . push ( [ ' setPath' , path ] ) ;
35+ hs . push ( [ ' trackPageView' ] ) ;
6836 }
6937 } , [ afterLoad , pathname , searchParams ] ) ;
7038
@@ -83,39 +51,10 @@ function HubSpot() {
8351 ) ;
8452}
8553
86- function Posthog ( ) {
87- useEffect ( ( ) => {
88- if ( inEU ( ) || ! process . env . NEXT_PUBLIC_POSTHOG_KEY ) {
89- return ;
90- }
91-
92- posthog . init ( process . env . NEXT_PUBLIC_POSTHOG_KEY ?? "" , {
93- api_host : isProd ? "/i" : process . env . NEXT_PUBLIC_POSTHOG_HOST , // See Posthog rewrites in next config
94- ui_host : process . env . NEXT_PUBLIC_POSTHOG_HOST ,
95- person_profiles : "always" ,
96- loaded : ( posthog ) => {
97- if ( process . env . NODE_ENV === "development" ) posthog . debug ( ) ;
98- } ,
99- } ) ;
100-
101- const handleRouteChange = ( ) => posthog ?. capture ( "$pageview" ) ;
102-
103- Router . events . on ( "routeChangeComplete" , handleRouteChange ) ;
104-
105- return ( ) => {
106- Router . events . off ( "routeChangeComplete" , handleRouteChange ) ;
107- } ;
108- } , [ ] ) ;
109-
110- return < > </ > ;
111- }
112-
11354export default function Scripts ( ) {
11455 return (
11556 < Suspense fallback = { < > </ > } >
116- < Reo />
11757 < HubSpot />
118- < Posthog />
11958 </ Suspense >
12059 ) ;
12160}
0 commit comments