Skip to content

Commit

Permalink
feat(app, config): implement app_data_collection_default_enabled fire…
Browse files Browse the repository at this point in the history
…base.json key

implement SDK-wide default data collection toggle capability from firebase.json
  • Loading branch information
mikehardy committed Aug 15, 2021
1 parent 8408160 commit 1e47d45
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 30 deletions.
22 changes: 17 additions & 5 deletions packages/analytics/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,33 @@ project.ext {
])
}

apply from: file("./../../app/android/firebase-json.gradle")
apply from: file('./../../app/android/firebase-json.gradle')

def autoCollectionEnabled = "true"
// If nothing is defined, data collection defaults to true
String dataCollectionEnabled = 'true'

if (rootProject.ext && rootProject.ext.firebaseJson) {
if (rootProject.ext.firebaseJson.isFlagEnabled("analytics_auto_collection_enabled", true) == false) {
autoCollectionEnabled = "false"
/* groovylint-disable-next-line NoDef, VariableTypeRequired */
def rnfbConfig = rootProject.ext.firebaseJson
// If the SDK-wide data collection flag is defined and false, our default flips to false
if (rnfbConfig.isFlagEnabled('app_data_collection_default_enabled', true) == false) {
dataCollectionEnabled = 'false'
}
// If our specific collection flag is defined, it's status takes precedence
if (rnfbConfig.isDefined('analytics_auto_collection_enabled')) {
if (rnfbConfig.isFlagEnabled('analytics_auto_collection_enabled', true)) {
dataCollectionEnabled = 'true'
} else {
dataCollectionEnabled = 'false'
}
}
}

android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders = [
firebaseJsonAutoCollectionEnabled: autoCollectionEnabled
firebaseJsonAutoCollectionEnabled: dataCollectionEnabled
]
}
lintOptions {
Expand Down
3 changes: 2 additions & 1 deletion packages/app-check/ios/RNFBAppcheck/RNFBAppCheckModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ - (dispatch_queue_t)methodQueue {
appCheck.isTokenAutoRefreshEnabled = isTokenAutoRefreshEnabled;
}

// Not present in JS or Android - it is iOS-specific so we only call this in testing - it is not in index.d.ts
// Not present in JS or Android - it is iOS-specific so we only call this in testing - it is not in
// index.d.ts
RCT_EXPORT_METHOD(isTokenAutoRefreshEnabled
: (FIRApp *)firebaseApp
: (RCTPromiseResolveBlock)resolve rejecter
Expand Down
16 changes: 14 additions & 2 deletions packages/app/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,23 @@ project.ext {
])
}

apply from: file('./firebase-json.gradle')

// If data collection isn't specifically disabled, default is enabled
String dataCollectionDefaultEnabled = 'true'

if (rootProject.ext && rootProject.ext.firebaseJson) {
if (rootProject.ext.firebaseJson.isFlagEnabled('app_data_collection_default_enabled', true) == false) {
dataCollectionDefaultEnabled = 'false'
}
}

