[Feature] JavaScript-type targeting attribute (client-side evaluated)
Targeting attributes currently support only static types (string, number, boolean, enum, secure string). To target on a computed/derived value, I have to calculate it in my own code and pass it into the SDK attributes object manually.
A new attribute type (e.g. javascript) whose value is defined as a JS expression evaluated by the SDK in the browser context at assignment time. The resolved value would then be usable in targeting conditions like any other attribute.
This enable us to trigger an experiment only when a specific DOM event or condition occurs, rather than on page load. For example:
A user clicks a specific element (e.g. a "Add to cart" button). A specific element becomes visible in the viewport (e.g. a promo banner scrolls into view). A DOM condition is met (e.g. cart contains > 3 items, a modal is open, a specific class is present).
Today this requires computing the value in custom JS (on site or via tag manager) and pushing it via setAttributes() after the event fires, then forcing a re-evaluation (updateAttribute). A javascript attribute type would let me define the expression directly in GrowthBook — e.g. an attribute addToCartClicked evaluated from a listener, or bannerVisible from an IntersectionObserver — and use it in targeting conditions natively.
Source: growthbook/growthbook