settings = $settings; } /** * Initializes all hooks. * * @since 1.33.0 */ public function register(): void { add_action( 'web_stories_print_analytics', [ $this, 'print_mgid_tag' ] ); } /** * Get the list of service IDs required for this service to be registered. * * Needed because settings needs to be registered first. * * @since 1.33.0 * * @return string[] List of required services. */ public static function get_requirements(): array { return [ 'settings' ]; } /** * Prints the tag for single stories. * * @since 1.33.0 */ public function print_mgid_tag(): void { $widget = $this->get_widget_id(); $enabled = $this->is_enabled(); if ( ! $enabled || ! $widget ) { return; } $configuration = [ 'ad-attributes' => [ 'type' => 'mgid', 'data-widget' => $widget, ], ]; /** * Filters MGID configuration passed to ``. * * @since 1.33.0 * * @param array $settings MGID configuration. * @param string $widget MGID Widget ID. */ $configuration = apply_filters( 'web_stories_mgid_configuration', $configuration, $widget ); ?> settings->get_setting( $this->settings::SETTING_NAME_MGID_WIDGET_ID ); } /** * Returns if MGID is enabled. * * @since 1.33.0 */ private function is_enabled(): bool { return ( 'mgid' === $this->settings->get_setting( $this->settings::SETTING_NAME_AD_NETWORK, 'none' ) ); } }