Skip to main content
All CollectionsTroubleshooting
Advanced Consent Mode with Redirect split tests
Advanced Consent Mode with Redirect split tests
O
Written by Optimize Team
Updated over a week ago

Note: Tag version 5.8+ is required for this solution.

How do you redirect users who have not yet given consent, and so we can't measure their participation in the test? This article addresses pre-optin split testing.

How redirects typically work

The usual process for redirect tests are:

  1. Check to make sure we're not on the new page already

  2. Mask the page

  3. Wait for the pageview event, to have "counted the user"

  4. Redirect the user after the event comes through.

This is fine for simple consent management, but Advanced Consent works a little differently.

We do not wait for consent before running experiments with Advanced Consent, but the masking will stop us from being able to achieve consent. So the user is stuck in limbo - what do we do?

Creating the cookies yourself

Note: This approach only works if your variant pages are typically inaccessible to regular users. E.g. there is no chance of users stumbling across a journey with /v2/ in the URL. If they can naturally reach the page, this approach will create an imbalance in traffic.

The key challenge is stickyness of users. The Control or Project cookie is created when the pageview event happens, and this is typically too late if users have Advanced Consent.

Redirecting before having the cookie means we re-evaluate users, and potentially bucket them incorrectly.

A simple solution could therefore be to create the cookie yourself, in the test. You will only need to do this for variants that redirect the user - control groups will not need any extra work as we are not masking.

This, along with a Project Location that spans both the control and variant pages would allow the test to trigger again on the variant page, and count the users post-redirect instead of pre-redirect.

Steps to resolution

1. Extra preinit script

Add this code to your preinit script:

// Only include this function once.
WT.handleSplitTest = function(name, value){
// Only do this if the user hasn't already been properly entered into the test.
if(document.cookie.indexOf(name) === -1 && document.cookie.indexOf(name.replace("_wt.control", "_wt.project")) === -1){
WT.extraControlCookies = WT.extraControlCookies || {};
WT.extraControlCookies[name] = value;
}
};

2. Building the test

  1. Include the variant page/s in your project location

  2. Change your variant's JS code to redirect after a delay instead of on pageview:

  3. Once your test is built, visit your variation page and ensure you are bucketed in the correct variation using the FXP tool.

  4. Run the following function in your dev console:
    WT.getProjectCookies();

  5. Copy the name and value of you test from the object it outputs

  6. Create and add a rule for your test in the tags preinit, so that when you land on the variations page url you set the name:value of the variation cookie

    //example rule 
    if(/my-variation-url/i.test(location.pathname)){
    WT.handleSplitTest("_wt.control-2536287-ta_WTOmultiredirect", "WT3c24m_IDyHClqr7itXlnf-bsalZoeKIm7t_y7IKsb5-ANs_eVLLYLNbfin8IvGPepxzPDrXcDEdegNjr0q67Hzr6SIyh64FbS2U1z0EaStXL6Etcb3IYoMcfGvqM6cddFbSzQCd6e5rEoFjSa-WlBHk0dmItw09mUmeXMSZGxTMefdy9isfb2V8AFHCdjnpGg8CXMfjAI9mvoC1Rg7ui33BrgyFqXNpocwKW1NRHg4xR9cW3SaLaU7FK8CI3x5CD55FmCcsFSzVrS5d38ah5eBA~~");
    }


  7. Add this back into pre-init after the above function you created:

If completed successfully, we will create the correct control/project cookie for your test when users reach the variant page automatically, and count users at the right moment.

Did this answer your question?