Skip to content

Commit

Permalink
Merge pull request #2010 from Codeinwp/fix/issue-124
Browse files Browse the repository at this point in the history
Add NPS Survey
  • Loading branch information
HardeepAsrani authored Dec 18, 2023
2 parents 8cbf1fb + 69bdd0f commit a256849
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions inc/plugins/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public function enqueue_options_assets() {
'docsLink' => Pro::get_docs_url(),
'showFeedbackNotice' => $this->should_show_feedback_notice(),
'deal' => ! Pro::is_pro_installed() ? $offer->get_localized_data() : array(),
'days_since_install' => round( ( time() - get_option( 'otter_blocks_install', 0 ) ) / DAY_IN_SECONDS ),
'rootUrl' => get_site_url(),
)
)
);
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"lasttranslator": "Themeisle Translate Team <[email protected]>"
},
"dependencies": {
"@formbricks/js": "^1.2.7",
"@wordpress/icons": "^9.38.0",
"array-move": "^3.0.1",
"classnames": "^2.3.1",
Expand Down
1 change: 1 addition & 0 deletions plugins/otter-pro/inc/server/class-dashboard-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function apply_dashboard_data( $data ) {
'key' => apply_filters( 'product_otter_license_key', 'free' ),
'valid' => apply_filters( 'product_otter_license_status', false ),
'expiration' => License::get_license_expiration_date(),
'type' => License::get_license_type(),
),
'hasNevePro' => defined( 'NEVE_PRO_VERSION' ),
'storeURL' => 'https://store.themeisle.com/',
Expand Down
36 changes: 34 additions & 2 deletions src/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/* eslint-disable camelcase */
/**
* External dependencies.
*/
import formbricks from '@formbricks/js';

/**
* WordPress dependencies.
*/
Expand All @@ -24,11 +30,37 @@ if ( undefined === window.otterUtils ) {

window.otterUtils.useSettings = useSettings;

function getInitialStateFromURLQuery() {
const getInitialStateFromURLQuery = () => {
const hash = window.location.hash.slice( 1 ); // Remove the '#' at the start
return hash;
}
};

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 ) {
formbricks.init({
environmentId: 'clp9hqm8c1osfdl2ixwd0k0iz',
apiHost: 'https://app.formbricks.com',
userId: 'otter_' + ( undefined !== window.otterObj?.license?.key ? window.otterObj.license.key : window.otterObj.rootUrl.replace( /[^\w\d]*/g, '' ) ),
attributes: {
plan: undefined !== window.otterObj?.license?.type ? window.otterObj.license.type : 'free',
days_since_install: convertToCategory( window.otterObj.days_since_install )
}
});
}

const App = () => {
const [ currentTab, setTab ] = useState( getInitialStateFromURLQuery() );
Expand Down

0 comments on commit a256849

Please sign in to comment.