@@ -79,6 +79,10 @@ public function __construct( Visualizer_Plugin $plugin ) {
7979
8080 $ this ->_addFilter ( 'admin_footer_text ' , 'render_review_notice ' );
8181
82+ if ( ! defined ( 'TI_CYPRESS_TESTING ' ) ) {
83+ $ this ->_addFilter ( 'themeisle-sdk/survey/ ' . VISUALIZER_PRODUCT_SLUG , 'get_survey_metadata ' , 10 , 2 );
84+ }
85+
8286 if ( defined ( 'TI_CYPRESS_TESTING ' ) ) {
8387 $ this ->load_cypress_hooks ();
8488 }
@@ -934,7 +938,7 @@ private function getQuery() {
934938 */
935939 public function renderSupportPage () {
936940 wp_enqueue_style ( 'visualizer-upsell ' , VISUALIZER_ABSURL . 'css/upsell.css ' , array (), Visualizer_Plugin::VERSION );
937- $ this -> load_survey ( );
941+ do_action ( ' themeisle_internal_page ' , VISUALIZER_PRODUCT_SLUG , ' support ' );
938942 include_once VISUALIZER_ABSPATH . '/templates/support.php ' ;
939943 }
940944
@@ -1091,7 +1095,7 @@ public function renderLibraryPage() {
10911095 )
10921096 );
10931097
1094- $ this -> load_survey ( );
1098+ do_action ( ' themeisle_internal_page ' , VISUALIZER_PRODUCT_SLUG , ' library ' );
10951099
10961100 if ( ! apply_filters ( 'visualizer_is_business ' , false ) ) {
10971101 do_action ( 'themeisle_sdk_load_banner ' , 'visualizer ' );
@@ -1229,72 +1233,53 @@ public static function checkChartStatus( $type ) {
12291233
12301234 /**
12311235 * Get the survey metadata.
1236+ *
1237+ * @param array $data The data for survey in Formbricks format.
1238+ * @param string $page_slug The slug of the loaded page.
12321239 *
12331240 * @return array The survey metadata.
12341241 */
1235- private function get_survey_metadata () {
1236- $ install_date = get_option ( 'visualizer_install ' , false );
1237- $ install_category = 0 ;
1238-
1239- if ( false !== $ install_date ) {
1240- $ days_since_install = round ( ( time () - $ install_date ) / DAY_IN_SECONDS );
1241-
1242- if ( 0 === $ days_since_install || 1 === $ days_since_install ) {
1243- $ install_category = 0 ;
1244- } elseif ( 1 < $ days_since_install && 8 > $ days_since_install ) {
1245- $ install_category = 7 ;
1246- } elseif ( 8 <= $ days_since_install && 31 > $ days_since_install ) {
1247- $ install_category = 30 ;
1248- } elseif ( 30 < $ days_since_install && 90 > $ days_since_install ) {
1249- $ install_category = 90 ;
1250- } elseif ( 90 <= $ days_since_install ) {
1251- $ install_category = 91 ;
1252- }
1242+ public function get_survey_metadata ( $ data , $ page_slug ) {
1243+ $ install_date = get_option ( 'visualizer_install ' , time () );
1244+ $ install_category = 0 ;
1245+
1246+ $ install_days_number = intval ( ( time () - $ install_date ) / DAY_IN_SECONDS );
1247+
1248+ if ( 0 === $ install_days_number || 1 === $ install_days_number ) {
1249+ $ install_category = 0 ;
1250+ } elseif ( 1 < $ install_days_number && 8 > $ install_days_number ) {
1251+ $ install_category = 7 ;
1252+ } elseif ( 8 <= $ install_days_number && 31 > $ install_days_number ) {
1253+ $ install_category = 30 ;
1254+ } elseif ( 30 < $ install_days_number && 90 > $ install_days_number ) {
1255+ $ install_category = 90 ;
1256+ } elseif ( 90 <= $ install_days_number ) {
1257+ $ install_category = 91 ;
12531258 }
1259+
12541260
12551261 $ plugin_data = get_plugin_data ( VISUALIZER_BASEFILE , false , false );
12561262 $ plugin_version = '' ;
12571263 if ( ! empty ( $ plugin_data ['Version ' ] ) ) {
12581264 $ plugin_version = $ plugin_data ['Version ' ];
12591265 }
12601266
1261- $ user_id = 'visualizer_ ' . preg_replace ( '/[^\w\d]*/ ' , '' , get_site_url () ); // Use a normalized version of the site URL as a user ID.
1262-
1263- $ license_data = get_option ( 'visualizer_pro_license_data ' , false );
1264- if ( false !== $ license_data && isset ( $ license_data ->key ) ) {
1265- $ user_id = 'visualizer_ ' . $ license_data ->key ;
1266- }
1267-
1268- return array (
1269- 'userId ' => $ user_id ,
1267+ $ data = array (
1268+ 'environmentId ' => 'cltef8cut1s7wyyfxy3rlxzs5 ' ,
12701269 'attributes ' => array (
1271- 'days_since_install ' => strval ( $ install_category ),
1272- 'free_version ' => $ plugin_version ,
1273- 'pro_version ' => defined ( 'VISUALIZER_PRO_VERSION ' ) ? VISUALIZER_PRO_VERSION : '' ,
1274- 'license_status ' => apply_filters ( 'product_visualizer_license_status ' , 'invalid ' ),
1270+ 'days_since_install ' => strval ( $ install_category ),
1271+ 'free_version ' => $ plugin_version ,
1272+ 'pro_version ' => defined ( 'VISUALIZER_PRO_VERSION ' ) ? VISUALIZER_PRO_VERSION : '' ,
1273+ 'license_status ' => apply_filters ( 'product_visualizer_license_status ' , 'invalid ' ),
1274+ 'install_days_number ' => $ install_days_number ,
12751275 ),
12761276 );
1277- }
12781277
1279- /**
1280- * Load the survey.
1281- */
1282- private function load_survey () {
1283-
1284- if ( defined ( 'TI_CYPRESS_TESTING ' ) ) {
1285- return ;
1286- }
1287-
1288- $ survey_handler = apply_filters ( 'themeisle_sdk_dependency_script_handler ' , 'survey ' );
1289-
1290- if ( empty ( $ survey_handler ) ) {
1291- return ;
1278+ $ license_data = get_option ( 'visualizer_pro_license_data ' , false );
1279+ if ( isset ( $ license_data ->key ) ) {
1280+ $ data ['attributes ' ]['license_key ' ] = apply_filters ( 'themeisle_sdk_secret_masking ' , $ license_data ->key );
12921281 }
12931282
1294- $ metadata = $ this ->get_survey_metadata ();
1295-
1296- do_action ( 'themeisle_sdk_dependency_enqueue_script ' , 'survey ' );
1297- wp_enqueue_script ( 'visualizer_chart_survey ' , VISUALIZER_ABSURL . 'js/survey.js ' , array ( $ survey_handler ), $ metadata ['attributes ' ]['free_version ' ], true );
1298- wp_localize_script ( 'visualizer_chart_survey ' , 'visualizerSurveyData ' , $ metadata );
1283+ return $ data ;
12991284 }
13001285}
0 commit comments