@@ -288,15 +288,41 @@ class CloudinaryFile {
288288 // 2. If we got an object we have to check if URLSearchParams is available, and only then use it
289289 // Beause we want to throw a meaningful Error in case it's not - we can wrap the below code in a try catch clause
290290 // 3. If it already was a string then we can skip the parsing but still we need to assign it to `queryParamsString`
291- const queryParams = new URLSearchParams ( this . urlConfig . queryParams as Record < string , string > ) ;
292-
293- // urlConfig.analytics is true by default, has to be explicitly set to false to overwrite
294- // Don't add analytics when publicId includes a '?' to not risk changing existing query params
295- if ( this . urlConfig . analytics !== false && ! ( publicID . includes ( '?' ) ) ) {
296- queryParams . set ( "_a" , getSDKAnalyticsSignature ( trackedAnalytics ) ) ;
297- }
291+ //
292+
293+ const shouldAddAnalytics = this . urlConfig . analytics !== false && ! ( publicID . includes ( '?' ) ) ;
294+
295+ if ( typeof ( this . urlConfig . queryParams ) === 'object' ) { //#1
296+
297+ try { //#2
298+ const queryParams = new URLSearchParams ( this . urlConfig . queryParams as Record < string , string > ) ;
299+ // urlConfig.analytics is true by default, has to be explicitly set to false to overwrite
300+ // Don't add analytics when publicId includes a '?' to not risk changing existing query params
301+
302+ if ( shouldAddAnalytics ) {
303+ queryParams . set ( "_a" , getSDKAnalyticsSignature ( trackedAnalytics ) ) ;
304+ }
305+
306+ const queryParamsString = queryParams . toString ( ) ;
307+
308+ } catch ( ) {
309+ //TODO: improve error message, consult with docs team.
310+ throw "Error: URLSearchParams is not available." ; //#2
311+ }
312+ }
313+
314+ //if (typeof(this.urlConfig.queryParams) === 'string'){ //#3
315+ else { //#3
316+ //assign to queryParamsString
317+ let queryParamsString = this . urlConfig . queryParams || '' ;
318+
319+ if ( shouldAddAnalytics ) {
320+ queryParams . set ( "_a" , getSDKAnalyticsSignature ( trackedAnalytics ) ) ;
321+ queryParamsString += ( queryParamsString . length > 0 ? "&" :"" ) + "_a=" + getSDKAnalyticsSignature ( trackedAnalytics ) ;
322+ }
323+
324+ }
298325
299- const queryParamsString = queryParams . toString ( ) ;
300326 if ( queryParamsString ) {
301327 return `${ safeURL } ?${ queryParamsString } ` ;
302328 } else {
0 commit comments