Trying to run an experiment but only when a query ...
# experimentation
l
Trying to run an experiment but only when a query parameter is one of two options on the URL, in my case two affiliate ids. I've tried targeting with regex against both the URL and the query but can't find the right way to make this happen. Example URLs (only needs to target two aff ids) •
<https://mydomain.com/?source=affiliates&aff_id=12345&tracking_id=xyz123&ref=12345>
<https://mydomain.com/?source=affiliates&aff_id=abcdefg&tracking_id=abc789&ref=abcdefg>
Regex patterns I've tried that aren't working, both on
url
and `query`: 1.
aff_id=(12345|abcdefg)
2.
[?&]aff_id=(12345|abcdefg)(&|$)
3.
\?.*aff_id=(12345|abcdefg)
Feels like it's far too difficult to target experiments on specific URLs, is this something on the roadmap or maybe I'm missing with experiments?
s
Are you using a URL attribute for targeting or doing URL redirect test?
l
For targeting. I want the test only to be valid for people coming via some affiliate URLs, specifically.
s
I just tested the first pattern and it seemed to work. When you go Simulate on the feature flag, do you get a match? Or where are you finding it not working?
l
Okay I figured it out, I wasn't sending the query along via the SDK. I've updated this now and it seems to be working properly!
Copy code
gb.setAttributes({
      id: getUUID(),
      enableDevMode: !isProduction(),
      url: window.location.href,
      query: window.location.search,
      host: window.location.hostname,
      path: window.location.pathname,
    });
🙌 1