forked from chemerisuk/cordova-plugin-firebase-analytics
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from OutSystems/development
RMET-3677 & RMET-3678 - Add setConsent functionality
- Loading branch information
Showing
9 changed files
with
213 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/android/com/outsystems/firebase/analytics/model/OSFANLConsentModels.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.outsystems.firebase.analytics.model | ||
|
||
import com.google.firebase.analytics.FirebaseAnalytics | ||
|
||
enum class ConsentType(val value: Int, val consentType: FirebaseAnalytics.ConsentType) { | ||
AD_PERSONALIZATION(1, FirebaseAnalytics.ConsentType.AD_PERSONALIZATION), | ||
AD_STORAGE(2, FirebaseAnalytics.ConsentType.AD_STORAGE), | ||
AD_USER_DATA(3, FirebaseAnalytics.ConsentType.AD_USER_DATA), | ||
ANALYTICS_STORAGE(4, FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE); | ||
|
||
companion object { | ||
private val map = entries.associateBy(ConsentType::value) | ||
|
||
@JvmStatic | ||
fun fromInt(value: Int): FirebaseAnalytics.ConsentType? = map[value]?.consentType | ||
} | ||
} | ||
|
||
enum class ConsentStatus(val value: Int, val consentStatus: FirebaseAnalytics.ConsentStatus) { | ||
GRANTED(1, FirebaseAnalytics.ConsentStatus.GRANTED), | ||
DENIED(2, FirebaseAnalytics.ConsentStatus.DENIED); | ||
|
||
companion object { | ||
private val map = entries.associateBy(ConsentStatus::value) | ||
|
||
@JvmStatic | ||
fun fromInt(value: Int): FirebaseAnalytics.ConsentStatus? = map[value]?.consentStatus | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import FirebaseAnalytics | ||
import FirebaseCore | ||
|
||
@objc enum ConsentTypeRawValue: Int, CustomStringConvertible, CaseIterable { | ||
case adPersonalization = 1 | ||
case adStorage = 2 | ||
case adUserData = 3 | ||
case analyticsStorage = 4 | ||
|
||
var description: String { | ||
return switch self { | ||
case .adPersonalization: "ad_personalization" | ||
case .adStorage: "ad_storage" | ||
case .adUserData: "ad_user_data" | ||
case .analyticsStorage: "analytics_storage" | ||
} | ||
} | ||
|
||
static func allOptionsString() -> String { | ||
let capitalizedDescriptions = allCases.map { $0.description.uppercased() } | ||
|
||
if capitalizedDescriptions.count > 1 { | ||
let lastOption = capitalizedDescriptions.last! | ||
let allButLast = capitalizedDescriptions.dropLast().joined(separator: ", ") | ||
return "\(allButLast), or \(lastOption)" | ||
} else { | ||
return capitalizedDescriptions.first ?? "" | ||
} | ||
} | ||
} | ||
|
||
@objc enum ConsentStatusRawValue: Int, CustomStringConvertible, CaseIterable { | ||
case granted = 1 | ||
case denied = 2 | ||
|
||
var description: String { | ||
return switch self { | ||
case .granted: "granted" | ||
case .denied: "denied" | ||
} | ||
} | ||
|
||
static func allOptionsString() -> String { | ||
let capitalizedDescriptions = allCases.map { $0.description.uppercased() } | ||
|
||
if capitalizedDescriptions.count > 1 { | ||
let lastOption = capitalizedDescriptions.last! | ||
let allButLast = capitalizedDescriptions.dropLast().joined(separator: ", ") | ||
return "\(allButLast), or \(lastOption)" | ||
} else { | ||
return capitalizedDescriptions.first ?? "" | ||
} | ||
} | ||
} | ||
|
||
@objc class OSFANLConsentHelper: NSObject { | ||
@objc static func createConsentModel(_ commandArguments: NSArray) throws -> [ConsentType: ConsentStatus] { | ||
guard let jsonString = commandArguments[0] as? String, | ||
let jsonData = jsonString.data(using: .utf8), | ||
let array = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [[String: Any]] else { | ||
throw OSFANLError.invalidType("ConsentSettings", type: "JSON") | ||
} | ||
|
||
var firebaseConsentDict: [ConsentType: ConsentStatus] = [:] | ||
|
||
for item in array { | ||
guard let typeRawValue = item["Type"] as? Int, | ||
let statusRawValue = item["Status"] as? Int else { | ||
throw OSFANLError.invalidType("JSON passed Consent Type or Status", type: "Integer") | ||
} | ||
|
||
guard let consentTypeRawValue = ConsentTypeRawValue(rawValue: typeRawValue) else { | ||
throw OSFANLError.invalidType("Consent Type", type: ConsentTypeRawValue.allOptionsString()) | ||
} | ||
|
||
guard let consentStatusRawValue = ConsentStatusRawValue(rawValue: statusRawValue) else { | ||
throw OSFANLError.invalidType("Consent Status", type: ConsentStatusRawValue.allOptionsString()) | ||
} | ||
|
||
let consentType = ConsentType(rawValue: String(describing: consentTypeRawValue)) | ||
let consentStatus = ConsentStatus(rawValue: String(describing: consentStatusRawValue)) | ||
|
||
if firebaseConsentDict.keys.contains(consentType) { | ||
throw OSFANLError.duplicateItemsIn(parameter: "ConsentSettings") | ||
} else { | ||
firebaseConsentDict[consentType] = consentStatus | ||
} | ||
} | ||
|
||
if firebaseConsentDict.isEmpty { | ||
throw OSFANLError.missing("ConsentSettings") | ||
} else { | ||
return firebaseConsentDict | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters