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.
RMET-2732 ::: Merge development with latest ecommerce features (#31)
* RMET-2112 FB Analytics - Return user's response to App Tracking Transparency prompt (#22) * fix: add function for requestTrackingAuthorization without promise References: https://outsystemsrd.atlassian.net/browse/RMET-2112 * fix: fixing function structure * test: testing with promise * test: testing with only 1 export * test: use module.exports * refactor: remove commented lines * chore: update changelog References: https://outsystemsrd.atlassian.net/browse/RMET-2112 * refactor: use constant * RMET-2441 :: raise firebase-core version (#24) * feat: raise firebase core version * chore(release): raise to version 5.0.0-OS10 * RMET-2729 ::: JavaScript ::: Log e-commerce events (#26) * feat: added logECommerceEvent javascript function * chore: updates CHANGELOG.md * feat: changed how ecommerce arguments are passed to the native side * feat: Add E-Commerce Events Logging on iOS (#27) Implement the logic required to perform e-commerce event logging. The implementation is similar to the already existing logEvent but without any parameter number constraints. Before logging, and considering that the Firebase Analytics library doesn't return any kind of error in case of any issues with the data, the implementation performs the following steps: #1 - Flat the Key-Value pair information to a JSON Object. This is done on both Event Parameters and Items. #2 - Validate if the event parameters and items are correctly constructed. Both validations are done isolated, with errors being handled and returned in case of occurrence. #3 - Validate the event parameters and items are valid according to the event name. This time, the validation is done altogether, with errors being handled and returned in case of occurrence. #4 - Merge event parameters and items into a single JSON object to be sent to Analytics for logging purposes. The implementation, since it's done using Swift, involves adding the Swift dependency to the `plugin.xml`. References: https://outsystemsrd.atlassian.net/browse/RMET-2731 * fix: Adjust Validations (#29) Remove the default `quantity` value as this is already assured by Firebase. Fix the `item_list_id` and `item_list_name` as only the property set on the event parameters should be removed and not both always. File rename to match the structure name. References: https://outsystemsrd.atlassian.net/browse/RMET-2731 * RMET-2730 ::: Android ::: E-Commerce events (#28) * feat: added ecommerce events first version * fix: added removed hook * fix: fixed bugs with happy paths * feat: added KDoc * fix: removed unecessry verification * chore: updated CHANGELOG * fix: applied changes suggested on the PR comments * fix: added missing bridge file * fix: applied proposed changes * fix: fixed class name (#30) * chore(release): bump version to 5.0.0-OS11 --------- Co-authored-by: Alexandre Jacinto <[email protected]> Co-authored-by: Marta Carlos <[email protected]> Co-authored-by: Ricardo Silva <[email protected]>
- Loading branch information
1 parent
24a3a85
commit 57a993c
Showing
30 changed files
with
1,072 additions
and
10 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
160 changes: 160 additions & 0 deletions
160
src/android/com/outsystems/firebase/analytics/OSFANLManager.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,160 @@ | ||
package com.outsystems.firebase.analytics | ||
|
||
import android.os.Bundle | ||
import com.google.firebase.analytics.FirebaseAnalytics | ||
import com.outsystems.firebase.analytics.model.OSFANLError | ||
import com.outsystems.firebase.analytics.model.OSFANLEventOutputModel | ||
import com.outsystems.firebase.analytics.model.OSFANLInputDataFieldKey | ||
import com.outsystems.firebase.analytics.model.OSFANLInputDataFieldKey.EVENT | ||
import com.outsystems.firebase.analytics.model.OSFANLInputDataFieldKey.ITEMS | ||
import com.outsystems.firebase.analytics.model.OSFANLInputDataFieldKey.SHIPPING | ||
import com.outsystems.firebase.analytics.model.OSFANLInputDataFieldKey.TAX | ||
import com.outsystems.firebase.analytics.model.OSFANLInputDataFieldKey.TRANSACTION_ID | ||
import com.outsystems.firebase.analytics.model.OSFANLInputDataFieldKey.VALUE | ||
import com.outsystems.firebase.analytics.model.getArrayOrEmpty | ||
import com.outsystems.firebase.analytics.model.getStringOrNull | ||
import com.outsystems.firebase.analytics.validator.OSFANLEventItemsValidator | ||
import com.outsystems.firebase.analytics.validator.OSFANLEventParameterValidator | ||
import com.outsystems.firebase.analytics.validator.OSFANLMinimumRequired.AT_LEAST_ONE | ||
import com.outsystems.firebase.analytics.validator.OSFANLMinimumRequired.ONE | ||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
import java.io.Serializable | ||
|
||
class OSFANLManager { | ||
|
||
@Throws(OSFANLError::class) | ||
fun buildOutputEventFromInputJSON(input: JSONObject): OSFANLEventOutputModel { | ||
|
||
val eventName = input.getStringOrNull(OSFANLInputDataFieldKey.EVENT.json) ?: throw OSFANLError.missing(EVENT.json) | ||
val parameters = input.getArrayOrEmpty(OSFANLInputDataFieldKey.EVENT_PARAMETERS.json) | ||
val items = input.getArrayOrEmpty(ITEMS.json) | ||
|
||
val eventBuilderMethod = getEventBuilderMethod(eventName) | ||
val eventBundle = eventBuilderMethod(this, parameters, items) | ||
|
||
return OSFANLEventOutputModel(eventName, eventBundle) | ||
} | ||
|
||
private fun getEventBuilderMethod( | ||
eventName: String | ||
): (OSFANLManager, JSONArray, JSONArray) -> Bundle { | ||
|
||
when (eventName) { | ||
|
||
FirebaseAnalytics.Event.PURCHASE -> | ||
return OSFANLManager::buildBundleForPurchaseParametersEventType | ||
|
||
FirebaseAnalytics.Event.REFUND -> | ||
return OSFANLManager::buildBundleForRefundParametersEventType | ||
|
||
FirebaseAnalytics.Event.SELECT_ITEM -> | ||
return OSFANLManager::buildBundleForOneItemParametersEventType | ||
|
||
FirebaseAnalytics.Event.SELECT_PROMOTION -> | ||
return OSFANLManager::buildBundleForSelectPromotionParametersEventType | ||
|
||
FirebaseAnalytics.Event.VIEW_ITEM_LIST -> | ||
return OSFANLManager::buildBundleForViewItemListParametersEventType | ||
|
||
FirebaseAnalytics.Event.VIEW_PROMOTION -> | ||
return OSFANLManager::buildBundleForOneItemParametersEventType | ||
|
||
else -> | ||
return OSFANLManager::buildBundleForValueCurrencyAndMultipleItemsEventType | ||
} | ||
} | ||
|
||
private fun buildBundleForValueCurrencyAndMultipleItemsEventType( | ||
parameters: JSONArray, | ||
items: JSONArray | ||
): Bundle { | ||
return buildAndValidateParameterBundle( | ||
parameters, | ||
items, | ||
OSFANLEventParameterValidator.Builder() | ||
.requireCurrencyValue() | ||
.build(), | ||
OSFANLEventItemsValidator(minLimit = AT_LEAST_ONE) | ||
) | ||
} | ||
|
||
private fun buildBundleForPurchaseParametersEventType( | ||
parameters: JSONArray, | ||
items: JSONArray | ||
): Bundle { | ||
return buildAndValidateParameterBundle( | ||
parameters, | ||
items, | ||
OSFANLEventParameterValidator.Builder() | ||
.requireCurrencyValue() | ||
.required(TRANSACTION_ID) | ||
.number(SHIPPING, TAX) | ||
.build(), | ||
OSFANLEventItemsValidator(minLimit = AT_LEAST_ONE) | ||
) | ||
} | ||
|
||
private fun buildBundleForRefundParametersEventType( | ||
parameters: JSONArray, | ||
items: JSONArray | ||
): Bundle { | ||
return buildAndValidateParameterBundle( | ||
parameters, | ||
items, | ||
OSFANLEventParameterValidator.Builder() | ||
.requireCurrencyValue() | ||
.required(TRANSACTION_ID) | ||
.number(SHIPPING, TAX) | ||
.build() | ||
) | ||
} | ||
|
||
private fun buildBundleForOneItemParametersEventType( | ||
parameters: JSONArray, | ||
items: JSONArray | ||
): Bundle { | ||
return buildAndValidateParameterBundle( | ||
parameters, | ||
items, | ||
itemsValidator = OSFANLEventItemsValidator(minLimit = ONE) | ||
) | ||
} | ||
|
||
private fun buildBundleForSelectPromotionParametersEventType( | ||
parameters: JSONArray, | ||
items: JSONArray | ||
): Bundle { | ||
return buildAndValidateParameterBundle(parameters, items) | ||
} | ||
|
||
private fun buildBundleForViewItemListParametersEventType( | ||
parameters: JSONArray, | ||
items: JSONArray | ||
): Bundle { | ||
return buildAndValidateParameterBundle( | ||
parameters, | ||
items, | ||
itemsValidator = OSFANLEventItemsValidator(minLimit = AT_LEAST_ONE) | ||
) | ||
} | ||
|
||
private fun buildAndValidateParameterBundle( | ||
parameters: JSONArray, | ||
items: JSONArray, | ||
parametersValidator: OSFANLEventParameterValidator = OSFANLEventParameterValidator.Builder().build(), | ||
itemsValidator: OSFANLEventItemsValidator = OSFANLEventItemsValidator() | ||
): Bundle { | ||
|
||
// validate parameters | ||
val parameterBundle = parametersValidator.validate(parameters) | ||
|
||
// validate items | ||
val itemsBundle = itemsValidator.validate(items) | ||
if(itemsBundle.isNotEmpty()) | ||
parameterBundle.putSerializable(ITEMS.json, itemsBundle as Serializable) | ||
|
||
return parameterBundle | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/android/com/outsystems/firebase/analytics/model/OSFANLBundle+putAny.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,17 @@ | ||
package com.outsystems.firebase.analytics.model | ||
|
||
import android.os.Bundle | ||
|
||
/** | ||
* Adds a range of different types to a bundle. Accepted types are String, Int, Double and Long | ||
* @param key the key in which to store the value | ||
* @param value the value to store | ||
*/ | ||
fun Bundle.putAny(key: String, value: Any) { | ||
when (value) { | ||
is String -> this.putString(key, value) | ||
is Int -> this.putInt(key, value) | ||
is Double -> this.putDouble(key, value) | ||
is Long -> this.putLong(key, value) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/android/com/outsystems/firebase/analytics/model/OSFANLDefaultValues.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,12 @@ | ||
package com.outsystems.firebase.analytics.model | ||
|
||
/** | ||
* Holds the default size values for the input data | ||
*/ | ||
class OSFANLDefaultValues { | ||
companion object { | ||
const val itemQuantity: Int = 1 | ||
const val itemCustomParametersMaximum: Int = 27 | ||
const val eventItemsMaximum: Int = 200 | ||
} | ||
} |
Oops, something went wrong.