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

Release Oct 09 #1229

Merged
merged 14 commits into from
Oct 9, 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
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# [2.24.0-alpha.3](https://github.com/Automattic/newspack-popups/compare/v2.24.0-alpha.2...v2.24.0-alpha.3) (2023-09-29)


### Bug Fixes

* **data-api:** handle errored default donation settings ([#1224](https://github.com/Automattic/newspack-popups/issues/1224)) ([76b70b6](https://github.com/Automattic/newspack-popups/commit/76b70b636b3f45f7fa7826073afc5eabaadaa461))

# [2.24.0-alpha.2](https://github.com/Automattic/newspack-popups/compare/v2.24.0-alpha.1...v2.24.0-alpha.2) (2023-09-29)


### Features

* newsletter subscription list criteria ([#1218](https://github.com/Automattic/newspack-popups/issues/1218)) ([22961a3](https://github.com/Automattic/newspack-popups/commit/22961a39db38d5d64a2839091497aee8fa6f40e5))

# [2.24.0-alpha.1](https://github.com/Automattic/newspack-popups/compare/v2.23.1...v2.24.0-alpha.1) (2023-09-28)


### Features

* remove GA related code ([#1220](https://github.com/Automattic/newspack-popups/issues/1220)) ([cb2ce82](https://github.com/Automattic/newspack-popups/commit/cb2ce82919cca4ca9f6812cf445d71982b8e3cab))

## [2.23.1](https://github.com/Automattic/newspack-popups/compare/v2.23.0...v2.23.1) (2023-09-13)


Expand Down
26 changes: 13 additions & 13 deletions composer.lock

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

9 changes: 6 additions & 3 deletions includes/class-newspack-popups-data-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ function( $block ) use ( $block_name ) {
)[0];

if ( $donate_block && method_exists( '\Newspack\Donations', 'get_donation_settings' ) ) {
$is_manual = $donate_block['attrs']['manual'] ?? false;
$is_layout_tiers = isset( $donate_block['attrs']['layoutOption'] ) && 'tiers' === $donate_block['attrs']['layoutOption'];
$default_settings = \Newspack\Donations::get_donation_settings();
$is_manual = $donate_block['attrs']['manual'] ?? false;
$is_layout_tiers = isset( $donate_block['attrs']['layoutOption'] ) && 'tiers' === $donate_block['attrs']['layoutOption'];
$default_settings = \Newspack\Donations::get_donation_settings();
if ( ! $default_settings || is_wp_error( $default_settings ) ) {
$default_settings = [];
}
$donation_settings = $is_manual ? \wp_parse_args( $donate_block['attrs'], $default_settings ) : $default_settings;
$is_tiered = $donation_settings['tiered'] ?? false;
$suggested_amounts = $donation_settings['amounts'] ?? [];
Expand Down
126 changes: 0 additions & 126 deletions includes/class-newspack-popups-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,113 +826,6 @@ private static function get_form_class( $type, $element_id ) {
return $element_id . $type_index; // Use a unique class name.
}

/**
* Add tracked analytics events to use in Newspack Plugin's newspack_analytics_events filter.
*
* @param object $popup The popup object.
* @param string $body Post body.
* @param string $element_id The id of the popup element.
*/
private static function get_analytics_events( $popup, $body, $element_id ) {
if ( Newspack_Popups::is_preview_request() || ! Newspack_Popups::is_tracking() ) {
return [];
}

$popup_id = $popup['id'];
$segments = array_reduce(
$popup['segments'],
function( $acc, $segment ) {
if ( $segment instanceof \WP_Term ) {
$acc[] = $segment->name;
}
return $acc;
},
[]
);
$event_category = __( 'Newspack Announcement', 'newspack-popups' );
$formatted_placement = ucwords( str_replace( '_', ' ', $popup['options']['placement'] ) );
$default_event_label = sprintf(
// Translators: Analytics label with prompt details (placement, title, ID, targeted segments).
__( '%1$s: %2$s (%3$s) - %4$s', 'newspack-popups' ),
$formatted_placement,
$popup['title'],
$popup_id,
0 < count( $segments ) ? implode( '; ', $segments ) : __( 'Everyone', 'newspack-popups' )
);
$has_link = preg_match( '/<a\s/', $body ) !== 0;
$newspack_form_class = apply_filters( 'newspack_campaigns_form_class', '.newspack-subscribe-form' );
$newspack_form_class = '.' === substr( $newspack_form_class, 0, 1 ) ? substr( $newspack_form_class, 1 ) : $newspack_form_class; // Strip the "." class selector.
$has_register_form = preg_match( '/id="newspack-(register|subscribe)-(.+)"/', $body ) !== 0;
$has_lists_field = preg_match( '/name="lists\[\]"/', $body ) !== 0;
$has_form = preg_match( '/<form\s|mc4wp-form|\[gravityforms\s|' . $newspack_form_class . '/', $body ) !== 0;
$has_dismiss_form = self::is_overlay( $popup );

$analytics_events = [
[
'on' => 'ini-load',
'element' => '#' . esc_attr( $element_id ),
'event_name' => __( 'Load', 'newspack-popups' ),
'non_interaction' => true,
],
[
'on' => 'visible',
'element' => '#' . esc_attr( $element_id ),
'event_name' => __( 'Seen', 'newspack-popups' ),
'non_interaction' => true,
'visibilitySpec' => [
'totalTimeMin' => 500,
],
],
];

if ( $has_link ) {
$analytics_events[] = [
'on' => 'click',
'element' => '#' . esc_attr( $element_id ) . ' a',
'amp_element' => '#' . esc_attr( $element_id ) . ' a',
'event_name' => __( 'Link Click', 'newspack-popups' ),
];
}

if ( $has_form ) {
$analytics_events[] = [
'amp_on' => 'amp-form-submit',
'on' => 'submit',
'element' => '#' . esc_attr( $element_id ) . ' form:not(.popup-dismiss-form)', // Not a dismissal form.
'event_name' => __( 'Form Submission', 'newspack-popups' ),
];
}
if ( $has_dismiss_form ) {
$analytics_events[] = [
'amp_on' => 'amp-form-submit-success',
'on' => 'submit',
'element' => '#' . esc_attr( $element_id ) . ' .popup-dismiss-form',
'event_name' => __( 'Dismissal', 'newspack-popups' ),
'non_interaction' => true,
];
}

foreach ( $analytics_events as &$event ) {
$event_label = $default_event_label;

// If a form submission and the form contains registration + list info, append that to the event label.
if ( isset( $event['amp_on'] ) && 'amp-form-submit' === $event['amp_on'] && $has_register_form ) {
$event_label .= ' | ${formId}';

// If the reg form has a lists[] field, append the value to the event label.
if ( $has_lists_field ) {
$event_label .= ' - ${formFields[lists[]]}';
}
}

$event['id'] = self::get_uniqid();
$event['event_category'] = esc_attr( $event_category );
$event['event_label'] = esc_attr( $event_label );
}

return $analytics_events;
}

/**
* Canonise popups id. The id from WP will be an integer, but AMP does not play well with that and needs a string.
*
Expand Down Expand Up @@ -1044,7 +937,6 @@ private static function get_frequency_config( $popup ) {
public static function generate_inline_popup( $popup ) {
global $wp;

do_action( 'newspack_campaigns_before_campaign_render', $popup );
$blocks = parse_blocks( $popup['content'] );
$body = '';
self::add_form_hooks( $popup );
Expand All @@ -1069,16 +961,6 @@ public static function generate_inline_popup( $popup ) {
$assigned_segments = Newspack_Segments_Model::get_popup_segments_ids_string( $popup['id'] );
$frequency_config = self::get_frequency_config( $popup );

$analytics_events = self::get_analytics_events( $popup, $body, $element_id );
if ( ! empty( $analytics_events ) ) {
add_filter(
'newspack_analytics_events',
function ( $evts ) use ( $analytics_events ) {
return array_merge( $evts, $analytics_events );
}
);
}

ob_start();
?>
<div
Expand Down Expand Up @@ -1124,7 +1006,6 @@ public static function generate_popup( $popup ) {
return self::generate_inline_popup( $popup );
}

do_action( 'newspack_campaigns_before_campaign_render', $popup );
$blocks = parse_blocks( $popup['content'] );
$body = '';
self::add_form_hooks( $popup );
Expand Down Expand Up @@ -1157,13 +1038,6 @@ public static function generate_popup( $popup ) {
$assigned_segments = Newspack_Segments_Model::get_popup_segments_ids_string( $popup['id'] );
$frequency_config = self::get_frequency_config( $popup );

add_filter(
'newspack_analytics_events',
function ( $evts ) use ( $popup, $body, $element_id ) {
return array_merge( $evts, self::get_analytics_events( $popup, $body, $element_id ) );
}
);

$animation_id = 'a_' . $element_id;

ob_start();
Expand Down
Loading