From 0875c1313bc96c27bcf6b05f5a8d2c1d39cb3a2e Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Wed, 12 Feb 2025 16:53:21 +0200 Subject: [PATCH 1/2] refactor: load survey via internal pages hook --- assets/apps/dashboard/src/dashboard.js | 1 - assets/apps/dashboard/src/utils/survey.js | 44 ----------------- inc/admin/dashboard/main.php | 60 +++++++++++++++++++++-- 3 files changed, 56 insertions(+), 49 deletions(-) delete mode 100644 assets/apps/dashboard/src/utils/survey.js diff --git a/assets/apps/dashboard/src/dashboard.js b/assets/apps/dashboard/src/dashboard.js index 2eb6e41c34..8e27384b68 100644 --- a/assets/apps/dashboard/src/dashboard.js +++ b/assets/apps/dashboard/src/dashboard.js @@ -12,7 +12,6 @@ import selectors from './store/selectors'; import { NEVE_STORE } from './utils/constants'; import './utils/module-observer'; -import './utils/survey'; maybeAddPolyFills(); diff --git a/assets/apps/dashboard/src/utils/survey.js b/assets/apps/dashboard/src/utils/survey.js deleted file mode 100644 index aaa6fa04ac..0000000000 --- a/assets/apps/dashboard/src/utils/survey.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Take the number of days since install and convert it to a category for NPS user profile. - * - * @param {number} number - Number to convert. - * @param {number} scale - Scale to use. - * @return {number} - Converted number. - */ -const convertToCategory = (number, scale = 1) => { - const normalizedNumber = Math.round(number / scale); - if (0 === normalizedNumber || 1 === normalizedNumber) { - return 0; - } else if (1 < normalizedNumber && 8 > normalizedNumber) { - return 7; - } else if (8 <= normalizedNumber && 31 > normalizedNumber) { - return 30; - } else if (30 < normalizedNumber && 90 > normalizedNumber) { - return 90; - } else if (90 > normalizedNumber) { - return 91; - } -}; - -if ('undefined' !== typeof window && 'undefined' !== typeof window.neveDash) { - window.addEventListener('themeisle:survey:loaded', function () { - window?.tsdk_formbricks?.init?.({ - environmentId: 'clr0ply35522h8up0bay2de4y', - apiHost: 'https://app.formbricks.com', - userId: - 'neve_' + - (window.neveDash?.license?.key ?? - window.neveDash?.rootUrl?.replace(/[^\w\d]*/g, '')), - attributes: { - plan: window.neveDash?.pro ? window.neveDash?.license?.tier : 0, - days_since_install: convertToCategory( - window.neveDash.daysSinceInstall - ), - language: window.neveDash.lang, - license_status: window.neveDash?.license?.valid ?? 'invalid', - free_version: window.neveDash?.version, - pro_version: window.neveDash?.proPluginVersion, - }, - }); - }); -} diff --git a/inc/admin/dashboard/main.php b/inc/admin/dashboard/main.php index 88027a5855..ecf8c28a24 100755 --- a/inc/admin/dashboard/main.php +++ b/inc/admin/dashboard/main.php @@ -270,19 +270,22 @@ public function enqueue() { $build_path = get_template_directory_uri() . '/assets/apps/dashboard/build/'; $dependencies = ( include get_template_directory() . '/assets/apps/dashboard/build/dashboard.asset.php' ); + $dash_data = apply_filters( 'neve_dashboard_page_data', $this->get_localization() ); + + $this->register_survey( $dash_data ); wp_register_style( 'neve-dash-style', $build_path . 'style-dashboard.css', [ 'wp-components', 'neve-components' ], $dependencies['version'] ); wp_style_add_data( 'neve-dash-style', 'rtl', 'replace' ); wp_enqueue_style( 'neve-dash-style' ); wp_register_script( 'neve-dash-script', $build_path . 'dashboard.js', array_merge( $dependencies['dependencies'], [ 'updates' ] ), $dependencies['version'], true ); - wp_localize_script( 'neve-dash-script', 'neveDash', apply_filters( 'neve_dashboard_page_data', $this->get_localization() ) ); + wp_localize_script( 'neve-dash-script', 'neveDash', $dash_data ); wp_enqueue_script( 'neve-dash-script' ); if ( function_exists( 'wp_set_script_translations' ) ) { wp_set_script_translations( 'neve-dash-script', 'neve' ); } - do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' ); + do_action( 'themeisle_internal_page', 'neve', 'dashboard' ); } /** @@ -361,8 +364,6 @@ private function get_localization() { 'canActivatePlugins' => current_user_can( 'activate_plugins' ), 'deal' => $offer->get_localized_data(), 'rootUrl' => get_site_url(), - 'daysSinceInstall' => round( ( time() - get_option( 'neve_install', 0 ) ) / DAY_IN_SECONDS ), - 'proPluginVersion' => defined( 'NEVE_PRO_VERSION' ) ? NEVE_PRO_VERSION : '', ]; if ( defined( 'NEVE_PRO_PATH' ) ) { @@ -1084,4 +1085,55 @@ public function render_neve_header() { $install_days_number ) { + $install_category = 7; + } elseif ( 8 <= $install_days_number && 31 > $install_days_number ) { + $install_category = 30; + } elseif ( 30 < $install_days_number && 90 > $install_days_number ) { + $install_category = 90; + } elseif ( 90 <= $install_days_number ) { + $install_category = 91; + } + + $data = array( + 'environmentId' => 'clr0ply35522h8up0bay2de4y', + 'attributes' => array( + 'plan' => isset( $dash_data['license'], $dash_data['license']['tier'] ) ? $dash_data['license']['tier'] : 0, + 'license_status' => isset( $dash_data['license'], $dash_data['license']['valid'] ) ? $dash_data['license']['valid'] : 'invalid', + 'days_since_install' => $install_category, + 'install_days_number' => $install_days_number, + 'free_version' => $dash_data['version'], + ), + ); + + if ( isset( $dash_data['license'], $dash_data['license']['key'] ) ) { + $data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', $dash_data['license']['key'] ); + } + + if ( defined( 'NEVE_PRO_VERSION' ) ) { + $data['attributes']['pro_version'] = NEVE_PRO_VERSION; + } + + return $data; + }, + 10, + 2 + ); + } } From 898c1aa7b56ad5f3ee91564bc6d0c9bfa290a548 Mon Sep 17 00:00:00 2001 From: "Soare Robert Daniel (Mac 2023)" Date: Tue, 18 Feb 2025 12:00:33 +0200 Subject: [PATCH 2/2] refactor: remove install category for survey --- inc/admin/dashboard/main.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/inc/admin/dashboard/main.php b/inc/admin/dashboard/main.php index ecf8c28a24..322e6b5708 100755 --- a/inc/admin/dashboard/main.php +++ b/inc/admin/dashboard/main.php @@ -1097,26 +1097,14 @@ public function register_survey( $dash_data ) { add_filter( 'themeisle-sdk/survey/neve', function( $data, $page_slug ) use ( $dash_data ) { - - $install_category = 0; - $install_days_number = intval( ( time() - get_option( 'neve_install', time() ) ) / DAY_IN_SECONDS ); - if ( 1 < $install_days_number && 8 > $install_days_number ) { - $install_category = 7; - } elseif ( 8 <= $install_days_number && 31 > $install_days_number ) { - $install_category = 30; - } elseif ( 30 < $install_days_number && 90 > $install_days_number ) { - $install_category = 90; - } elseif ( 90 <= $install_days_number ) { - $install_category = 91; - } + $install_days_number = intval( ( time() - get_option( 'neve_install', time() ) ) / DAY_IN_SECONDS ); $data = array( 'environmentId' => 'clr0ply35522h8up0bay2de4y', 'attributes' => array( 'plan' => isset( $dash_data['license'], $dash_data['license']['tier'] ) ? $dash_data['license']['tier'] : 0, 'license_status' => isset( $dash_data['license'], $dash_data['license']['valid'] ) ? $dash_data['license']['valid'] : 'invalid', - 'days_since_install' => $install_category, 'install_days_number' => $install_days_number, 'free_version' => $dash_data['version'], ),