diff --git a/includes/class-newspack-popups-model.php b/includes/class-newspack-popups-model.php index 7deb01a7..77ea051a 100644 --- a/includes/class-newspack-popups-model.php +++ b/includes/class-newspack-popups-model.php @@ -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( '/ '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. * @@ -1068,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(); ?>
post_content, 'woocommerce_my_account' ); } - /** - * Should tracking code be inserted? - * We shouldn't be tracking analytics in the dashboard or on the front-end by admin/editor users. - */ - public static function is_tracking() { - if ( is_admin() || self::is_user_admin() ) { - return false; - } - return true; - } - /** * Create campaign. *