Skip to content

Commit

Permalink
feat(analytics): add support for analytics_auto_collection_enabled in…
Browse files Browse the repository at this point in the history
… firebase.json (#4730)
  • Loading branch information
gewfy authored Dec 30, 2020
1 parent 2efb5c2 commit 9a24ecd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/analytics/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,22 @@ project.ext {
])
}

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

def autoCollectionEnabled = "true"

if (rootProject.ext && rootProject.ext.firebaseJson) {
if (rootProject.ext.firebaseJson.isFlagEnabled("analytics_auto_collection_enabled") == false) {
autoCollectionEnabled = "false"
}
}

android {
defaultConfig {
multiDexEnabled true
manifestPlaceholders = [
firebaseJsonAutoCollectionEnabled: autoCollectionEnabled
]
}
lintOptions {
disable 'GradleCompatible'
Expand Down
6 changes: 6 additions & 0 deletions packages/analytics/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application>
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="${firebaseJsonAutoCollectionEnabled}"/>
</application>
</manifest>
8 changes: 8 additions & 0 deletions packages/app/ios_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ if [[ ${_SEARCH_RESULT} ]]; then
_PLIST_ENTRY_TYPES+=("string")
_PLIST_ENTRY_VALUES+=("$_JSON_OUTPUT_BASE64")

# 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.messaging_auto_init_enabled
_MESSAGING_AUTO_INIT=$(getFirebaseJsonKeyValue "$_JSON_OUTPUT_RAW" "messaging_auto_init_enabled")
if [[ $_MESSAGING_AUTO_INIT ]]; then
Expand Down
3 changes: 2 additions & 1 deletion tests/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"messaging_android_notification_color": "@color/hotpink",
"messaging_ios_auto_register_for_remote_messages": true,

"TODO_analytics_auto_collection_enabled": true,
"analytics_auto_collection_enabled": true,

"TODO_perf_auto_collection_enabled": true,
"TODO_in_app_messaging_auto_collection_enabled": true,
"TODO_database_persistence_enabled": true,
Expand Down

3 comments on commit 9a24ecd

@vercel
Copy link

@vercel vercel bot commented on 9a24ecd Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WadhahEssam
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is something wrong with this commit, for some reason the analytics_auto_collection_enabled value is set to false by default if you don't set it in the firebase.json file, I am not sure why this happens to me but analytics didn't work when I dont set its value in the firebase.json
I had to release a new version for it.

I tried logging the value of analytics_auto_collection_enabled from the gradle file, but I had no luck with it due to my weak experience with them

@WadhahEssam
Copy link

@WadhahEssam WadhahEssam commented on 9a24ecd Jan 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After investigating : here are my notes :

-isFlagEnabled(key) in firebase-json.gradle returns true if the (key) exists in firebase.json & its value is equal to true, so (rootProject.ext.firebaseJson.isFlagEnabled("analytics_auto_collectadmob_delay_app_measurement_initon_enabled") == false) this expression will be evaluated as true if the key analytics_auto_collectadmob_delay_app_measurement_initon_enabled is not specefied in firebase.json which will set it to false hence analytics will be disabled.

Please sign in to comment.