Split Test¶
The configuration remains unchanged. However, for this specific scenario, the code presented below can be applied within 'Experiment 1 - Variant'. The provided code will facilitate user redirection to a new page. Moreover, it will retain the URL parameters, subsequently reapplying them after the redirection process if they exist.
Important, do not forget to change the link!
JavaScript explained¶
This JavaScript code performs the following steps:
- The code is enclosed within an immediately invoked function expression (IIFE) to isolate its scope and ensure that it operates independently without interfering with other scripts.
use
strict is set at the beginning to enforce stricter adherence to JavaScript's syntax and prevent certain errors.- The code utilizes the
URLSearchParams
object to extract and handle the parameters from the current URL's query string (the part of a URL after the '?' sign that contains key-value pairs). - A new URL,
'https://sandervolbeda.com/'
, is created as the destination for redirection. - The script checks if there are any query parameters present in the current URL. If so, it appends them to the new URL to ensure the parameters are carried over to the redirected page.
- Finally, the code changes the
window.location.href
to the newly constructed URL, effectively triggering a redirect to the new URL while retaining any query parameters from the original URL.
In summary, this script captures the query parameters from the current URL, constructs a new URL with these parameters, and then redirects the user to the new URL. This can be useful for scenarios where specific data needs to be maintained across a redirection process.
Last update: June 25, 2024