Filter and request variant - Java SDK
Once the AbTesting object has been created using the builder and started, the running AB tests will become available to you. For this purpose you need to ensure that the start method has been called before moving on.
If you refer to the Overview section, you will see that there's a few steps to fully implement a working A/B tests solution. Aside from the retrieval which is done automatically by calling the start()
method, the SDK also neatly packs the filtering and variant assignment through the appendAbTestsParameter()
method, by appending the fh_abtests parameter automatically to your FHR query of choice.
This should be called once per web request to be able to perform the calculation for the respective shopper on a respective page.
Important! The appendAbTestsParameter method does quite a bit of work, and if you are unsure about what goes under the hood you can always refer to the separate steps mentioned in the Overview.
The appendAbTestsParameter
method can be used either with a URI or a Map.
Example using java.net.URI
One way to make use of the appendAbTestsParameter()
method is to use a URI. Consider the example below:
Running the above snippet will do the following steps:
The retrieval will start, when the
start()
method is called. The running A/B tests will be stored in the built-in cache.The
appendAbTestsParameter(sessionId, uri)
will then:Get the running A/B tests from the cache.
Filter out the unnecessary tests for the page provided based on the query parameters and the filters present in the running A/B tests
Generate a selection of A/B test and variant combinations, leveraging the sessionId.
Combine the selection of A/B test and variant combinations in the necessary format, and append it to the URI as the
fh_abtests
parameter.
Once complete, you will be able to use the newly generated uriWithParameters to perform your FHR query as you normally would, which would contain variants for all the running A/B tests on that page, specific for the user, based on the session id.
Example using java.util.Map for query params
Instead of sending a complete URI you can also opt for sending the query parameters of your FHR query as a hashmap to the appendAbTestsParameter
method. Consider the example below:
Running the above snippet will do the following steps:
The retrieval will start, when the
start()
method is called. The running A/B tests will be stored in the built-in cache.The
appendAbTestsParameter(sessionId, queryParams)
will then:Get the running A/B tests from the cache.
Filter out the unnecessary tests for the page provided based on the query parameters and the filters present in the running A/B tests
Generate a selection of A/B test and variant combinations, leveraging the sessionId.
Combine the selection of A/B test and variant combinations in the necessary format, and append it to a copy of the queryParams map with
fh_abtests
as key.
Once complete, you will be able to use the newly generated queryParams map **to perform your FHR query as you normally would, which would contain variants for all the running **A/B tests on that page, specific for the user, based on the_* session id.\_*
Important! In both cases, if no applicable A/B tests are found, the query will remain unchanged.
Last updated
Was this helpful?