Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(newspack-ads): remove gam ad targeting #16

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) {
Expand All @@ -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' ] );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );
}

/**
Expand All @@ -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;
}
}