https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
j

jolly-spring-26283

01/26/2024, 7:49 PM
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

fresh-football-47124

01/27/2024, 3:26 PM
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

jolly-spring-26283

01/29/2024, 4:07 PM
we are using the own id as mentioned in the documentation
f

fresh-football-47124

01/29/2024, 4:08 PM
okay
j

jolly-spring-26283

01/29/2024, 4:08 PM
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

fresh-football-47124

01/29/2024, 4:08 PM
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

jolly-spring-26283

01/29/2024, 4:10 PM
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

fresh-football-47124

01/29/2024, 4:12 PM
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

jolly-spring-26283

01/29/2024, 4:15 PM
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

fresh-football-47124

01/29/2024, 4:15 PM
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

jolly-spring-26283

01/29/2024, 4:17 PM
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

fresh-football-47124

01/29/2024, 4:20 PM
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

jolly-spring-26283

01/29/2024, 4:22 PM
yes
5 Views