whats the better way to preform the redirect test ...
# ask-questions
j
whats the better way to preform the redirect test in GrowthBook... In Shopify we want to split traffic 50/50 in 2 themes. we can enable a theme in Shopify using a query parameter in url like
<http://mywebsite.com/?preview_theme_id=127602196534|mywebsite.com/?preview_theme_id=127602196534>
Maybe we can achieve this using feature flag? Like when we get
true
value of feature we redirect to theme B else we keep our theme A. Also we want to measure some matrices in both themes (we can do that using GA4 bigquery as datasource) Is this approach a better way...? please guide.
we tried this approach on a test site and got these warnings in the results
f
1, we have url redirect testing coming soon, but until then,... 2. what you are suggesting isn't wrong ,but its likely that the attribute you're using for the targeting is not sticky enough - ie, perhaps a session id?
j
we are using the own id as mentioned in the documentation
f
okay
j
Here is our code:
Copy code
<script
        id="growthbook-sdk"
        src="<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/index.min.js>"
      ></script>
      <script>
        (function () {
          
          function getUUID() {
            let $ = 'gbuuid',
              e = () =>
                window.crypto.randomUUID
                  ? window.crypto.randomUUID()
                  : '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, ($) =>
                      ($ ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> ($ / 4)))).toString(16)
                    ),
              t = ($) => {
                let e = `; ${document.cookie}`.split(`; ${$}=`);
                if (2 === e.length) return e.pop().split(';').shift();
              },
              r = ($, e) => {
                var t = new Date();
                t.setTime(t.getTime() + 3456e7), (document.cookie = $ + '=' + e + ';path=/;expires=' + t.toGMTString());
              };
            if (t($)) return t($);
            let i = e();
            return r($, i), i;
          }
          
          function getCustomerId() {
            let c = document.querySelector('#customerIdForGB')?.value;
            return c;
          }  
        
          // Wait for the SDK to load before starting GrowthBook
          if (window.growthbook) {
            startGrowthbook();
          } else {
            document.querySelector('#growthbook-sdk').addEventListener('load', startGrowthbook);
          }
          function startGrowthbook() {
            if (!window.growthbook) return;
            let gbUserId = getCustomerId() || getUUID();
            let gb = new growthbook.GrowthBook({
              apiHost: '<https://cdn.growthbook.io>',
              clientKey: 'sdk-CLIENTID',
              attributes: {
                id: gbUserId,
              },
              experiments: [
                {
                  key: 'barton_ga4',
                  variations: [true, false],
                },
              ],
              trackingCallback: function (experiment, result) {
                
                console.log('result', result);
                console.log('experiment', experiment);
                
                console.log(`%c Now we are on PREVIEW THEME `, 'color:white;background:orange;font-size:20px;');
                gtag('event', 'experiment_viewed', {
                  event_category: 'experiment',
                  experiment_id: experiment.key,
                  variation_id: result.variationId,
                  gb_user_id: gbUserId,
                });
              },
            });
            
            window.gb = gb;
            
            // TODO: Instrument DOM with AB test logic
            gb.loadFeatures().then(function () {
              // if you want to do anything after GB loads
            });
          }
        })();
      </script>
f
are you using that same ID for the experiment assignment id in the experiment reports?
what is this for?
Copy code
function getCustomerId() {
            let c = document.querySelector('#customerIdForGB')?.value;
            return c;
          }
you seem to be storing the id in a cookie
j
here is our experiment summary
Copy code
function getCustomerId() {
            let c = document.querySelector('#customerIdForGB')?.value;
            return c;
          }
this is for the logged in user, like if the user is logged in we can use the customer id from Shopify instead of creating our own id.
f
so if a user was logged out, then logs in, their ID will change
1
that's probably not what you want
1
you should keep the logged in id and the logged out as separate attributes
1
j
in one of our test we did earlier. we got these warnings... can you please guide on this:
*Sample Ratio Mismatch (SRM) detected. P-value below 0.001*.
Multiple Exposures Warning
f
so the multiple exposure warning is likely due to the id || otherid problem
for the SRM warning - did you change the split percentage?
looks like you're 98% and 2%, but the overall numbers are much more equal
j
these results were from experiment with 50/50 split
so we need to keep only one id... and do we have any chance of other issue in this implementation...
f
you might, Its not obvious
I would fix that other error and try again
are you returning the value from the cookie if its already set?
j
yes