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..322e6b5708 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,43 @@ public function render_neve_header() { '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', + '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 + ); + } }