Skip to content

Commit e4e6e91

Browse files
authored
Merge pull request #26 from newfold-labs/fix/PRESS10-239
Fix use the siteUrl for build the url with tracking parameters in JS
2 parents 0c4b1e3 + f2bf684 commit e4e6e91

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => 'bb67971ce0533fc3cea2');
1+
<?php return array('dependencies' => array(), 'version' => '9af3bb6fbedda8b0ad32');

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// Function to add query parameters to a URL while preserving the fragment (hash) part.
1919
function addQueryArgsPreserveFragment( url, params ) {
2020
const [ baseUrl, fragment ] = url.split( '#', 2 );
21-
const urlObj = new URL( baseUrl, window.location.origin );
21+
const urlObj = new URL( baseUrl, window.NewfoldRuntime?.siteUrl );
2222
Object.entries( params ).forEach( ( [ key, value ] ) => {
2323
urlObj.searchParams.set( key, value );
2424
} );
@@ -46,15 +46,17 @@
4646
window.location.hash;
4747

4848
// Check if the URL is relative or absolute
49+
// We use the siteUrl to avoid issues on sites that are located in subdirectories.
50+
// Example: https://example.com/website_44554
4951
if ( ! url.startsWith( 'http' ) && ! url.startsWith( '/' ) ) {
5052
const isInWpAdmin =
5153
window.location.pathname.includes( '/wp-admin/' );
5254
url = isInWpAdmin
53-
? window.location.origin + '/wp-admin/' + url
54-
: window.location.origin + '/' + url;
55+
? window.NewfoldRuntime?.siteUrl + '/wp-admin/' + url
56+
: window.NewfoldRuntime?.siteUrl + '/' + url;
5557
}
5658

57-
const urlObj = new URL( url, window.location.origin );
59+
const urlObj = new URL( url, window.NewfoldRuntime?.siteUrl );
5860

5961
const defaultParams = {
6062
channelid: urlObj.pathname.includes( 'wp-admin' )

0 commit comments

Comments
 (0)