@@ -33,7 +33,7 @@ public function setup_admin_hooks() {
3333 add_action ( 'admin_notices ' , array ( $ this , 'render_welcome_notice ' ), 0 );
3434 add_action ( 'wp_ajax_jaxon_dismiss_welcome_notice ' , array ( $ this , 'remove_welcome_notice ' ) );
3535 add_action ( 'wp_ajax_jaxon_set_otter_ref ' , array ( $ this , 'set_otter_ref ' ) );
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_jaxon_dismiss_design_pack_notice ' , array ( $ this , 'remove_design_pack_notice ' ) );
@@ -307,50 +307,35 @@ private function get_otter_status(): string {
307307 }
308308
309309 /**
310- * Add NPS form .
310+ * Register internal pages .
311311 *
312312 * @return void
313313 */
314- public function add_nps_form () {
314+ public function register_internal_page () {
315315 $ screen = get_current_screen ();
316-
317- if ( current_user_can ( 'manage_options ' ) && ( 'dashboard ' === $ screen ->id || 'themes ' === $ screen ->id ) ) {
318- $ website_url = preg_replace ( '/[^a-zA-Z0-9]+/ ' , '' , get_site_url () );
319-
320- $ config = array (
321- 'environmentId ' => 'clr7jjqypey8v8up0bg5lk2nw ' ,
322- 'apiHost ' => 'https://app.formbricks.com ' ,
323- 'userId ' => 'jaxon_ ' . $ website_url ,
324- 'attributes ' => array (
325- 'days_since_install ' => self ::convert_to_category ( round ( ( time () - get_option ( 'jaxon_install ' , time () ) ) / DAY_IN_SECONDS ) ),
326- ),
327- );
328-
329- 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> ' ;
316+
317+ if ( ! current_user_can ( 'manage_options ' ) || ( 'dashboard ' !== $ screen ->id && 'themes ' !== $ screen ->id ) ) {
318+ return ;
330319 }
331- }
320+
321+ add_filter (
322+ 'themeisle-sdk/survey/ ' . JAXON_PRODUCT_SLUG ,
323+ function ( $ data , $ page_slug ) {
324+ $ install_days_number = intval ( ( time () - get_option ( 'jaxon_install ' , time () ) ) / DAY_IN_SECONDS );
325+
326+ $ data = array (
327+ 'environmentId ' => 'clr7jjqypey8v8up0bg5lk2nw ' ,
328+ 'attributes ' => array (
329+ 'install_days_number ' => $ install_days_number ,
330+ 'version ' => JAXON_VERSION ,
331+ ),
332+ );
332333
333- /**
334- * Convert a number to a category.
335- *
336- * @param int $number Number to convert.
337- * @param int $scale Scale.
338- *
339- * @return int
340- */
341- public static function convert_to_category ( $ number , $ scale = 1 ) {
342- $ normalized_number = intval ( round ( $ number / $ scale ) );
343-
344- if ( 0 === $ normalized_number || 1 === $ normalized_number ) {
345- return 0 ;
346- } elseif ( $ normalized_number > 1 && $ normalized_number < 8 ) {
347- return 7 ;
348- } elseif ( $ normalized_number >= 8 && $ normalized_number < 31 ) {
349- return 30 ;
350- } elseif ( $ normalized_number > 30 && $ normalized_number < 90 ) {
351- return 90 ;
352- } elseif ( $ normalized_number > 90 ) {
353- return 91 ;
354- }
334+ return $ data ;
335+ },
336+ 10 ,
337+ 2
338+ );
339+ do_action ( 'themeisle_internal_page ' , JAXON_PRODUCT_SLUG , $ screen ->id );
355340 }
356341}
0 commit comments