PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.4.2
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.4.2
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 All 96 releases
sureforms / admin / analytics.php

analytics.php in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 1.4.2, at admin/analytics.php

214 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Analytics class helps to connect BSFAnalytics.
4 *
5 * @package sureforms.
6 */
7
8 namespace SRFM\Admin;
9
10 use SRFM\Inc\Traits\Get_Instance;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15 /**
16 * Analytics class.
17 *
18 * @since 1.4.0
19 */
20 class Analytics {
21 use Get_Instance;
22
23 /**
24 * Class constructor.
25 *
26 * @return void
27 * @since 1.4.0
28 */
29 public function __construct() {
30 /*
31 * BSF Analytics.
32 */
33 if ( ! class_exists( 'BSF_Analytics_Loader' ) ) {
34 require_once SRFM_DIR . 'inc/lib/bsf-analytics/class-bsf-analytics-loader.php';
35 }
36
37 if ( ! class_exists( 'Astra_Notices' ) ) {
38 require_once SRFM_DIR . 'inc/lib/astra-notices/class-astra-notices.php';
39 }
40
41 add_filter(
42 'uds_survey_allowed_screens',
43 static function () {
44 return [ 'plugins' ];
45 }
46 );
47
48 $srfm_bsf_analytics = \BSF_Analytics_Loader::get_instance();
49
50 $srfm_bsf_analytics->set_entity(
51 [
52 'sureforms' => [
53 'product_name' => 'SureForms',
54 'path' => SRFM_DIR . 'inc/lib/bsf-analytics',
55 'author' => 'SureForms',
56 'time_to_display' => '+24 hours',
57 'deactivation_survey' => apply_filters(
58 'srfm_deactivation_survey_data',
59 [
60 [
61 'id' => 'deactivation-survey-sureforms',
62 'popup_logo' => SRFM_URL . 'admin/assets/sureforms-logo.png',
63 'plugin_slug' => 'sureforms',
64 'popup_title' => 'Quick Feedback',
65 'support_url' => 'https://sureforms.com/contact/',
66 'popup_description' => 'If you have a moment, please share why you are deactivating SureForms:',
67 'show_on_screens' => [ 'plugins' ],
68 'plugin_version' => SRFM_VER,
69 ],
70 ]
71 ),
72 ],
73 ]
74 );
75
76 add_filter( 'bsf_core_stats', [ $this, 'add_srfm_analytics_data' ] );
77 }
78
79 /**
80 * Callback function to add SureForms specific analytics data.
81 *
82 * @param array $stats_data existing stats_data.
83 * @since 1.4.0
84 * @return array
85 */
86 public function add_srfm_analytics_data( $stats_data ) {
87 $stats_data['plugin_data']['sureforms'] = [
88 'free_version' => SRFM_VER,
89 'site_language' => get_locale(),
90 ];
91 $stats_data['plugin_data']['sureforms']['numeric_values'] = [
92 'total_forms' => wp_count_posts( SRFM_FORMS_POST_TYPE )->publish ?? 0,
93 'instant_forms_enabled' => $this->instant_forms_enabled(),
94 'forms_using_custom_css' => $this->forms_using_custom_css(),
95 'ai_generated_forms' => $this->ai_generated_forms(),
96 ];
97
98 $stats_data['plugin_data']['sureforms'] = array_merge_recursive( $stats_data['plugin_data']['sureforms'], $this->global_settings_data() );
99
100 return $stats_data;
101 }
102
103 /**
104 * Return total number of forms using instant forms.
105 *
106 * @since 1.4.0
107 * @return int
108 */
109 public function instant_forms_enabled() {
110 $meta_query = [
111 [
112 'key' => '_srfm_instant_form_settings',
113 'value' => '"enable_instant_form";b:1;',
114 'compare' => 'LIKE',
115 ],
116 ];
117
118 return $this->custom_wp_query_total_posts( $meta_query );
119 }
120
121 /**
122 * Return total number of ai generated forms.
123 *
124 * @since 1.4.0
125 * @return int
126 */
127 public function ai_generated_forms() {
128 $meta_query = [
129 [
130 'key' => '_srfm_is_ai_generated',
131 'value' => '',
132 'compare' => '!=', // Checks if the value is NOT empty.
133 ],
134 ];
135
136 return $this->custom_wp_query_total_posts( $meta_query );
137 }
138
139 /**
140 * Returns total number of forms using custom css.
141 *
142 * @since 1.4.0
143 * @return int
144 */
145 public function forms_using_custom_css() {
146 $meta_query = [
147 [
148 'key' => '_srfm_form_custom_css',
149 'value' => '',
150 'compare' => '!=', // Checks if the value is NOT empty.
151 ],
152 ];
153
154 return $this->custom_wp_query_total_posts( $meta_query );
155 }
156
157 /**
158 * Generates global setting data for analytics
159 *
160 * @since 1.4.0
161 * @return array
162 */
163 public function global_settings_data() {
164 $global_data = [];
165
166 $security_settings = get_option( 'srfm_security_settings_options', [] );
167 $global_data['boolean_values']['honeypot_enabled'] = isset( $security_settings['srfm_honeypot'] ) && true === $security_settings['srfm_honeypot'];
168
169 $email_summary_data = get_option( 'srfm_email_summary_settings_options', [] );
170 $global_data['boolean_values']['email_summary_enabled'] = isset( $email_summary_data['srfm_email_summary'] ) && true === $email_summary_data['srfm_email_summary'];
171
172 $global_data['boolean_values']['suretriggers_active'] = is_plugin_active( 'suretriggers/suretriggers.php' );
173
174 $bsf_internal_referrer = get_option( 'bsf_product_referers', [] );
175 if ( ! empty( $bsf_internal_referrer['sureforms'] ) ) {
176 $global_data['internal_referer'] = $bsf_internal_referrer['sureforms'];
177 } else {
178 $global_data['internal_referer'] = '';
179 }
180
181 $general_settings = get_option( 'srfm_general_settings_options', [] );
182 $global_data['boolean_values']['ip_logging_enabled'] = ! empty( $general_settings['srfm_ip_log'] );
183
184 $validation_messages = get_option( 'srfm_default_dynamic_block_option', [] );
185 $global_data['boolean_values']['custom_validation_message'] = ! empty( $validation_messages ) && is_array( $validation_messages );
186
187 return $global_data;
188 }
189
190 /**
191 * Runs custom WP_Query to fetch data as per requirement
192 *
193 * @param array $meta_query meta query array for WP_Query.
194 * @since 1.4.0
195 * @return int
196 */
197 private function custom_wp_query_total_posts( $meta_query ) {
198
199 $args = [
200 'post_type' => SRFM_FORMS_POST_TYPE,
201 'post_status' => 'publish',
202 'posts_per_page' => -1,
203 'meta_query' => $meta_query, //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Meta query required as we need to fetch count of nested data.
204 ];
205
206 $query = new \WP_Query( $args );
207 $posts_count = $query->found_posts;
208
209 wp_reset_postdata();
210
211 return $posts_count;
212 }
213 }
214