diff --git a/src/android/com/outsystems/firebase/analytics/FirebaseAnalyticsPlugin.java b/src/android/com/outsystems/firebase/analytics/FirebaseAnalyticsPlugin.java index 905e037..0b232ea 100644 --- a/src/android/com/outsystems/firebase/analytics/FirebaseAnalyticsPlugin.java +++ b/src/android/com/outsystems/firebase/analytics/FirebaseAnalyticsPlugin.java @@ -19,9 +19,7 @@ import java.util.Iterator; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; public class FirebaseAnalyticsPlugin extends ReflectiveCordovaPlugin { @@ -110,42 +108,38 @@ private void logECommerceEvent(JSONObject params, CallbackContext callbackContex @CordovaMethod private void setConsent(String consentSetting, CallbackContext callbackContext) throws JSONException { - JSONArray consentSettings; try { - consentSettings = new JSONArray(consentSetting); - } catch (JSONException e) { - callbackContext.error(e.getMessage()); - return; - } - - Map consentMap = new HashMap<>(); - Set seenTypes = new HashSet<>(); - - for (int i = 0; i < consentSettings.length(); i++) { - JSONObject consentItem = consentSettings.getJSONObject(i); - int typeValue = consentItem.getInt("Type"); - int statusValue = consentItem.getInt("Status"); - - FirebaseAnalytics.ConsentType consentType = getConsentType(typeValue); - FirebaseAnalytics.ConsentStatus consentStatus = getConsentStatus(statusValue); - - if (consentType != null && consentStatus != null) { - if (seenTypes.contains(consentType)) { - callbackContext.error("Error: Duplicate consent types found in the input array."); - return; + JSONArray consentSettings = new JSONArray(consentSetting); + + Map consentMap = new HashMap<>(); + + for (int i = 0; i < consentSettings.length(); i++) { + JSONObject consentItem = consentSettings.getJSONObject(i); + int typeValue = consentItem.getInt("Type"); + int statusValue = consentItem.getInt("Status"); + + FirebaseAnalytics.ConsentType consentType = getConsentType(typeValue); + FirebaseAnalytics.ConsentStatus consentStatus = getConsentStatus(statusValue); + + if (consentType != null && consentStatus != null) { + if (consentMap.containsKey(consentType)) { + callbackContext.error("Error: Duplicate consent types found in the input array."); + return; + } + consentMap.put(consentType, consentStatus); + } else { + Log.w(TAG, "Invalid consent type or status for item: " + consentItem); } - seenTypes.add(consentType); - consentMap.put(consentType, consentStatus); - } else { - Log.w(TAG, "Invalid consent type or status for item: " + consentItem); } - } - if (!consentMap.isEmpty()) { - this.firebaseAnalytics.setConsent(consentMap); - callbackContext.success(); - } else { - callbackContext.error("Error: No valid consent types provided."); + if (!consentMap.isEmpty()) { + this.firebaseAnalytics.setConsent(consentMap); + callbackContext.success(); + } else { + callbackContext.error("Error: No valid consent types provided."); + } + } catch (JSONException e) { + callbackContext.error(e.getMessage()); } } diff --git a/src/ios/FirebaseAnalyticsPlugin.m b/src/ios/FirebaseAnalyticsPlugin.m index de175f8..fe6776f 100644 --- a/src/ios/FirebaseAnalyticsPlugin.m +++ b/src/ios/FirebaseAnalyticsPlugin.m @@ -156,9 +156,7 @@ - (void)setConsent:(CDVInvokedUrlCommand*)command pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description]; } else { - NSMutableSet *seenTypes = [NSMutableSet set]; NSMutableDictionary *firebaseConsentDict = [NSMutableDictionary dictionary]; - BOOL duplicatesFound = NO; for (NSDictionary *item in array) { NSNumber *type = item[@"Type"]; @@ -167,11 +165,11 @@ - (void)setConsent:(CDVInvokedUrlCommand*)command FIRConsentStatus consentStatus = [self consentStatusFromNumber:status]; if (consentType && consentStatus) { - if ([seenTypes containsObject:consentType]) { - duplicatesFound = YES; + if (firebaseConsentDict[consentType]) { + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR + messageAsString:@"Error: Duplicate consent types found in the input array."]; break; } else { - [seenTypes addObject:consentType]; firebaseConsentDict[consentType] = consentStatus; } } else { @@ -179,10 +177,7 @@ - (void)setConsent:(CDVInvokedUrlCommand*)command } } - if (duplicatesFound) { - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR - messageAsString:@"Error: Duplicate consent types found in the input array."]; - } else { + if (pluginResult == nil) { if (firebaseConsentDict.count > 0) { [FIRAnalytics setConsent:firebaseConsentDict]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];