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

straight-dog-45711

03/26/2024, 2:45 PM
Hey There! We're testing some new designs via Webflow and are trying to avoid a client side redirect. Since this is going to be a test on Paid Traffic, I thought it may be possible to split the traffic within Google Ads and then send them to either
/landing-page-a
or
/landing-page-b
. Wondering what the best way would be to handle the assignment to the a / b group using growthbook in this case. I'm guessing maybe we could append a query param from google ads, but curious if anyone might have a solution for this type of thing off the top of their head
f

fresh-football-47124

03/26/2024, 5:26 PM
you might want to add a bit of code to manually fire the exposure event for visitors to those landing pages when you detect the url parameter
I dont think GrowthBook has some internal way to make this easier
s

straight-dog-45711

03/26/2024, 6:14 PM
thanks @fresh-football-47124! if we simply wanted to force folks into control if landing on A or variant if they land on B, is that still the best way? was also looking at forcing rules for features, but not sure if that's compatible with the HTTP SDK Essentially, we're noticing that there is a very large SSM when using visual editor to redirect from a->b. So wondering if it's worth trying the new redirect experiment type or if the mismatch would continue to happen regardless unless we employed a neutral page or went the route I was alluding to earlier. any guidance would be appreciated!
current code in case helpful:
Copy code
// Function to retrieve a cookie's value by name
  function getCookie(name) {
    const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
    return match ? decodeURIComponent(match[2]) : null;
  }

  // Function to configure GrowthBook with attributes including the anonymousId
  function configGrowthbook(anonymousId) {
    window.growthbook_config = window.growthbook_config || {};
    window.growthbook_config.attributes = { anonymousId };
    console.log("Configured GrowthBook with Anonymous ID:", anonymousId);
  }

  // Try to initialize GrowthBook with the anonymous ID from the cookie
  const anonymousIdFromCookie = getCookie("ajs_anonymous_id");
  if (anonymousIdFromCookie) {
    configGrowthbook(anonymousIdFromCookie);
  } else {
    // Wait for analytics to be ready if the cookie is not found
    console.log("Anonymous ID cookie not found, waiting for analytics...");
    analytics.ready(function() {
      const analyticsAnonymousId = analytics.user().anonymousId();
      if (analyticsAnonymousId) {
        configGrowthbook(analyticsAnonymousId);
      } else {
        console.error("Failed to retrieve Anonymous ID after analytics ready.");
      }
    });
  }

<script async="" data-api-host="<https://cdn.growthbook.io>" data-client-key="sdk-xEb0AZIn228345Oj" src="<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/auto.min.js>">
</script>
Alright, actually it turned out to be something entirely different. Maybe this will help out others - might also be nice for growthbook to handle this under the hood or add to the docs. We use Segment for tracking. In order for it to really work with Segment, GB needs the anonymous ID from Segment. To get it, you have a few options. You can look for the
ajs_anonymous_id
cookie / local storage value and grab it or use the
analytics.user().anonymousId()
method to get it. The using the latter method, however, won't work until Segment is initialized. Typically, you can use the
analytics.ready(function() { Logic Here })
call back to make sure you're going to be able to get an anonymous id, but if the user is using an ad blocker and Segment is loading client side destinations - chances are those libraries will fail to load and thus the ready callback will never happen (this also happens with Rudderstack btw). So, our solution was to check for the cookie and then generate our own UUID and pass it to Segment as our own Anonymous ID like so
analytics.user().anonymousId(anonymousId);
Anyway, this was not intuitive and so maybe worth investigating further / mentioning in the docs or handling in the SDK so folks don't have to roll their own code to make GB work when using Segment, Rudderstack, etc
4 Views