diff --git a/includes/Compatibility/Safe_Mode.php b/includes/Compatibility/Safe_Mode.php index f7bbc368d..e005be888 100644 --- a/includes/Compatibility/Safe_Mode.php +++ b/includes/Compatibility/Safe_Mode.php @@ -2,6 +2,7 @@ namespace NewfoldLabs\WP\Module\Onboarding\Compatibility; +use NewfoldLabs\WP\Module\Onboarding\Data\Data; use NewfoldLabs\WP\Module\Onboarding\Data\Options; use NewfoldLabs\WP\Module\Onboarding\Permissions; use NewfoldLabs\WP\Module\Onboarding\WP_Admin; @@ -242,8 +243,8 @@ public static function handle_redirect() { Status::reset(); // Get the post core update redirect URL. $onboarding_referrer = \get_transient( Options::get_option_name( 'core_update_referrer' ) ); - // Only redirect if th URL exists and the site is in coming soon mode. - if ( $onboarding_referrer && \get_option( Options::get_option_name( 'coming_soon', false ), 'false' ) === 'true' ) { + // Only redirect if the URL exists and the site is in coming soon mode. + if ( $onboarding_referrer && Data::coming_soon() ) { \delete_transient( Options::get_option_name( 'core_update_referrer' ) ); // Ensure that it is a safe Onboarding URL before redirecting. if ( ! preg_match( $valid_onboarding_referrer_regex, $onboarding_referrer ) ) { diff --git a/includes/Data/Brands.php b/includes/Data/Brands.php index 513a5c3f5..51ba228c7 100644 --- a/includes/Data/Brands.php +++ b/includes/Data/Brands.php @@ -92,8 +92,7 @@ public static function get_brands() { ), ), 'config' => array( - 'net_new_signup_date_threshold' => '2023-05-04T00:00:00.000Z', - 'enabled_flows' => array( + 'enabled_flows' => array( 'ecommerce' => true, 'wp-setup' => true, ), @@ -149,8 +148,7 @@ public static function get_brands() { ), ), 'config' => array( - 'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z', - 'enabled_flows' => array( + 'enabled_flows' => array( 'ecommerce' => true, 'wp-setup' => false, ), @@ -207,8 +205,7 @@ public static function get_brands() { ), ), 'config' => array( - 'net_new_signup_date_threshold' => '2022-08-18T15:30:00.000Z', - 'enabled_flows' => array( + 'enabled_flows' => array( 'ecommerce' => false, 'wp-setup' => false, ), @@ -265,12 +262,11 @@ public static function get_brands() { ), ), 'config' => array( - 'net_new_signup_date_threshold' => '2023-05-04T00:00:00.000Z', - 'enabled_flows' => array( + 'enabled_flows' => array( 'ecommerce' => true, 'wp-setup' => true, ), - 'views' => array( + 'views' => array( 'sidebar' => array( 'illustration' => array( 'shown' => false, diff --git a/includes/Data/Data.php b/includes/Data/Data.php index 38e9c7b67..6d2c8fc9a 100644 --- a/includes/Data/Data.php +++ b/includes/Data/Data.php @@ -119,4 +119,26 @@ public static function customer_data() { return array(); } + /** + * Determine whether the site is in coming soon mode. + * + * @return boolean + */ + public static function coming_soon() { + // Check if nfd_coming_soon is set to true. + $coming_soon = \get_option( Options::get_option_name( 'new_coming_soon', false ), null ); + if ( null !== $coming_soon ) { + return 'true' === $coming_soon; + } + + // Check if legacy mm_coming_soon is set to true. + $coming_soon = \get_option( Options::get_option_name( 'old_coming_soon', false ), null ); + if ( null !== $coming_soon ) { + return 'true' === $coming_soon; + } + + // Assume site has been launched if both options do not exist. + return false; + } + } diff --git a/includes/Data/Options.php b/includes/Data/Options.php index e073a6ee2..475e7b128 100644 --- a/includes/Data/Options.php +++ b/includes/Data/Options.php @@ -22,12 +22,12 @@ final class Options { 'redirect_param' => 'redirect_param', 'activate' => 'activate', 'activate_param' => 'activate_param', - 'coming_soon' => 'nfd_coming_soon', + 'new_coming_soon' => 'nfd_coming_soon', + 'old_coming_soon' => 'mm_coming_soon', 'brand' => 'mm_brand', 'close_comments_for_old_posts' => 'close_comments_for_old_posts', 'close_comments_days_old' => 'close_comments_days_old', 'comments_per_page' => 'comments_per_page', - 'install_date' => 'mm_install_date', 'start_date' => 'start_date', 'allow_major_auto_core_updates' => 'allow_major_auto_core_updates', 'allow_minor_auto_core_updates' => 'allow_minor_auto_core_updates', @@ -58,7 +58,7 @@ final class Options { 'close_comments_for_old_posts' => 1, 'close_comments_days_old' => 28, 'comments_per_page' => 20, - 'coming_soon' => 'true', + 'new_coming_soon' => 'true', 'allow_major_auto_core_updates' => 'true', 'allow_minor_auto_core_updates' => 'true', 'auto_update_plugin' => 'true', diff --git a/includes/LoginRedirect.php b/includes/LoginRedirect.php index ff7c8c2d0..945a407eb 100644 --- a/includes/LoginRedirect.php +++ b/includes/LoginRedirect.php @@ -1,7 +1,7 @@ diff( $install_date ); - $interval_in_hours = ( $interval->days * 24 ) + $interval->h; - if ( $interval_in_hours >= 72 ) { - return $original_redirect; - } - // Finally, if we made it this far, then set the redirect URL to point to onboarding return \admin_url( '/index.php?page=nfd-onboarding' ); } diff --git a/includes/ModuleController.php b/includes/ModuleController.php index 7c26db7eb..4656c3f4d 100644 --- a/includes/ModuleController.php +++ b/includes/ModuleController.php @@ -84,79 +84,25 @@ public static function verify_onboarding_criteria() { switch ( $flow ) { case 'ecommerce': - if ( self::is_new_commerce_signup( $customer_data ) ) { + if ( self::is_commerce_signup( $customer_data ) ) { return true; } break; case 'wp-setup': - if ( self::is_net_new_signup( $customer_data ) ) { - return true; - } - break; + return true; } } return false; } - /** - * Get signup date of the install. - * - * @param array $customer_data The customer data to be checked for signup date. - * @return string|boolean - */ - public static function get_signup_date( $customer_data ) { - // Get the signup_date from customer data. - if ( isset( $customer_data['signup_date'] ) ) { - return gmdate( 'Y-m-d H:i:s', strtotime( $customer_data['signup_date'] ) ); - } - - // Get the signup_date from the container's install_date. - if ( ! empty( container()->plugin()->install_date ) ) { - return gmdate( 'Y-m-d H:i:s', container()->plugin()->install_date ); - } - - // Get the signup_date from the mm_install_date option. - $install_date = \get_option( Options::get_option_name( 'install_date', false ), false ); - if ( false !== $install_date ) { - return gmdate( 'Y-m-d H:i:s', strtotime( $install_date ) ); - } - - return false; - } - - /** - * Determines if the signup data is after the brand's net_new_signup_date_threshold. - * - * @param array $customer_data The brand customer data. - * @return boolean - */ - public static function is_net_new_signup( $customer_data ) { - $current_brand = Data::current_brand(); - if ( ! isset( $current_brand['config']['net_new_signup_date_threshold'] ) ) { - return false; - } - $net_new_signup_date_threshold = gmdate( 'Y-m-d H:i:s', strtotime( $current_brand['config']['net_new_signup_date_threshold'] ) ); - - // Get the actual signup date of the install. - $signup_date = self::get_signup_date( $customer_data ); - - // As a safety measure, return false if a signup date cannot be determined. - if ( false === $signup_date ) { - return false; - } - - // Determine whether the commerce install is a net new signup. - return $signup_date >= $net_new_signup_date_threshold; - } - /** * Determine if the install is a new commerce signup * * @param array $customer_data The site's customer data. * @return boolean */ - public static function is_new_commerce_signup( $customer_data ) { + public static function is_commerce_signup( $customer_data ) { // Determine if the flow=ecommerce param is set. if ( isset( $_GET['flow'] ) && 'ecommerce' === \sanitize_text_field( $_GET['flow'] ) ) { return true; @@ -174,12 +120,6 @@ public static function is_new_commerce_signup( $customer_data ) { return false; } - // Determine whether the commerce install is a net new signup. - $is_net_new_signup = self::is_net_new_signup( $customer_data ); - if ( ! $is_net_new_signup ) { - return false; - } - return true; } } diff --git a/src/OnboardingSPA/utils/analytics/index.js b/src/OnboardingSPA/utils/analytics/index.js index 58fd001d8..20964e6cf 100644 --- a/src/OnboardingSPA/utils/analytics/index.js +++ b/src/OnboardingSPA/utils/analytics/index.js @@ -1,11 +1,18 @@ -import { HiiveAnalytics, HiiveEvent } from '@newfold-labs/js-utility-ui-analytics'; +import { + HiiveAnalytics, + HiiveEvent, +} from '@newfold-labs/js-utility-ui-analytics'; import { HIIVE_ANALYTICS_CATEGORY } from '../../../constants'; export const trackHiiveEvent = ( action, value ) => { - const hiiveEvent = new HiiveEvent( HIIVE_ANALYTICS_CATEGORY, action, { + const data = { value, timestamp: Date.now(), - } ); + }; + if ( 'pageview' === action ) { + data.page = value; + } + const hiiveEvent = new HiiveEvent( HIIVE_ANALYTICS_CATEGORY, action, data ); HiiveAnalytics.track( hiiveEvent ); };