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

Alpha release Aug 01 #879

Merged
merged 5 commits into from
Aug 1, 2024
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
25 changes: 13 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions includes/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private function includes() {
include_once NEWSPACK_ADS_ABSPATH . '/includes/class-placements.php';
include_once NEWSPACK_ADS_ABSPATH . '/includes/class-sidebar-placements.php';
include_once NEWSPACK_ADS_ABSPATH . '/includes/integrations/class-scaip.php';
include_once NEWSPACK_ADS_ABSPATH . '/includes/integrations/class-complianz.php';
include_once NEWSPACK_ADS_ABSPATH . '/includes/integrations/class-ad-refresh-control.php';
include_once NEWSPACK_ADS_ABSPATH . '/includes/class-blocks.php';
include_once NEWSPACK_ADS_ABSPATH . '/includes/class-widget.php';
Expand Down
54 changes: 54 additions & 0 deletions includes/integrations/class-complianz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Newspack Ads Complianz Integration
*
* @package Newspack
*/

namespace Newspack_Ads\Integrations;

defined( 'ABSPATH' ) || exit;

/**
* Newspack Ads Complianz Integration Class.
*/
final class Complianz {

/**
* Initialize hooks
*/
public static function init() {
add_filter( 'newspack_ads_ad_targeting', [ __CLASS__, 'gam_ad_targeting' ] );
}

/**
* Whether to allow reader data to be used for ad targeting.
*/
private static function should_allow_reader_data() {
// Allow reader data if consent strategy is not detected.
if ( ! function_exists( 'cmplz_has_consent' ) ) {
return true;
}
return cmplz_has_consent( 'marketing' );
}

/**
* Filter GAM ad targeting according to Complianz settings.
*
* @param array $targeting Ad targeting.
*
* @return array Filtered ad targeting.
*/
public static function gam_ad_targeting( $targeting ) {
if ( ! self::should_allow_reader_data() ) {
// Unset reader data (reader_*) from targeting.
foreach ( $targeting as $key => $value ) {
if ( 0 === strpos( $key, 'reader_' ) ) {
unset( $targeting[ $key ] );
}
}
}
return $targeting;
}
}
Complianz::init();
Loading