| 1 |
<?php |
| 2 |
/** |
| 3 |
* Aha 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 AhaMomentEvents |
| 20 |
* |
| 21 |
* Tracks aha moment-related events. |
| 22 |
* |
| 23 |
* @package WpVr\Tracking\Events |
| 24 |
* @since 8.5.37 |
| 25 |
*/ |
| 26 |
class AhaMomentEvents 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( 'rex_wpvr_embadded_tour', array( $this, 'track_embadded_tour' ), 10, 2 ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Track an aha moment when a tour is embedded. |
| 39 |
* |
| 40 |
* @param int $tour_id The ID of the tour post. |
| 41 |
* @param array $args Additional arguments for the tour rendering. |
| 42 |
* @since 8.5.37 |
| 43 |
*/ |
| 44 |
public function track_embadded_tour($tour_id, $args) { |
| 45 |
$tour = get_post( $tour_id ); |
| 46 |
|
| 47 |
if ( ! $tour || $tour->post_type !== 'wpvr_item' ) { |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
$post_type = $tour->post_type; |
| 52 |
$post_type_object = get_post_type_object( $post_type ); |
| 53 |
$post_type_name = $post_type_object ? strtolower( $post_type_object->labels->singular_name ) : 'post'; |
| 54 |
|
| 55 |
$this->track_aha_moment( 'tour_embadded', array( |
| 56 |
'post_type' => $post_type_name, |
| 57 |
'tour_id' => $tour_id, |
| 58 |
'title' => $tour->post_title, |
| 59 |
'render_type' => $args, |
| 60 |
'timestamp' => current_time( 'c' ), |
| 61 |
) ); |
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
|