While you are running a Split URL test on your website, there could be scenarios where you may want VWO to execute a specific portion of the code based on whether the user is redirected to a variation or not. For example, you may want to execute a code snippet only when there is no redirection or you may want to avoid GA Code execution on the control if it is redirecting to another variation.
In this article, we will talk about the following use cases:
- Executing a code snippet only when redirection is not happening
- Avoiding GA Code execution if the page is going to be redirected to variation
- Using VWO with Exit Pop-up Code
Executing Code Only When Redirection Is Not Happening
If you only need to execute code when the redirection does not occur, then you can attach an event to listen for redirection. This can be done by adding the following code snippet before VWO SmartCode (let’s call it Code-1).
NOTE: You can use the variable willRedirectionOccurByVWO in later
scripts to decide if you want to execute any code on the page or not.
Avoiding GA Code Execution if the Page Is Going to Be Redirected to Variation
If a split campaign is running and GA is installed, GA will log a visitor for the control page as well as the variation page (for both Synchronous and Asynchronous code). To avoid this, install code-1 above VWO Sync Code and then execute the GA tracking code conditionally.
NOTE: If the UA code on your website is installed via GTM, copy-paste
the GTM code in the code block instead of GA.
For asynchronous SmartCode, this implementation will not work because, by the time the script executes, it is not necessary that the VWO library is loaded. For asynchronous code implementation, add the following code:
Using VWO with Exit Pop-Up Code
You can also use VWO Sync Code with websites with exit pop-ups. Add the Code-1 snippet, and then the following code before VWO Sync SmartCode:
NOTE: This code will work for the Asynchronous code as well, but it is
recommended to use this with synchronous code.