PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.10
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.10
5.6.11 5.6.10 5.6.9 5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / analytics_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago analytics_helper.php 6 months ago auth_helper.php 6 months ago blocks_helper.php 1 year ago booking_helper.php 6 months ago bricks_helper.php 1 year ago bundles_helper.php 1 year ago calendar_helper.php 11 months ago carts_helper.php 1 year ago connector_helper.php 11 months ago csv_helper.php 6 months ago customer_helper.php 6 months ago customer_import_helper.php 6 months ago database_helper.php 11 months ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 11 months ago encrypt_helper.php 1 year ago events_helper.php 11 months ago form_helper.php 6 months ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 6 months ago license_helper.php 1 year ago location_helper.php 1 year ago marketing_systems_helper.php 1 year ago meeting_systems_helper.php 1 year ago menu_helper.php 11 months ago meta_helper.php 6 months ago migrations_helper.php 1 year ago money_helper.php 6 months ago notifications_helper.php 11 months ago nps_survey_helper.php 6 months ago order_intent_helper.php 11 months ago orders_helper.php 1 year ago otp_helper.php 11 months ago pages_helper.php 1 year ago params_helper.php 1 year ago payments_helper.php 1 year ago price_breakdown_helper.php 1 year ago process_jobs_helper.php 1 year ago processes_helper.php 1 year ago replacer_helper.php 1 year ago resource_helper.php 1 year ago roles_helper.php 8 months ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 6 months ago settings_helper.php 6 months ago short_links_systems_helper.php 11 months ago shortcodes_helper.php 11 months ago sms_helper.php 1 year ago steps_helper.php 6 months ago stripe_connect_helper.php 11 months ago styles_helper.php 11 months ago support_topics_helper.php 1 year ago time_helper.php 11 months ago timeline_helper.php 11 months ago transaction_helper.php 6 months ago transaction_intent_helper.php 1 year ago util_helper.php 8 months ago version_specific_updates_helper.php 11 months ago whatsapp_helper.php 1 year ago work_periods_helper.php 7 months ago wp_datetime.php 1 year ago wp_user_helper.php 1 year ago
analytics_helper.php
165 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 class OsAnalyticsHelper {
8
9 /**
10 * Initialize BSF Analytics.
11 *
12 * @return void
13 */
14 public static function init() {
15
16 add_action( 'latepoint_settings_updated', array( self::class, 'update_contribute_option' ) );
17
18 if ( ! class_exists( 'BSF_Analytics_Loader' ) ) {
19 require_once LATEPOINT_ABSPATH . 'lib/kit/bsf-analytics/class-bsf-analytics-loader.php';
20 }
21
22 if ( ! class_exists( 'Astra_Notices' ) ) {
23 require_once LATEPOINT_ABSPATH . 'lib/kit/astra-notices/class-astra-notices.php';
24 }
25
26 $bsf_analytics = \BSF_Analytics_Loader::get_instance();
27
28 $bsf_analytics->set_entity(
29 [
30 'latepoint' => [
31 'product_name' => 'LatePoint',
32 'path' => LATEPOINT_ABSPATH . 'lib/kit/bsf-analytics',
33 'author' => 'LatePoint',
34 'time_to_display' => '+24 hours',
35 'deactivation_survey' => apply_filters(
36 'latepoint_deactivation_survey_data',
37 [
38 [
39 'id' => 'deactivation-survey-latepoint',
40 'popup_logo' => LATEPOINT_IMAGES_URL . 'logo.svg',
41 'plugin_slug' => 'latepoint',
42 'popup_title' => 'Quick Feedback',
43 'support_url' => 'https://latepoint.com/support/',
44 'popup_description' => 'If you have a moment, please share why you are deactivating LatePoint:',
45 'show_on_screens' => [ 'plugins' ],
46 'plugin_version' => LATEPOINT_VERSION,
47 ],
48 ]
49 ),
50 ],
51 ]
52 );
53
54 add_filter( 'bsf_core_stats', [ __CLASS__, 'add_latepoint_analytics_data' ] );
55 }
56
57 /**
58 * Toggle contribute to latepoint from general settings.
59 *
60 * @param array<mixed> $settings settings array.
61 * @return bool
62 */
63 public static function update_contribute_option( $settings ) {
64 if ( isset( $settings['contribute_to_latepoint'] ) && 'on' === $settings['contribute_to_latepoint'] ) {
65 $enable_tracking = 'yes';
66 } else {
67 $enable_tracking = '';
68 }
69
70 return update_option( 'latepoint_usage_optin', $enable_tracking );
71 }
72
73 /**
74 * Add LatePoint specific analytics data.
75 *
76 * @param array $stats_data Existing stats data.
77 * @return array
78 */
79 public static function add_latepoint_analytics_data( $stats_data ) {
80 $stats_data['plugin_data']['latepoint'] = [
81 'free_version' => LATEPOINT_VERSION,
82 'db_version' => LATEPOINT_DB_VERSION,
83 'site_language' => get_locale(),
84 ];
85
86 $stats_data['plugin_data']['latepoint']['numeric_values'] = [
87 'total_bookings' => self::get_table_count( LATEPOINT_TABLE_BOOKINGS ),
88 'total_services' => self::get_table_count( LATEPOINT_TABLE_SERVICES ),
89 'total_agents' => self::get_table_count( LATEPOINT_TABLE_AGENTS ),
90 'total_customers' => self::get_table_count( LATEPOINT_TABLE_CUSTOMERS ),
91 'total_locations' => self::get_table_count( LATEPOINT_TABLE_LOCATIONS ),
92 ];
93
94 // Add KPI tracking data.
95 $kpi_data = self::get_kpi_tracking_data();
96 if ( ! empty( $kpi_data ) ) {
97 $stats_data['plugin_data']['latepoint']['kpi_records'] = $kpi_data;
98 }
99
100 return $stats_data;
101 }
102
103 /**
104 * Get KPI tracking data for the last 2 days (excluding today).
105 *
106 * @return array KPI data organized by date.
107 */
108 private static function get_kpi_tracking_data() {
109 $kpi_data = [];
110 $today = current_time( 'Y-m-d' );
111
112 for ( $i = 1; $i <= 2; $i++ ) {
113 $date = gmdate( 'Y-m-d', strtotime( $today . ' -' . $i . ' days' ) );
114 $bookings = self::get_daily_count( LATEPOINT_TABLE_BOOKINGS, $date );
115 $orders = self::get_daily_count( LATEPOINT_TABLE_ORDERS, $date );
116
117 $kpi_data[ $date ] = [
118 'numeric_values' => [
119 'bookings' => $bookings,
120 'orders' => $orders,
121 ],
122 ];
123 }
124
125 return $kpi_data;
126 }
127
128 /**
129 * Get count of rows created on a specific date.
130 *
131 * @param string $table_name Full table name.
132 * @param string $date Date in Y-m-d format.
133 * @return int
134 */
135 private static function get_daily_count( $table_name, $date ) {
136 global $wpdb;
137
138 $start_date = $date . ' 00:00:00';
139 $end_date = $date . ' 23:59:59';
140
141 $count = $wpdb->get_var(
142 $wpdb->prepare(
143 'SELECT COUNT(*) FROM %i WHERE created_at >= %s AND created_at <= %s',
144 $table_name,
145 $start_date,
146 $end_date
147 )
148 );
149
150 return $count ? (int) $count : 0;
151 }
152
153 /**
154 * Get total row count from a table.
155 *
156 * @param string $table_name Full table name.
157 * @return int
158 */
159 private static function get_table_count( $table_name ) {
160 global $wpdb;
161 $count = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', $table_name ) );
162 return $count ? (int) $count : 0;
163 }
164 }
165