| 1 |
<?php |
| 2 |
/** |
| 3 |
* Habit moment events. |
| 4 |
* |
| 5 |
* @package WpVr\Tracking |
| 6 |
* @since 8.5.37 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Wpvr\Admin\Tracking\Events; |
| 10 |
|
| 11 |
// Exit if accessed directly. |
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
use Wpvr\Admin\Tracking\AbstractEvent; |
| 17 |
|
| 18 |
/** |
| 19 |
* Class HabitMomentEvents |
| 20 |
* |
| 21 |
* Tracks habit moment-related events. |
| 22 |
* |
| 23 |
* @package WpVr\Tracking\Events |
| 24 |
* @since 8.5.37 |
| 25 |
*/ |
| 26 |
class HabitMomentEvents extends AbstractEvent { |
| 27 |
|
| 28 |
/** |
| 29 |
* Register WordPress hooks for this event. |
| 30 |
* |
| 31 |
* @since 8.5.37 |
| 32 |
*/ |
| 33 |
public function register_hooks() { |
| 34 |
add_action('current_screen', array( $this, 'track_page_view' ) ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Track page views with user information |
| 39 |
* |
| 40 |
* @param \WP_Screen $screen The current screen object |
| 41 |
* @since 8.5.37 |
| 42 |
*/ |
| 43 |
public function track_page_view($screen) { |
| 44 |
if ( ! is_admin() || ! $screen->id ) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$current_user_id = get_current_user_id(); |
| 49 |
$current_user_email = (wp_get_current_user())->user_email; |
| 50 |
$page_view_count = (int) get_user_meta($current_user_id, '_rex_page_view_count_' . $screen->id, true); |
| 51 |
$page_view_count++; |
| 52 |
update_user_meta($current_user_id, '_rex_page_view_count_' . $screen->id, $page_view_count); |
| 53 |
|
| 54 |
$this->track_habit_moment( 'page_view', array( |
| 55 |
'screen_id' => $screen->id, |
| 56 |
'screen_base' => $screen->base, |
| 57 |
'view_count' => $page_view_count, |
| 58 |
'user_email' => $current_user_email |
| 59 |
) ); |
| 60 |
} |
| 61 |
} |