@@ -145,17 +145,19 @@ public function load_survey( $handler, $data = array() ) {
145145 true
146146 );
147147
148- $ data = array_replace_recursive ( $ this ->get_survey_common_data (), $ data );
148+ $ data = array_replace_recursive ( $ this ->get_survey_common_data ( $ data ), $ data );
149149
150150 wp_localize_script ( $ handler , 'tsdk_survey_data ' , $ data );
151151 }
152152
153153 /**
154154 * Get the common data in the Formbrick survey format.
155155 *
156+ * @param array $reference_data Reference data to extrapolate common properties.
157+ *
156158 * @return array
157159 */
158- public function get_survey_common_data () {
160+ public function get_survey_common_data ( $ reference_data = array () ) {
159161 $ language = apply_filters ( 'themeisle_sdk_current_lang ' , get_user_locale () );
160162 $ available_languages = [
161163 'de_DE ' => 'de ' ,
@@ -168,15 +170,47 @@ public function get_survey_common_data() {
168170 if ( isset ( $ url_parts ['path ' ] ) ) {
169171 $ clean_url .= $ url_parts ['path ' ];
170172 }
171- $ user_id = 'u_ ' . hash ( 'crc32b ' , $ clean_url );
173+ $ user_id = 'u_ ' . hash ( 'crc32b ' , $ clean_url );
172174
173- return [
175+ $ common_data = [
174176 'userId ' => $ user_id ,
175177 'apiHost ' => 'https://app.formbricks.com ' ,
176178 'attributes ' => [
177179 'language ' => $ lang_code ,
178180 ],
179181 ];
182+
183+ if (
184+ isset ( $ reference_data ['attributes ' ], $ reference_data ['attributes ' ]['install_days_number ' ] )
185+ && is_int ( $ reference_data ['attributes ' ]['install_days_number ' ] )
186+ ) {
187+ $ common_data ['attributes ' ]['days_since_install ' ] = $ this ->install_time_category ( $ reference_data ['attributes ' ]['install_days_number ' ] );
188+ }
189+
190+ return $ common_data ;
191+ }
192+
193+ /**
194+ * Compute the install time category.
195+ *
196+ * @param int $install_days_number The number of days passed since installation.
197+ *
198+ * @return int The category.
199+ */
200+ private function install_time_category ( $ install_days_number ) {
201+ $ install_category = 0 ;
202+
203+ if ( 1 < $ install_days_number && 8 > $ install_days_number ) {
204+ $ install_category = 7 ;
205+ } elseif ( 8 <= $ install_days_number && 31 > $ install_days_number ) {
206+ $ install_days_number = 30 ;
207+ } elseif ( 30 < $ install_days_number && 90 > $ install_days_number ) {
208+ $ install_category = 90 ;
209+ } elseif ( 90 <= $ install_days_number ) {
210+ $ install_category = 91 ;
211+ }
212+
213+ return $ install_category ;
180214 }
181215
182216 /**
0 commit comments