Created
August 5, 2019 19:53
-
-
Save ryanshoover/f3eb4b5f2d59df4ace5a133f62a628bd to your computer and use it in GitHub Desktop.
Server-side A/B testing with NGINX & Varnish (WP Engine)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_header Set-Cookie "my_test_group=$test_group;Domain=.mydomain.com;Path=/;Max-Age=604800"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################# | |
# Define our A/B Test group # | |
############################# | |
set $test_group a; | |
if ( $time_iso8601 ~ '[13579]\+00:00$' ) { | |
set $test_group b; | |
} | |
if ( $cookie_wpe_test_group != '' ) { | |
set $test_group $cookie_my_test_group; | |
} | |
#################### | |
# Redirect Group B # | |
#################### | |
set $variant ''; | |
# Redirect Group B | |
if ( $test_group = b ) { | |
set $variant 'new'; | |
} | |
# Don't redirect if we're hitting a WP resource file. | |
if ( $request_uri ~* ^/(wp-admin|wp-content|wp-includes)/? ) { | |
set $variant ''; | |
} | |
# Don't redirect if we're already in the experiment page. | |
if ( $request_uri ~* ^/new/? ) { | |
set $variant ''; | |
} | |
# Redirect to language path if we have one | |
if ( $variant != '' ) { | |
rewrite .* "/$variant/$request_uri" permanent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This setup in WP Engine's NGINX rules will send 1/2 of all visitors from
mydomain.com/path/to/post/
tomydomain.com/new/path/to/post/
.