@@ -128,6 +128,10 @@ public function enqueue_styles_admin() {
128
128
wp_enqueue_script ( $ this ->plugin_name . '_telemetry ' , FEEDZY_ABSURL . 'js/telemetry.js ' , array (), $ this ->version , true );
129
129
}
130
130
131
+ if ( 'feedzy_imports ' === $ screen ->post_type && 'edit ' === $ screen ->base ) {
132
+ $ this ->register_survey ();
133
+ }
134
+
131
135
if ( 'feedzy_categories ' === $ screen ->post_type ) {
132
136
wp_enqueue_script (
133
137
$ this ->plugin_name . '_categories ' ,
@@ -152,6 +156,8 @@ public function enqueue_styles_admin() {
152
156
),
153
157
)
154
158
);
159
+
160
+ $ this ->register_survey ();
155
161
}
156
162
157
163
if ( 'feedzy_page_feedzy-settings ' === $ screen ->base ) {
@@ -171,6 +177,8 @@ public function enqueue_styles_admin() {
171
177
),
172
178
)
173
179
);
180
+
181
+ $ this ->register_survey ();
174
182
}
175
183
176
184
$ upsell_screens = array ( 'feedzy-rss_page_feedzy-settings ' , 'feedzy-rss_page_feedzy-admin-menu-pro-upsell ' );
@@ -195,6 +203,8 @@ public function enqueue_styles_admin() {
195
203
)
196
204
);
197
205
wp_enqueue_style ( 'wp-block-editor ' );
206
+
207
+ $ this ->register_survey ();
198
208
}
199
209
if ( ! defined ( 'TI_CYPRESS_TESTING ' ) && ( 'edit ' !== $ screen ->base && 'feedzy_imports ' === $ screen ->post_type && feedzy_show_import_tour () ) ) {
200
210
wp_enqueue_script ( $ this ->plugin_name . '_on_boarding ' , FEEDZY_ABSURL . 'js/Onboarding/import-onboarding.min.js ' , array ( 'react ' , 'react-dom ' , 'wp-editor ' , 'wp-api ' , 'lodash ' ), $ this ->version , true );
@@ -205,6 +215,9 @@ public function enqueue_styles_admin() {
205
215
}
206
216
207
217
if ( 'feedzy_page_feedzy-support ' === $ screen ->base || ( 'edit ' !== $ screen ->base && 'feedzy_imports ' === $ screen ->post_type ) ) {
218
+
219
+ $ this ->register_survey ();
220
+
208
221
wp_enqueue_script ( $ this ->plugin_name . '_feedback ' , FEEDZY_ABSURL . 'js/FeedBack/feedback.min.js ' , array ( 'react ' , 'react-dom ' , 'wp-editor ' , 'wp-api ' , 'lodash ' ), $ this ->version , true );
209
222
wp_enqueue_style ( 'wp-block-editor ' );
210
223
@@ -1565,10 +1578,13 @@ public function api_license_status() {
1565
1578
'spinnerChiefStatus ' => false ,
1566
1579
'wordaiStatus ' => false ,
1567
1580
'openaiStatus ' => false ,
1581
+ 'amazonStatus ' => false ,
1568
1582
);
1583
+
1569
1584
if ( ! feedzy_is_pro () ) {
1570
1585
return $ data ;
1571
1586
}
1587
+
1572
1588
if ( apply_filters ( 'feedzy_is_license_of_type ' , false , 'agency ' ) ) {
1573
1589
if ( isset ( $ pro_options ['spinnerchief_licence ' ] ) && 'yes ' === $ pro_options ['spinnerchief_licence ' ] ) {
1574
1590
$ data ['spinnerChiefStatus ' ] = true ;
@@ -1577,11 +1593,119 @@ public function api_license_status() {
1577
1593
$ data ['wordaiStatus ' ] = true ;
1578
1594
}
1579
1595
}
1596
+
1580
1597
if ( isset ( $ pro_options ['openai_licence ' ] ) && 'yes ' === $ pro_options ['openai_licence ' ] ) {
1581
1598
if ( apply_filters ( 'feedzy_is_license_of_type ' , false , 'business ' ) || apply_filters ( 'feedzy_is_license_of_type ' , false , 'agency ' ) ) {
1582
1599
$ data ['openaiStatus ' ] = true ;
1583
1600
}
1584
1601
}
1602
+
1603
+ if ( ! empty ( $ pro_options ['amazon_access_key ' ] ) && ! empty ( $ pro_options ['amazon_secret_key ' ] ) ) {
1604
+ $ data ['amazonStatus ' ] = true ;
1605
+ }
1585
1606
return $ data ;
1586
1607
}
1608
+
1609
+ /**
1610
+ * Get the plan category for the product plan ID.
1611
+ *
1612
+ * @param object $license_data The license data.
1613
+ * @return int
1614
+ */
1615
+ private static function plan_category ( $ license_data ) {
1616
+
1617
+ if ( ! isset ( $ license_data ->plan ) || ! is_numeric ( $ license_data ->plan ) ) {
1618
+ return 0 ; // Free
1619
+ }
1620
+
1621
+ $ plan = (int ) $ license_data ->plan ;
1622
+ $ current_category = -1 ;
1623
+
1624
+ $ categories = array (
1625
+ '1 ' => array (1 , 4 , 9 ), // Personal
1626
+ '2 ' => array (2 , 5 , 8 ), // Business/Developer
1627
+ '3 ' => array (3 , 6 , 7 , 10 ), // Agency
1628
+ );
1629
+
1630
+ foreach ( $ categories as $ category => $ plans ) {
1631
+ if ( in_array ( $ plan , $ plans , true ) ) {
1632
+ $ current_category = (int ) $ category ;
1633
+ break ;
1634
+ }
1635
+ }
1636
+
1637
+ return $ current_category ;
1638
+ }
1639
+
1640
+ /**
1641
+ * Get the data used for the survey.
1642
+ *
1643
+ * @return array
1644
+ * @see survey.js
1645
+ */
1646
+ public function get_survery_metadata () {
1647
+
1648
+ $ user_id = 'feedzy_ ' ;
1649
+ $ license_data = get_option ( 'feedzy_rss_feeds_pro_license_data ' , array () );
1650
+
1651
+ if ( ! empty ( $ license_data ->key ) ) {
1652
+ $ user_id .= $ license_data ->key ;
1653
+ } else {
1654
+ $ user_id .= preg_replace ( '/[^\w\d]*/ ' , '' , get_site_url () ); // Use a normalized version of the site URL as a user ID for free users.
1655
+ }
1656
+
1657
+ $ integration_status = $ this ->api_license_status ();
1658
+
1659
+ $ days_since_install = round ( ( time () - get_option ( 'feedzy_rss_feeds_install ' , 0 ) ) / DAY_IN_SECONDS );
1660
+ $ install_category = 0 ;
1661
+ if ( 0 === $ days_since_install || 1 === $ days_since_install ) {
1662
+ $ install_category = 0 ;
1663
+ } elseif ( 1 < $ days_since_install && 8 > $ days_since_install ) {
1664
+ $ install_category = 7 ;
1665
+ } elseif ( 8 <= $ days_since_install && 31 > $ days_since_install ) {
1666
+ $ install_category = 30 ;
1667
+ } elseif ( 30 < $ days_since_install && 90 > $ days_since_install ) {
1668
+ $ install_category = 90 ;
1669
+ } elseif ( 90 <= $ days_since_install ) {
1670
+ $ install_category = 91 ;
1671
+ }
1672
+
1673
+ return array (
1674
+ 'userId ' => $ user_id ,
1675
+ 'attributes ' => array (
1676
+ 'free_version ' => $ this ->version ,
1677
+ 'pro_version ' => defined ( 'FEEDZY_PRO_VERSION ' ) ? FEEDZY_PRO_VERSION : '' ,
1678
+ 'openai ' => $ integration_status ['openaiStatus ' ] ? 'valid ' : 'invalid ' ,
1679
+ 'amazon ' => $ integration_status ['amazonStatus ' ] ? 'valid ' : 'invalid ' ,
1680
+ 'spinnerchief ' => $ integration_status ['spinnerChiefStatus ' ] ? 'valid ' : 'invalid ' ,
1681
+ 'wordai ' => $ integration_status ['wordaiStatus ' ] ? 'valid ' : 'invalid ' ,
1682
+ 'plan ' => $ this ->plan_category ( $ license_data ),
1683
+ 'days_since_install ' => $ install_category ,
1684
+ 'license_status ' => ! empty ( $ license_data ->license ) ? $ license_data ->license : 'invalid ' ,
1685
+ ),
1686
+ );
1687
+ }
1688
+
1689
+ /**
1690
+ * Register the survey script.
1691
+ *
1692
+ * It does register if we are in CI environment.
1693
+ *
1694
+ * @return void
1695
+ */
1696
+ public function register_survey () {
1697
+
1698
+ if ( defined ( 'CYPRESS_TESTING ' ) ) {
1699
+ return ;
1700
+ }
1701
+
1702
+ $ survey_handler = apply_filters ( 'themeisle_sdk_dependency_script_handler ' , 'survey ' );
1703
+ if ( empty ( $ survey_handler ) ) {
1704
+ return ;
1705
+ }
1706
+
1707
+ do_action ( 'themeisle_sdk_dependency_enqueue_script ' , 'survey ' );
1708
+ wp_enqueue_script ( $ this ->plugin_name . '_survey ' , FEEDZY_ABSURL . 'js/survey.js ' , array ( $ survey_handler ), $ this ->version , true );
1709
+ wp_localize_script ( $ this ->plugin_name . '_survey ' , 'feedzySurveyData ' , $ this ->get_survery_metadata () );
1710
+ }
1587
1711
}
0 commit comments