@@ -126,13 +126,13 @@ function escapeRegExp(string: string): string {
126126
127127function getScriptSrc ( props : AnalyticsProps & { basePath ?: string } ) : string {
128128 if ( props . scriptSrc ) {
129- return props . scriptSrc ;
129+ return makeAbsolute ( props . scriptSrc ) ;
130130 }
131131 if ( isDevelopment ( ) ) {
132132 return 'https://va.vercel-scripts.com/v1/script.debug.js' ;
133133 }
134134 if ( props . basePath ) {
135- return `${ props . basePath } /insights/script.js` ;
135+ return makeAbsolute ( `${ props . basePath } /insights/script.js` ) ;
136136 }
137137 return '/_vercel/insights/script.js' ;
138138}
@@ -166,13 +166,13 @@ export function loadProps(
166166 dataset . disableAutoTrack = '1' ;
167167 }
168168 if ( props . viewEndpoint ) {
169- dataset . viewEndpoint = props . viewEndpoint ;
169+ dataset . viewEndpoint = makeAbsolute ( props . viewEndpoint ) ;
170170 }
171171 if ( props . eventEndpoint ) {
172- dataset . eventEndpoint = props . eventEndpoint ;
172+ dataset . eventEndpoint = makeAbsolute ( props . eventEndpoint ) ;
173173 }
174174 if ( props . sessionEndpoint ) {
175- dataset . sessionEndpoint = props . sessionEndpoint ;
175+ dataset . sessionEndpoint = makeAbsolute ( props . sessionEndpoint ) ;
176176 }
177177 if ( isDevelopment ( ) && props . debug === false ) {
178178 dataset . debug = 'false' ;
@@ -184,7 +184,7 @@ export function loadProps(
184184 if ( props . endpoint ) {
185185 dataset . endpoint = props . endpoint ;
186186 } else if ( props . basePath ) {
187- dataset . endpoint = `${ props . basePath } /insights` ;
187+ dataset . endpoint = makeAbsolute ( `${ props . basePath } /insights` ) ;
188188 }
189189
190190 return {
@@ -193,3 +193,11 @@ export function loadProps(
193193 dataset,
194194 } ;
195195}
196+
197+ function makeAbsolute ( url : string ) : string {
198+ return url . startsWith ( 'http://' ) ||
199+ url . startsWith ( 'https://' ) ||
200+ url . startsWith ( '/' )
201+ ? url
202+ : `/${ url } ` ;
203+ }
0 commit comments