PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.37
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.37
9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 8.5.4 All 221 releases
wpvr / admin / Tracking / AbstractEvent.php

AbstractEvent.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.37, at admin/Tracking/AbstractEvent.php

145 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abstract class for all event types.
4 *
5 * @package WpVr\Tracking
6 * @since 8.5.37
7 */
8
9 namespace Wpvr\Admin\Tracking;
10
11 // Exit if accessed directly.
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Class AbstractEvent
19 *
20 * Base class for all tracking events.
21 *
22 * @package WpVr\Tracking
23 * @since 8.5.37
24 */
25 abstract class AbstractEvent {
26
27 /**
28 * PostHog client instance.
29 *
30 * @var PosthogClient
31 */
32 protected $client;
33
34 /**
35 * Constructor.
36 *
37 * @param PosthogClient $client PostHog client.
38 * @since 8.5.37
39 */
40 public function __construct( $client ) {
41 $this->client = $client;
42 $this->register_hooks();
43 }
44
45 /**
46 * Register WordPress hooks for this event.
47 *
48 * Each child class must implement this to define when events are triggered.
49 * @since 8.5.37
50 */
51 abstract public function register_hooks();
52
53 /**
54 * Get common properties for all events.
55 *
56 * @return array Common properties.
57 * @since 8.5.37
58 */
59 protected function get_common_properties() {
60 $properties = array(
61 'timestamp' => current_time( 'c' ),
62 'plugin' => 'wpvr',
63 'version' => defined('WPVR_VERSION') ? WPVR_VERSION : 'unknown',
64 );
65
66 return $properties;
67 }
68
69 /**
70 * Track signup moment event.
71 *
72 * @param string $action The specific action that triggered this event.
73 * @param array $metadata Additional metadata for the event.
74 * @since 8.5.37
75 */
76 protected function track_signup_moment( $action, $metadata = array() ) {
77 $properties = array_merge(
78 $this->get_common_properties(),
79 array(
80 'funnel_type' => 'signup',
81 ),
82 $metadata
83 );
84
85 $this->client->capture( $action, $properties );
86 }
87
88 /**
89 * Track setup moment event.
90 *
91 * @param string $action The specific action that triggered this event.
92 * @param array $metadata Additional metadata for the event.
93 * @since 8.5.37
94 */
95 protected function track_setup_moment( $action, $metadata = array() ) {
96 $properties = array_merge(
97 $this->get_common_properties(),
98 array(
99 'funnel_type' => 'setup',
100 ),
101 $metadata
102 );
103
104 $this->client->capture( $action, $properties );
105 }
106
107 /**
108 * Track aha moment event.
109 *
110 * @param string $action The specific action that triggered this event.
111 * @param array $metadata Additional metadata for the event.
112 * @since 8.5.37
113 */
114 protected function track_aha_moment( $action, $metadata = array() ) {
115 $properties = array_merge(
116 $this->get_common_properties(),
117 array(
118 'funnel_type' => 'aha',
119 ),
120 $metadata
121 );
122
123 $this->client->capture( $action, $properties );
124 }
125
126 /**
127 * Track habit moment event.
128 *
129 * @param string $action The specific action that triggered this event.
130 * @param array $metadata Additional metadata for the event.
131 * @since 8.5.37
132 */
133 protected function track_habit_moment( $action, $metadata = array() ) {
134 $properties = array_merge(
135 $this->get_common_properties(),
136 array(
137 'funnel_type' => 'habit',
138 ),
139 $metadata
140 );
141
142 $this->client->capture( $action, $properties );
143 }
144 }
145