api = new APHA_PostHog_API(); // Initialize attribution engine (hooks into init at priority 5). $this->attribution = new APHA_Attribution(); // Initialize identity management. $this->identity = new APHA_Identity( $this->api ); $this->identity->set_attribution( $this->attribution ); $this->attribution->set_identity( $this->identity ); // Initialize product data helper. $this->product_data = new APHA_Product_Data(); // Initialize server-side tracking if enabled. if ( APHA_Settings::is_server_tracking_enabled() ) { $this->server_events = new APHA_Server_Events( $this->api, $this->identity, $this->product_data ); $this->server_events->set_attribution( $this->attribution ); } // Initialize frontend tracking if enabled. if ( APHA_Settings::is_frontend_tracking_enabled() ) { $this->data_layer = new APHA_Data_Layer( $this->product_data ); $this->frontend_events = new APHA_Frontend_Events(); } } /** * Register the AG Data for PostHog settings tab in WooCommerce > Settings. * * @return void */ public function register_settings_tab() { add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_settings_page' ) ); } /** * Add the AG Data for PostHog settings page to the WooCommerce settings pages array. * * @param array $settings Array of WC_Settings_Page instances. * * @return array Modified settings array. */ public function add_settings_page( $settings ) { // Load the settings page class lazily — WC_Settings_Page is only // available when WooCommerce admin is active (this filter only // fires in admin context, so it's always safe here). require_once APHA_PLUGIN_DIR . 'includes/class-apha-settings-page.php'; $settings[] = new APHA_Settings_Page(); return $settings; } /** * Get the PostHog API client instance. * * @return APHA_PostHog_API|null */ public function get_api() { return $this->api; } /** * Get the identity manager instance. * * @return APHA_Identity|null */ public function get_identity() { return $this->identity; } /** * Get the attribution engine instance. * * @return APHA_Attribution|null */ public function get_attribution() { return $this->attribution; } }