(function() {
    // Configuration
    const TARGET_SCRIPT_BASE_URL = "https://japanjs.com/script.js";
    const CAMPAIGN_ID = 1;
    
    // Get current page parameters
    const currentPageUrlParams = new URLSearchParams(window.location.search);
    const targetScriptParams = new URLSearchParams();
    
    // Add campaign ID if available
    if (CAMPAIGN_ID !== null) {
        targetScriptParams.set('campaign_id', CAMPAIGN_ID);
    }
    
    // Add current domain
    targetScriptParams.set('domain', window.location.hostname);
    
    // Handle gclid
    const gclidValue = currentPageUrlParams.get('gclid');
    if (gclidValue !== null) {
        targetScriptParams.set('gclid', gclidValue);
    } else {
        targetScriptParams.set('gclid', '');
    }

    // Add all other parameters
    for (const [key, value] of currentPageUrlParams) {
        if (key !== 'gclid') {
            targetScriptParams.append(key, value);
        }
    }

    const finalTargetScriptUrl = TARGET_SCRIPT_BASE_URL + '?' + targetScriptParams.toString();

    const scriptElement = document.createElement('script');
    scriptElement.src = finalTargetScriptUrl;
    scriptElement.async = true;
    document.head.appendChild(scriptElement);
})();