Skip to content

Commit

Permalink
feat(analytics, config): expose all the native data collection toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehardy committed Aug 15, 2021
1 parent 1e47d45 commit f5eaffb
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 5 deletions.
25 changes: 24 additions & 1 deletion packages/analytics/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* groovylint-disable DuplicateStringLiteral */
import io.invertase.gradle.common.PackageJson

buildscript {
Expand Down Expand Up @@ -65,6 +66,11 @@ project.ext {

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

String collectionDeactivated = 'false'
String adidEnabled = 'true'
String ssaidEnabled = 'true'
String personalizationEnabled = 'true'

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

Expand All @@ -83,13 +89,30 @@ if (rootProject.ext && rootProject.ext.firebaseJson) {
dataCollectionEnabled = 'false'
}
}

if (rnfbConfig.isFlagEnabled('analytics_collection_deactivated', false) == true) {
collectionDeactivated = 'true'
}
if (rnfbConfig.isFlagEnabled('google_analytics_adid_collection_enabled', true) == false) {
adidEnabled = 'false'
}
if (rnfbConfig.isFlagEnabled('google_analytics_ssaid_collection_enabled', true) == false) {
ssaidEnabled = 'false'
}
if (rnfbConfig.isFlagEnabled('analytics_default_allow_ad_personalization_signals', true) == false) {
personalizationEnabled = 'false'
}
}

android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders = [
firebaseJsonAutoCollectionEnabled: dataCollectionEnabled
firebaseJsonAutoCollectionEnabled: dataCollectionEnabled,
firebaseJsonCollectionDeactivated: collectionDeactivated,
firebaseJsonAdidEnabled: adidEnabled,
firebaseJsonSsaidEnabled: ssaidEnabled,
firebaseJsonPersonalizationEnabled: personalizationEnabled
]
}
lintOptions {
Expand Down
8 changes: 5 additions & 3 deletions packages/analytics/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application>
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="${firebaseJsonAutoCollectionEnabled}"/>
<meta-data android:name="firebase_analytics_collection_enabled" android:value="${firebaseJsonAutoCollectionEnabled}"/>
<meta-data android:name="firebase_analytics_collection_deactivated" android:value="${firebaseJsonCollectionDeactivated}" />
<meta-data android:name="google_analytics_adid_collection_enabled" android:value="${firebaseJsonAdidEnabled}" />
<meta-data android:name="google_analytics_ssaid_collection_enabled" android:value="${firebaseJsonSsaidEnabled}" />
<meta-data android:name="google_analytics_default_allow_ad_personalization_signals" android:value="${firebaseJsonPersonalizationEnabled}" />
</application>
</manifest>
20 changes: 20 additions & 0 deletions packages/app/firebase-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@
"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"
},
"analytics_collection_deactivated": {
"description": "If you need to deactivate Analytics collection permanently in a version of your app.\n This cannot be altered at runtime once set in the config.",
"type": "boolean"
},
"analytics_idfv_collection_enabled": {
"description": "If you wish to disable collection of the IDFV (Identifier for Vendor) in your iOS app.\n This cannot be altered at runtime once set in the config.",
"type": "boolean"
},
"google_analytics_adid_collection_enabled": {
"description": " If you wish to disable collection of the Advertising ID in your Android app.\n This cannot be altered at runtime once set in the config.",
"type": "boolean"
},
"google_analytics_ssaid_collection_enabled": {
"description": "If you wish to disable collection of SSAID (Settings.Secure.ANDROID_ID) in your Android app,.\n This cannot be altered at runtime once set in the config.",
"type": "boolean"
},
"analytics_default_allow_ad_personalization_signals": {
"description": "Configure whether a user's Analytics data may be used for personalized advertising in other products.\n If set, may be overridden at runtime by calling setUserProperty on the key 'allow_personalized_ads'",
"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"
Expand Down
25 changes: 25 additions & 0 deletions packages/app/ios_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ if [[ ${_SEARCH_RESULT} ]]; then
_PLIST_ENTRY_TYPES+=("bool")
_PLIST_ENTRY_VALUES+=("$(jsonBoolToYesNo "$_ANALYTICS_AUTO_COLLECTION")")
fi

# config.analytics_collection_deactivated
_ANALYTICS_DEACTIVATED=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "analytics_collection_deactivated")
if [[ $_ANALYTICS_DEACTIVATED ]]; then
_PLIST_ENTRY_KEYS+=("FIREBASE_ANALYTICS_COLLECTION_DEACTIVATED")
_PLIST_ENTRY_TYPES+=("bool")
_PLIST_ENTRY_VALUES+=("$(jsonBoolToYesNo "$_ANALYTICS_DEACTIVATED")")
fi

# config.analytics_idfv_collection_enabled
_ANALYTICS_IDFV_COLLECTION=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "analytics_idfv_collection_enabled")
if [[ $_ANALYTICS_IDFV_COLLECTION ]]; then
_PLIST_ENTRY_KEYS+=("GOOGLE_ANALYTICS_IDFV_COLLECTION_ENABLED")
_PLIST_ENTRY_TYPES+=("bool")
_PLIST_ENTRY_VALUES+=("$(jsonBoolToYesNo "$_ANALYTICS_IDFV_COLLECTION")")
fi

# config.analytics_default_allow_ad_personalization_signals
_ANALYTICS_PERSONALIZATION=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "analytics_default_allow_ad_personalization_signals")
if [[ $_ANALYTICS_PERSONALIZATION ]]; then
_PLIST_ENTRY_KEYS+=("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS")
_PLIST_ENTRY_TYPES+=("bool")
_PLIST_ENTRY_VALUES+=("$(jsonBoolToYesNo "$_ANALYTICS_PERSONALIZATION")")
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: 5 additions & 0 deletions tests/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"messaging_ios_auto_register_for_remote_messages": false,

"analytics_auto_collection_enabled": true,
"analytics_collection_deactivated": false,
"analytics_idfv_collection_enabled": false,
"google_analytics_adid_collection_enabled": true,
"google_analytics_ssaid_collection_enabled": true,
"analytics_default_allow_ad_personalization_signals": true,

"perf_auto_collection_enabled": false,

Expand Down
Loading

0 comments on commit f5eaffb

Please sign in to comment.