Hi! Perhaps someone can help me :smile: I'm helpin...
# ask-questions
c
Hi! Perhaps someone can help me šŸ˜„ I'm helping a client with an AB-test but this one part I'm getting frustrated with.. We want to start the test when the cart is open (can be opened on every page). but I can't find a way of pushing Growthbook to run when the attribute if cart is open is true... since it's implemented only on every page - and not in cart. Any ideas?!?!?!?!
a
Hi! This should be in a GrowthBook hands-on learning lab! A few questions: 1. When the session starts, what is the state of the cart component? 2. You say the triggering event is "when cart is open" and that it can be opened on any page. But are you using setAttributes() with the "cartOpen" attribute change? 3. GrowthBook only re-evaluates based on the attributes it currently has when the feature is checked. Have you touched this part of the GrowthBook docs: https://docs.growthbook.io/features/targeting?utm_source=chatgpt.com
c
Yes I've read on that, and sorry I don't know what a learning lab is šŸ™‚ we are using setAttributes when a specific element is showing which is within the cart (sometimes)
a
Hi ok. Are you using the no code approach?
c
the visual editor? no
we have put the attribute in the source code
a
Just to clarify: a learning lab is a personal instance of GrowthBook that someone learning the platform can use to build feature flags, experiments, and such, where breaking things is not a failure of the exercise but part of it. It is a safe place to poke at the system, make bad assumptions, misconfigure a rollout, recover from it, and learn how the platform actually behaves without putting production work or shared environments at risk.
Are you utilizing GrowthBook's SDKs, and if so, which one?
c
no, no SDK's
just regular web experience, adding code in the variants through the tool
sorry not really sure what you mean by all these questions šŸ˜„ for me we're using Growthbook in a very "regular" way. adding the script and attributes to source code on site, then adding the variation code in the tool
a
No that's perfect šŸ˜†. Here's what I can offer in terms of a solution path: One probable diagnosis: Basically, the "brain" of GrowthBook on your site only scans the page once when it first loads. Because the cart is a "pop-up" or "drawer" that doesn't refresh the page, GrowthBook thinks nothing has changed. To fix this, you need to tell GrowthBook to "re-scan" the moment that cart button is clicked. Here is the non-technical breakdown of what needs to happen: Right now, the site code says: "Open the cart." You need the code to say: "Open the cart AND tell GrowthBook the cart is now open." By "poking" GrowthBook when the cart opens, it forces the tool to check its rules again. It will see the attribute
cart_is_open = true
and instantly trigger your experiment code. How to explain it to the client/developer You don't need to write the code yourself. Just tell their developer this: > "The experiment targets an attribute that changes after the page loads (when the cart opens). Can you trigger
growthbook.setAttributes
inside the cart-toggle function so the SDK re-evaluates the rules when the state changes?" Once the developer adds that "poke," you just need to make sure your experiment settings look like this: • Targeting: Set it to run on "All Pages" (since the cart can appear anywhere). • Condition: Add a rule where
isCartOpen
(or whatever the attribute is named) equals
true
. Why this works: Imagine GrowthBook is a security guard checking IDs at the front door (page load). If someone puts on a hat (opens the cart) inside the building, the guard won't notice. This fix tells the guard to look at the person again every time they touch their hat. Does the client have a developer available to add that one line of code to the cart component?
In JavaScript, that one liner generally looks like this:
growthbook.setAttributes({...growthbook.getAttributes(), cart_open: true});