' . esc_html__( 'Customer Activity Tracking', 'aisp-customer-activity' ) . ''; $content .= '

' . esc_html__( 'When you are logged in as a registered customer, this site records the following information for internal sales and follow-up purposes:', 'aisp-customer-activity' ) . '

'; $content .= ''; $content .= '

' . esc_html__( 'This information is visible only to store administrators and is used solely to assist customers who may have left items in their cart. It is not shared with third parties.', 'aisp-customer-activity' ) . '

'; $content .= '

' . esc_html__( 'Tracking data is automatically deleted after a period of inactivity as configured by the store, or immediately upon request.', 'aisp-customer-activity' ) . '

'; wp_add_privacy_policy_content( __( 'Customer Activity', 'aisp-customer-activity' ), wp_kses_post( $content ) ); } // ------------------------------------------------------------------------- // 2. Personal data exporter // ------------------------------------------------------------------------- public static function register_exporter( array $exporters ): array { $exporters['aisp-customer-activity'] = [ 'exporter_friendly_name' => __( 'Customer Activity', 'aisp-customer-activity' ), 'callback' => [ __CLASS__, 'export_user_data' ], ]; return $exporters; } public static function export_user_data( string $email, int $page = 1 ): array { $user = get_user_by( 'email', $email ); if ( ! $user ) { return [ 'data' => [], 'done' => true ]; } $last_login = get_user_meta( $user->ID, 'aisp_ca_last_login', true ); $last_activity = get_user_meta( $user->ID, 'aisp_ca_last_activity', true ); $cart_count = get_user_meta( $user->ID, 'aisp_ca_cart_count', true ); $cart_total = get_user_meta( $user->ID, 'aisp_ca_cart_total', true ); $cart_updated = get_user_meta( $user->ID, 'aisp_ca_cart_updated', true ); // Only export if we actually have tracking data for this user. if ( ! $last_activity && ! $last_login ) { return [ 'data' => [], 'done' => true ]; } $data = []; if ( $last_login ) { $data[] = [ 'name' => __( 'Last Login', 'aisp-customer-activity' ), 'value' => date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), (int) $last_login ), ]; } if ( $last_activity ) { $data[] = [ 'name' => __( 'Last Activity', 'aisp-customer-activity' ), 'value' => date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), (int) $last_activity ), ]; } if ( $cart_count !== '' ) { $data[] = [ 'name' => __( 'Cart Item Count (last recorded)', 'aisp-customer-activity' ), 'value' => absint( $cart_count ), ]; } if ( $cart_total !== '' ) { $data[] = [ 'name' => __( 'Cart Total (last recorded)', 'aisp-customer-activity' ), 'value' => wc_price( $cart_total ), ]; } if ( $cart_updated ) { $data[] = [ 'name' => __( 'Cart Last Updated', 'aisp-customer-activity' ), 'value' => date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), (int) $cart_updated ), ]; } return [ 'data' => [ [ 'group_id' => 'aisp-customer-activity', 'group_label' => __( 'Customer Activity', 'aisp-customer-activity' ), 'item_id' => 'aisp-ca-' . $user->ID, 'data' => $data, ], ], 'done' => true, ]; } // ------------------------------------------------------------------------- // 3. Personal data eraser // ------------------------------------------------------------------------- public static function register_eraser( array $erasers ): array { $erasers['aisp-customer-activity'] = [ 'eraser_friendly_name' => __( 'Customer Activity', 'aisp-customer-activity' ), 'callback' => [ __CLASS__, 'erase_user_data' ], ]; return $erasers; } public static function erase_user_data( string $email, int $page = 1 ): array { $user = get_user_by( 'email', $email ); if ( ! $user ) { return [ 'items_removed' => false, 'items_retained' => false, 'messages' => [], 'done' => true, ]; } $had_data = (bool) get_user_meta( $user->ID, 'aisp_ca_last_activity', true ); AISP_Customer_Activity_Tracker::delete_user_metas( $user->ID ); return [ 'items_removed' => $had_data, 'items_retained' => false, 'messages' => $had_data ? [ __( 'Customer Activity tracking data erased.', 'aisp-customer-activity' ) ] : [], 'done' => true, ]; } }