From a1e9cb10d3b78fb34bd4eb1cc6a5c6e8eda355f1 Mon Sep 17 00:00:00 2001 From: Miguel Peixe Date: Tue, 28 Nov 2023 10:53:04 -0300 Subject: [PATCH] fix: remove gam ad targeting --- includes/class-initializer.php | 2 +- .../class-newspack-ads-gam.php} | 32 ++++++------------- 2 files changed, 11 insertions(+), 23 deletions(-) rename includes/{class-gam.php => hub/class-newspack-ads-gam.php} (56%) diff --git a/includes/class-initializer.php b/includes/class-initializer.php index 0fea4640..b6d0b1ab 100644 --- a/includes/class-initializer.php +++ b/includes/class-initializer.php @@ -26,6 +26,7 @@ public static function init() { Hub\Event_Listeners::init(); Hub\Database\Subscriptions::init(); Hub\Database\Orders::init(); + Hub\Newspack_Ads_GAM::init(); } if ( Site_Role::is_node() ) { @@ -40,7 +41,6 @@ public static function init() { Data_Listeners::init(); Reader_Roles_Filter::init(); Distributor_Customizations::init(); - GAM::init(); register_activation_hook( NEWSPACK_NETWORK_PLUGIN_FILE, [ __CLASS__, 'activation_hook' ] ); } diff --git a/includes/class-gam.php b/includes/hub/class-newspack-ads-gam.php similarity index 56% rename from includes/class-gam.php rename to includes/hub/class-newspack-ads-gam.php index 353bcd12..95161964 100644 --- a/includes/class-gam.php +++ b/includes/hub/class-newspack-ads-gam.php @@ -3,27 +3,28 @@ * Newspack Ads GAM Integration. * * Implements support for custom targeting key-val pairs for each site in the - * network. The ad slots are then targeted to the site's URL. + * network. * * @package Newspack */ -namespace Newspack_Network; +namespace Newspack_Network\Hub; + +use Newspack_Network\Site_Role; +use Newspack_Network\Debugger; -use Newspack_Ads\Providers\GAM\Api as GAM_API; use Newspack_Ads\Providers\GAM_Model; /** - * Integration class for Newspack Ads' GAM support. + * Integration class for Newspack Ads GAM support. */ -final class GAM { +final class Newspack_Ads_GAM { /** * Initialize hooks. */ public static function init() { add_action( 'newspack_ads_setup_gam', [ __CLASS__, 'create_targeting_keys' ] ); - add_action( 'save_post_' . Hub\Nodes::POST_TYPE_SLUG, [ __CLASS__, 'create_targeting_keys' ] ); - add_filter( 'newspack_ads_ad_targeting', [ __CLASS__, 'add_targeting' ], 10, 2 ); + add_action( 'save_post_' . Nodes::POST_TYPE_SLUG, [ __CLASS__, 'create_targeting_keys' ] ); } /** @@ -41,28 +42,15 @@ public static function create_targeting_keys() { Debugger::log( 'Error adding GAM targeting keys: GAM API is not available.' ); return; } - $nodes = Hub\Nodes::get_all_nodes(); + $nodes = Nodes::get_all_nodes(); $node_urls = array_map( function( $node ) { return $node->get_url(); }, $nodes ); - $urls = array_merge( [ \get_site_url() ], $node_urls ); + $urls = array_merge( [ \get_bloginfo( 'url' ) ], $node_urls ); $api->targeting_keys->create_targeting_key( 'site', $urls, 'PREDEFINED', 'CUSTOM_DIMENSION' ); Debugger::log( 'Updated GAM targeting keys.' ); } - - /** - * Add targeting. - * - * @param array $targeting Targeting. - * @param array $ad_unit Ad unit. - * - * @return array - */ - public static function add_targeting( $targeting, $ad_unit ) { - $targeting['site'] = \get_site_url(); - return $targeting; - } }