Skip to content

Commit

Permalink
feat: nps plan category & license status
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Feb 15, 2024
1 parent 114c75c commit 4782d62
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
42 changes: 37 additions & 5 deletions includes/admin/feedzy-rss-feeds-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,37 @@ public function api_license_status() {
return $data;
}

/**
* Get the plan category for the product plan ID.
*
* @param object $license_data The license data.
* @return int
*/
private static function plan_category( $license_data ) {

if ( ! isset( $license_data->plan ) || ! is_numeric( $license_data->plan ) ) {
return 0; // Free
}

$plan = (int) $license_data->plan;
$current_category = 0;

$categories = array(
'1' => array(1, 4, 9), // Personal
'2' => array(2, 5, 8), // Business/Developer
'3' => array(3, 6, 7, 10), // Agency
);

foreach ( $categories as $category => $plans ) {
if ( in_array( $plan, $plans, true ) ) {
$current_category = (int) $category;
break;
}
}

return $current_category;
}

/**
* Get the data used for the survey.
*
Expand All @@ -1623,18 +1654,18 @@ public function api_license_status() {
public function get_survery_metadata() {

$user_id = 'feedzy_';
$license = get_option( 'feedzy_rss_feeds_pro_license_data', array() );
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );

if ( ! empty( $license->key ) ) {
$user_id .= $license->key;
if ( ! empty( $license_data->key ) ) {
$user_id .= $license_data->key;
} else {
$user_id .= preg_replace( '/[^\w\d]*/', '', get_site_url() ); // Use a normalized version of the site URL as a user ID for free users.
}

$integration_status = $this->api_license_status();

$days_since_install = round( ( time() - get_option( 'feedzy_rss_feeds_install', 0 ) ) / DAY_IN_SECONDS );
$install_category = null;
$install_category = 0;
if ( 0 === $days_since_install || 1 === $days_since_install ) {
$install_category = 0;
} elseif ( 1 < $days_since_install && 8 > $days_since_install ) {
Expand All @@ -1656,8 +1687,9 @@ public function get_survery_metadata() {
'amazon' => $integration_status['amazonStatus'] ? 'valid' : 'invalid',
'spinnerchief' => $integration_status['spinnerChiefStatus'] ? 'valid' : 'invalid',
'wordai' => $integration_status['wordaiStatus'] ? 'valid' : 'invalid',
'plan' => apply_filters( 'product_feedzy_license_plan', 0 ),
'plan' => $this->plan_category( $license_data ),
'days_since_install' => $install_category,
'license_status' => ! empty( $license_data->license ) ? $license_data->license : 'invalid',
),
);
}
Expand Down
3 changes: 1 addition & 2 deletions js/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ window.addEventListener('load', function () {
window?.formbricks?.init?.({
environmentId: "clskgehf78eu5podwdrnzciti",
apiHost: "https://app.formbricks.com",
debug: true,
...(window?.feedzySurveyData ?? {})
...(window?.feedzySurveyData ?? {}),
});
});

0 comments on commit 4782d62

Please sign in to comment.