Skip to content

Commit b93ff18

Browse files
authored
Updated to latest firebase analytics for destination (#17)
* Updated to latest firebase analytics for destination
1 parent 1f2fac3 commit b93ff18

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath "com.android.tools.build:gradle:4.1.2"
10+
classpath 'com.android.tools.build:gradle:4.2.2'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
1313

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

samples/kotlin-android-app-destinations/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ dependencies {
4242
api 'com.mixpanel.android:mixpanel-android:5.8.7'
4343

4444
// Firebase
45-
implementation 'com.google.firebase:firebase-core:15.0.2'
45+
implementation platform('com.google.firebase:firebase-bom:28.2.1')
46+
// Declare the dependency for the Analytics library
47+
// When using the BoM, you don't specify versions in Firebase library dependencies
48+
implementation 'com.google.firebase:firebase-analytics-ktx'
4649

4750
implementation project(':android')
4851

samples/kotlin-android-app-destinations/src/main/java/com/segment/analytics/destinations/plugins/FirebaseDestination.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ class FirebaseDestination(
103103
eventName = makeKey(eventName)
104104
}
105105

106-
payload.properties.let {
107-
val formattedProperties = formatProperties(it)
108-
firebaseAnalytics.logEvent(eventName, formattedProperties)
109-
analytics.log("firebaseAnalytics.logEvent($eventName, $formattedProperties)")
110-
}
106+
val bundledProperties = formatProperties(payload.properties)
107+
108+
firebaseAnalytics.logEvent(eventName, bundledProperties)
109+
analytics.log("firebaseAnalytics.logEvent($eventName, $bundledProperties)")
111110

112111
return returnPayload
113112
}
@@ -117,7 +116,9 @@ class FirebaseDestination(
117116

118117
val tempActivity = activity
119118
if (tempActivity != null) {
120-
firebaseAnalytics.setCurrentScreen(tempActivity, payload.name, null);
119+
val bundle = Bundle()
120+
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, payload.name)
121+
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle)
121122
}
122123

123124
return returnPayload
@@ -134,7 +135,9 @@ class FirebaseDestination(
134135
packageManager.getActivityInfo(activity.componentName, PackageManager.GET_META_DATA)
135136
.let {
136137
it.loadLabel(packageManager).toString().let { activityName ->
137-
firebaseAnalytics.setCurrentScreen(activity, activityName, null)
138+
val bundle = Bundle()
139+
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, activityName)
140+
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle)
138141
analytics.log(
139142
"firebaseAnalytics.setCurrentScreen(activity, $activityName, null"
140143
)
@@ -184,7 +187,6 @@ class FirebaseDestination(
184187
}
185188
}
186189

187-
188190
// Don't return a valid bundle if there wasn't anything added
189191
if (bundle?.isEmpty == true) {
190192
bundle = null
@@ -214,11 +216,10 @@ class FirebaseDestination(
214216
return mappedProducts
215217
}
216218

217-
// Make sure keys do not contain ".", "-", " ", ":"
219+
// Make sure keys do not contain ".", "-", " ", ":" and are replaced with _
218220
private fun makeKey(key: String): String {
219-
val charsToFilter = ".- :"
220-
// only filter out the characters in charsToFilter by relying on the other characters not being found
221-
return key.filter { charsToFilter.indexOf(it) == -1 }
221+
val charsToFilter = """[\. \-:]""".toRegex()
222+
return key.replace(charsToFilter, "_")
222223
}
223224

224225
// Adds the appropriate value & type to a supplied bundle

0 commit comments

Comments
 (0)