@@ -33,7 +33,7 @@ public function setup_admin_hooks() {
3333 add_action ( 'wp_ajax_raft_dismiss_welcome_notice ' , array ( $ this , 'remove_welcome_notice ' ) );
3434 add_action ( 'wp_ajax_raft_set_otter_ref ' , array ( $ this , 'set_otter_ref ' ) );
3535 add_action ( 'activated_plugin ' , array ( $ this , 'after_otter_activation ' ) );
36- add_action ( 'admin_print_scripts ' , array ( $ this , 'add_nps_form ' ) );
36+ add_action ( 'admin_enqueue_scripts ' , array ( $ this , 'register_internal_page ' ) );
3737
3838 add_action ( 'enqueue_block_editor_assets ' , array ( $ this , 'add_fse_design_pack_notice ' ) );
3939 add_action ( 'wp_ajax_raft_dismiss_design_pack_notice ' , array ( $ this , 'remove_design_pack_notice ' ) );
@@ -380,50 +380,35 @@ public function after_otter_activation( $plugin ) {
380380 }
381381
382382 /**
383- * Add NPS form .
383+ * Register internal pages .
384384 *
385385 * @return void
386386 */
387- public function add_nps_form () {
387+ public function register_internal_page () {
388388 $ screen = get_current_screen ();
389-
390- if ( current_user_can ( 'manage_options ' ) && ( 'dashboard ' === $ screen ->id || 'themes ' === $ screen ->id ) ) {
391- $ website_url = preg_replace ( '/[^a-zA-Z0-9]+/ ' , '' , get_site_url () );
392-
393- $ config = array (
394- 'environmentId ' => 'clp9hp3j71oqndl2ietgq8nej ' ,
395- 'apiHost ' => 'https://app.formbricks.com ' ,
396- 'userId ' => 'raft_ ' . $ website_url ,
397- 'attributes ' => array (
398- 'days_since_install ' => self ::convert_to_category ( round ( ( time () - get_option ( 'raft_install ' , time () ) ) / DAY_IN_SECONDS ) ),
399- ),
400- );
401-
402- echo '<script type="text/javascript">!function(){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src="https://unpkg.com/@formbricks/js@^1.6.5/dist/index.umd.js";var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e),setTimeout(function(){window.formbricks.init( ' . wp_json_encode ( $ config ) . ')},500)}();</script> ' ;
389+
390+ if ( ! current_user_can ( 'manage_options ' ) || ( 'dashboard ' !== $ screen ->id && 'themes ' !== $ screen ->id ) ) {
391+ return ;
403392 }
404- }
393+
394+ add_filter (
395+ 'themeisle-sdk/survey/ ' . RAFT_PRODUCT_SLUG ,
396+ function ( $ data , $ page_slug ) {
397+ $ install_days_number = intval ( ( time () - get_option ( 'raft_install ' , time () ) ) / DAY_IN_SECONDS );
398+
399+ $ data = array (
400+ 'environmentId ' => 'clp9hp3j71oqndl2ietgq8nej ' ,
401+ 'attributes ' => array (
402+ 'install_days_number ' => $ install_days_number ,
403+ 'version ' => RAFT_VERSION ,
404+ ),
405+ );
405406
406- /**
407- * Convert a number to a category.
408- *
409- * @param int $number Number to convert.
410- * @param int $scale Scale.
411- *
412- * @return int
413- */
414- public static function convert_to_category ( $ number , $ scale = 1 ) {
415- $ normalized_number = intval ( round ( $ number / $ scale ) );
416-
417- if ( 0 === $ normalized_number || 1 === $ normalized_number ) {
418- return 0 ;
419- } elseif ( $ normalized_number > 1 && $ normalized_number < 8 ) {
420- return 7 ;
421- } elseif ( $ normalized_number >= 8 && $ normalized_number < 31 ) {
422- return 30 ;
423- } elseif ( $ normalized_number > 30 && $ normalized_number < 90 ) {
424- return 90 ;
425- } elseif ( $ normalized_number > 90 ) {
426- return 91 ;
427- }
407+ return $ data ;
408+ },
409+ 10 ,
410+ 2
411+ );
412+ do_action ( 'themeisle_internal_page ' , RAFT_PRODUCT_SLUG , $ screen ->id );
428413 }
429414}
0 commit comments