screens = $screens ?: new Screens( $context ); $this->consent = new Tracking_Consent( $user_options ); $this->rest_controller = new REST_Tracking_Consent_Controller( $this->consent ); } /** * Registers functionality through WordPress hooks. * * @since 1.49.0 */ public function register() { $this->consent->register(); $this->rest_controller->register(); add_filter( 'googlesitekit_inline_tracking_data', $this->get_method_proxy( 'inline_js_tracking_data' ) ); } /** * Is tracking active for the current user? * * @since 1.49.0 * * @return bool True if tracking enabled, and False if not. */ public function is_active() { return (bool) $this->consent->get(); } /** * Adds / modifies tracking relevant data to pass to JS. * * @since 1.78.0 * * @param array $data Inline JS data. * @return array Filtered $data. */ private function inline_js_tracking_data( $data ) { global $hook_suffix; $data['isSiteKitScreen'] = $this->screens->get_screen( $hook_suffix ) instanceof Screen; $data['trackingEnabled'] = $this->is_active(); $data['trackingID'] = self::TRACKING_ID; return $data; } }