android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders = [
firebaseJsonDataCollectionDefaultEnabled: dataCollectionDefaultEnabled
]
}
lintOptions {
disable 'GradleCompatible'
Expand Down Expand Up @@ -82,8 +96,6 @@ dependencies {
implementation "com.google.android.gms:play-services-auth:${ReactNative.ext.getVersion("play", "play-services-auth")}"
}

apply from: file("./firebase-json.gradle")

ReactNative.shared.applyPackageVersion()
ReactNative.shared.applyDefaultExcludes()
ReactNative.module.applyAndroidVersions()
Expand Down
3 changes: 3 additions & 0 deletions packages/app/android/firebase-json.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ if (jsonFile?.exists()) {

rootProject.ext.firebaseJson = [
raw: json[jsonRoot],
isDefined: { key ->
return (json[jsonRoot] != null && json[jsonRoot][key] != null)
},
isFlagEnabled: { key, defaultValue ->
if (json[jsonRoot] == null || json[jsonRoot][key] == null) { return defaultValue }
return json[jsonRoot][key] == true
Expand Down
1 change: 1 addition & 0 deletions packages/app/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="io.invertase.firebase">

<application>
<meta-data android:name="app_data_collection_default_enabled" android:value="${firebaseJsonDataCollectionDefaultEnabled}"/>
<service android:name="com.google.firebase.components.ComponentDiscoveryService">
<meta-data
android:name="com.google.firebase.components:io.invertase.firebase.app.ReactNativeFirebaseAppRegistrar"
Expand Down
4 changes: 4 additions & 0 deletions packages/app/firebase-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"description": "Disable or enable auto collection of analytics data.\n This is useful for opt-in-first data flows, for example when dealing with GDPR compliance. This can be overridden in JavaScript. \n Re-enable analytics data collection, e.g. once user has granted permission.",
"type": "boolean"
},
"app_data_collection_default_enabled": {
"description": "Whether automatic data collection is enabled for all products, unless overridden by product-specific data collection settings.\n Setting this to false is useful for opt-in-first data flows, for example when dealing with GDPR compliance. \nThis may be overridden dynamically in Javascript via automaticDataCollectionEnabled FirebaseAppConfig property.",
"type": "boolean"
},
"app_check_token_auto_refresh": {
"description": "If this flag is disabled then Firebase App Check will not periodically auto-refresh the app check token.\n This is useful for opt-in-first data flows, for example when dealing with GDPR compliance. \nIf unset it will default to the SDK-wide data collection default enabled setting. This may be overridden dynamically in Javascript.",
"type": "boolean"
Expand Down
9 changes: 8 additions & 1 deletion packages/app/ios_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,21 @@ if [[ ${_SEARCH_RESULT} ]]; then
_PLIST_ENTRY_TYPES+=("string")
_PLIST_ENTRY_VALUES+=("$_JSON_OUTPUT_BASE64")

# config.app_data_collection_default_enabled
_APP_DATA_COLLECTION_ENABLED=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "app_data_collection_default_enabled")
if [[ $_APP_DATA_COLLECTION_ENABLED ]]; then
_PLIST_ENTRY_KEYS+=("FirebaseDataCollectionDefaultEnabled")
_PLIST_ENTRY_TYPES+=("bool")
_PLIST_ENTRY_VALUES+=("$(jsonBoolToYesNo "$_APP_DATA_COLLECTION_ENABLED")")
fi

# config.analytics_auto_collection_enabled
_ANALYTICS_AUTO_COLLECTION=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "analytics_auto_collection_enabled")
if [[ $_ANALYTICS_AUTO_COLLECTION ]]; then
_PLIST_ENTRY_KEYS+=("FIREBASE_ANALYTICS_COLLECTION_ENABLED")
_PLIST_ENTRY_TYPES+=("bool")
_PLIST_ENTRY_VALUES+=("$(jsonBoolToYesNo "$_ANALYTICS_AUTO_COLLECTION")")
fi

# config.perf_auto_collection_enabled
_PERF_AUTO_COLLECTION=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "perf_auto_collection_enabled")
if [[ $_PERF_AUTO_COLLECTION ]]; then
Expand Down
5 changes: 4 additions & 1 deletion packages/app/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ export namespace ReactNativeFirebase {
name?: string;

/**
*
* Default setting for data collection on startup that affects all Firebase module startup data collection settings,
* in the absence of module-specific overrides. This will start as false if you set "app_data_collection_default_enabled"
* to false in firebase.json and may be used in opt-in flows, for example a GDPR-compliant app.
* If configured false initially, set to true after obtaining consent, then enable module-specific settings as needed afterwards.
*/
automaticDataCollectionEnabled?: boolean;

Expand Down
20 changes: 16 additions & 4 deletions packages/in-app-messaging/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,31 @@ project.ext {

apply from: file('./../../app/android/firebase-json.gradle')

def autoInitEnabled = 'true'
// If nothing is defined, data collection defaults to true
String dataCollectionEnabled = 'true'

if (rootProject.ext && rootProject.ext.firebaseJson) {
if (rootProject.ext.firebaseJson.isFlagEnabled('in_app_messaging_auto_collection_enabled', true) == false) {
autoInitEnabled = 'false'
/* groovylint-disable-next-line NoDef, VariableTypeRequired */
def rnfbConfig = rootProject.ext.firebaseJson
// If the SDK-wide data collection flag is defined and false, our default flips to false
if (rnfbConfig.isFlagEnabled('app_data_collection_default_enabled', true) == false) {
dataCollectionEnabled = 'false'
}
// If our specific collection flag is defined, it's status takes precedence
if (rnfbConfig.isDefined('in_app_messaging_auto_collection_enabled')) {
if (rnfbConfig.isFlagEnabled('in_app_messaging_auto_collection_enabled', true)) {
dataCollectionEnabled = 'true'
} else {
dataCollectionEnabled = 'false'
}
}
}

android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders = [
firebaseJsonAutoInitEnabled: autoInitEnabled
firebaseJsonAutoInitEnabled: dataCollectionEnabled
]
}
lintOptions {
Expand Down
33 changes: 23 additions & 10 deletions packages/messaging/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,40 @@ project.ext {
])
}

apply from: file("./../../app/android/firebase-json.gradle")
apply from: file('./../../app/android/firebase-json.gradle')

def autoInitEnabled = "true"
def notificationChannelId = ""
def defaultNotificationColor = "@color/white";
def notificationColor = defaultNotificationColor
String notificationChannelId = ''
String defaultNotificationColor = '@color/white'
String notificationColor = defaultNotificationColor

// If nothing is defined, data collection defaults to true
String dataCollectionEnabled = 'true'

if (rootProject.ext && rootProject.ext.firebaseJson) {
if (rootProject.ext.firebaseJson.isFlagEnabled("messaging_auto_init_enabled", true) == false) {
autoInitEnabled = "false"
/* groovylint-disable-next-line NoDef, VariableTypeRequired */
def rnfbConfig = rootProject.ext.firebaseJson
// If the SDK-wide data collection flag is defined and false, our default flips to false
if (rnfbConfig.isFlagEnabled('app_data_collection_default_enabled', true) == false) {
dataCollectionEnabled = 'false'
}
notificationChannelId = rootProject.ext.firebaseJson.getStringValue("messaging_android_notification_channel_id", "")
notificationColor = rootProject.ext.firebaseJson.getStringValue("messaging_android_notification_color", defaultNotificationColor)
// If our specific collection flag is defined, it's status takes precedence
if (rnfbConfig.isDefined('messaging_auto_init_enabled')) {
if (rnfbConfig.isFlagEnabled('messaging_auto_init_enabled', true)) {
dataCollectionEnabled = 'true'
} else {
dataCollectionEnabled = 'false'
}
}

notificationChannelId = rnfbConfig.getStringValue('messaging_android_notification_channel_id', '')
notificationColor = rnfbConfig.getStringValue('messaging_android_notification_color', defaultNotificationColor)
}

android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders = [
firebaseJsonAutoInitEnabled: autoInitEnabled,
firebaseJsonAutoInitEnabled: dataCollectionEnabled,
firebaseJsonNotificationChannelId: notificationChannelId,
firebaseJsonNotificationColor: notificationColor
]
Expand Down
22 changes: 17 additions & 5 deletions packages/perf/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,33 @@ project.ext {
])
}

apply from: file("./../../app/android/firebase-json.gradle")
apply from: file('./../../app/android/firebase-json.gradle')

def autoCollectionEnabled = "true"
// If nothing is defined, data collection defaults to true
String dataCollectionEnabled = 'true'

if (rootProject.ext && rootProject.ext.firebaseJson) {
if (rootProject.ext.firebaseJson.isFlagEnabled("perf_auto_collection_enabled", true) == false) {
autoCollectionEnabled = "false"
/* groovylint-disable-next-line NoDef, VariableTypeRequired */
def rnfbConfig = rootProject.ext.firebaseJson
// If the SDK-wide data collection flag is defined and false, our default flips to false
if (rnfbConfig.isFlagEnabled('app_data_collection_default_enabled', true) == false) {
dataCollectionEnabled = 'false'
}
// If our specific collection flag is defined, it's status takes precedence
if (rnfbConfig.isDefined('perf_auto_collection_enabled')) {
if (rnfbConfig.isFlagEnabled('perf_auto_collection_enabled', true)) {
dataCollectionEnabled = 'true'
} else {
dataCollectionEnabled = 'false'
}
}
}

android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders = [
firebaseJsonAutoCollectionEnabled: autoCollectionEnabled
firebaseJsonAutoCollectionEnabled: dataCollectionEnabled
]
}
lintOptions {
Expand Down
2 changes: 2 additions & 0 deletions tests/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"react-native": {
"android_background_activity_names": "NotActuallyAnActivity",

"app_data_collection_default_enabled": false,

"app_check_token_auto_refresh": false,

"crashlytics_ndk_enabled": true,
Expand Down
Loading

0 comments on commit 1e47d45

Please sign in to comment.