Skip links
View Categories

Hooks and filters for developers

2 min read

Actions #

HookFires when
opti_behavior_ab_variant_servedA variant is served
opti_behavior_ab_test_status_changedA test changes status
opti_behavior_ab_winner_declared / _applied / _revertedA winner is declared, applied or reverted
opti_behavior_smart_insights_register_signalsThe signal registry is built – register custom signals
opti_behavior_smart_insights_rules_upgradedSmart Insights rules changed version
opti_behavior_funnel_createdA funnel is created

Filters #

FilterLets you
opti_behavior_funnel_site_context / _funnel_recipes / _funnel_recipe_stepsAdjust site detection and suggested funnels
opti_behavior_smart_insights_category_labelsRename Smart Insights categories
opti_behavior_smart_insights_critical_min_lostChange the Critical floor
opti_behavior_smart_insights_purchase_funnelMark a funnel as a purchase funnel
opti_behavior_defer_tracker_scripts / opti_behavior_use_minified_jsControl defer and minified trackers
opti_behavior_consent_cookie_daysChange how long consent is remembered
opti_behavior_visitor_ipAdjust the visitor IP detection
opti_behavior_funnel_entry_rate_limit / opti_behavior_geo_lookups_per_minuteTune rate limits
opti_behavior_should_purge_cacheDecide whether a funnel change purges page caches
opti_behavior_ab_cookie_requires_consentOpt out of the A/B consent gate (not recommended)

Example #

add_filter( 'opti_behavior_consent_cookie_days', function () { return 365; } );

Hooks can change between major versions; check the changelog when you update.

Best practices #

  • Put your code in a small custom plugin or a child theme, never in Opti-Behavior files.
  • Check function_exists / class_exists before calling plugin classes.
  • Test on staging after each major update.

Example: exclude an internal tool from bot detection #

Add its user-agent fragment in Settings → Traffic & Behavior → Custom Bot Patterns – no code needed.

Example: trust your own proxy header #

add_filter( 'opti_behavior_visitor_ip', function ( $ip ) { return isset( $_SERVER['HTTP_X_CLIENT_IP'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_CLIENT_IP'] ) ) : $ip; } );

Only do this when the header is set by your own infrastructure; otherwise visitors could fake their IP.

Leave a comment

Explore
Drag