Use these PHP helpers in a theme or plugin when the change is too large for the experiment snippet boxes. They read the current request’s assignment after Alpha Insights has run (assignment is hooked on wp at priority 0).
wpdai_in_experiment( string $experiment_slug, string $variant_key ): bool
Returns true when the current visitor is assigned to that experiment slug and variant key. Returns false for holdout, unassigned visitors, and when the experiment is not applied on this request.
if ( wpdai_in_experiment( 'pricing-headline', 'treatment' ) ) {
echo 'New headline';
} else {
echo 'Original headline';
}
Full reference: Function: wpdai_in_experiment.
wpdai_get_experiment_variant( string $experiment_slug ): string|null
Returns the assigned variant key (for example control or treatment), or null if the visitor is unassigned or holdout.
$variant = wpdai_get_experiment_variant( 'pricing-headline' );
if ( 'treatment' === $variant ) {
add_filter( 'the_title', 'my_treatment_title' );
}
Full reference: Function: wpdai_get_experiment_variant.
Authorized users can force a variant with wpd_ai_preview_exp and wpd_ai_preview_var query args. Helpers follow the preview. Preview does not write experiment events. See Previewing and QA.
| Hook | Type | When |
|---|---|---|
wpd_ai_experiment_run_php_snippet |
Action | Pro runs the variant PHP snippet. Arguments: snippet, experiment, variant. |
wpd_ai_experiment_bypass_cache |
Action | A matching front-end request is marked uncacheable. Use this for custom cache layers. |
wpd_ai_experiments_variant_stats |
Filter | After variant rows are built for the warehouse. Pro adds significance and profit here. Arguments: rows, data warehouse. |
For a Pro custom-event goal, record the same event type with wpdai_track_custom_event or the JavaScript tracker. The report counts exposed sessions that include that event type.
Purchase value, revenue per exposure, and average order value (Pro) still convert on an attributed purchase. They change how the A/B Test list scores lift (revenue per visitor, revenue per exposure, or AOV), not the PHP helpers.