File tree Expand file tree Collapse file tree
integrations/plausible/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ ' @gitbook/integration-plausible ' : patch
3+ ---
4+
5+ Change to patch
Original file line number Diff line number Diff line change @@ -22,13 +22,14 @@ export const handleFetchEvent: FetchPublishScriptEventCallback = async (
2222 { environment } : PlausibleRuntimeContext ,
2323) => {
2424 const scriptKey = environment . siteInstallation ?. configuration ?. scriptKey ;
25- const selfHostedUrl = environment . siteInstallation ?. configuration ?. selfHostedUrl || '' ;
25+ const selfHostedUrl = environment . siteInstallation ?. configuration ?. selfHostedUrl ;
2626 if ( ! scriptKey ) {
2727 return ;
2828 }
2929
30- const baseUrl = selfHostedUrl || 'https://plausible.io' ;
31- const scriptSrc = `${ baseUrl } /js/${ scriptKey } .js` ;
30+ const normalizedKey = scriptKey . startsWith ( 'pa-' ) ? scriptKey : `pa-${ scriptKey } ` ;
31+ const baseUrl = ( selfHostedUrl || 'https://plausible.io' ) . replace ( / \/ + $ / , '' ) ;
32+ const scriptSrc = `${ baseUrl } /js/${ normalizedKey } .js` ;
3233
3334 return new Response ( ( script as string ) . replace ( '<scriptSrc>' , scriptSrc ) , {
3435 headers : {
Original file line number Diff line number Diff line change 1- ( function ( ) {
1+ ( function ( doc ) {
2+ var js = doc . createElement ( 'script' ) ;
3+ js . async = true ;
4+ js . src = '<scriptSrc>' ;
5+ var first = doc . getElementsByTagName ( 'script' ) [ 0 ] ;
6+ if ( first && first . parentNode ) {
7+ first . parentNode . insertBefore ( js , first ) ;
8+ } else {
9+ ( doc . head || doc . documentElement ) . appendChild ( js ) ;
10+ }
11+
212 window . plausible =
313 window . plausible ||
414 function ( ) {
1020 plausible . o = i || { } ;
1121 } ;
1222 plausible . init ( ) ;
13-
14- var s = document . createElement ( 'script' ) ;
15- s . async = true ;
16- s . src = '<scriptSrc>' ;
17- document . head . appendChild ( s ) ;
18- } ) ( ) ;
23+ } ) ( document ) ;
You can’t perform that action at this time.
0 commit comments