'Wordpress | Split Traffic before user enters site and redirect to variant a or b

I have a wordpress site and want to manual split my website traffic when they enter the site (without using a plugin).

If someone wants to enter https://mywebsite.com/page I want that people get directly routed to either: 50% of traffic: https://mywebsite.com/page?test=a 50% of traffic: https://mywebsite.com/page?test=b

This redirect should happen before the main page https://mywebsite.com/page is called. My goal is to have one of the above pages as entry page.

Is there a way to achieve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source