commit
e3e33d8497
@ -0,0 +1,125 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "YourProjectId",
|
||||
"project_id": "abc",
|
||||
"storage_bucket": "abc"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "Your:App:Id",
|
||||
"android_client_info": {
|
||||
"package_name": "com.google.samples.apps.nowinandroid"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "Your:App:Id",
|
||||
"android_client_info": {
|
||||
"package_name": "com.google.samples.apps.nowinandroid.demo.debug"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "Your:App:Id",
|
||||
"android_client_info": {
|
||||
"package_name": "com.google.samples.apps.nowinandroid.demo.benchmark"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "Your:App:Id",
|
||||
"android_client_info": {
|
||||
"package_name": "com.google.samples.apps.nowinandroid.benchmark"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "Your:App:Id",
|
||||
"android_client_info": {
|
||||
"package_name": "com.google.samples.apps.nowinandroid.debug"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "Your:App:Id",
|
||||
"android_client_info": {
|
||||
"package_name": "com.google.samples.apps.nowinandroid.demo"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "APlaceholderAPIKeyWith-ThirtyNineCharsX"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
"configuration_version": "1"
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2023 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<application>
|
||||
<!-- Enable Firebase analytics for `prod` builds -->
|
||||
<meta-data
|
||||
tools:replace="android:value"
|
||||
android:name="firebase_analytics_collection_deactivated"
|
||||
android:value="false" />
|
||||
</application>
|
||||
</manifest>
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import com.android.build.api.dsl.ApplicationExtension
|
||||
import com.google.samples.apps.nowinandroid.configureFlavors
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
|
||||
class AndroidApplicationFlavorsConventionPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
extensions.configure<ApplicationExtension> {
|
||||
configureFlavors(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
/build
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
plugins {
|
||||
id("nowinandroid.android.library")
|
||||
id("nowinandroid.android.library.compose")
|
||||
id("nowinandroid.android.hilt")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.google.samples.apps.nowinandroid.core.analytics"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.kotlinx.coroutines.android)
|
||||
implementation(libs.androidx.compose.runtime)
|
||||
implementation(libs.androidx.core.ktx)
|
||||
|
||||
implementation(platform(libs.firebase.bom))
|
||||
implementation(libs.firebase.analytics)
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.analytics
|
||||
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
abstract class AnalyticsModule {
|
||||
@Binds
|
||||
abstract fun bindsAnalyticsHelper(analyticsHelperImpl: StubAnalyticsHelper): AnalyticsHelper
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2023 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<manifest />
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.analytics
|
||||
|
||||
/**
|
||||
* Represents an analytics event.
|
||||
*
|
||||
* @param type - the event type. Wherever possible use one of the standard
|
||||
* event `Types`, however, if there is no suitable event type already defined, a custom event can be
|
||||
* defined as long as it is configured in your backend analytics system (for example, by creating a
|
||||
* Firebase Analytics custom event).
|
||||
*
|
||||
* @param extras - list of parameters which supply additional context to the event. See `Param`.
|
||||
*/
|
||||
data class AnalyticsEvent(
|
||||
val type: String,
|
||||
val extras: List<Param> = emptyList(),
|
||||
) {
|
||||
// Standard analytics types.
|
||||
class Types {
|
||||
companion object {
|
||||
const val SCREEN_VIEW = "screen_view" // (extras: SCREEN_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A key-value pair used to supply extra context to an analytics event.
|
||||
*
|
||||
* @param key - the parameter key. Wherever possible use one of the standard `ParamKeys`,
|
||||
* however, if no suitable key is available you can define your own as long as it is configured
|
||||
* in your backend analytics system (for example, by creating a Firebase Analytics custom
|
||||
* parameter).
|
||||
*
|
||||
* @param value - the parameter value.
|
||||
*/
|
||||
data class Param(val key: String, val value: String)
|
||||
|
||||
// Standard parameter keys.
|
||||
class ParamKeys {
|
||||
companion object {
|
||||
const val SCREEN_NAME = "screen_name"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.analytics
|
||||
|
||||
/**
|
||||
* Interface for logging analytics events. See `FirebaseAnalyticsHelper` and
|
||||
* `StubAnalyticsHelper` for implementations.
|
||||
*/
|
||||
interface AnalyticsHelper {
|
||||
fun logEvent(event: AnalyticsEvent)
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.analytics
|
||||
|
||||
/**
|
||||
* Implementation of AnalyticsHelper which does nothing. Useful for tests and previews.
|
||||
*/
|
||||
class NoOpAnalyticsHelper : AnalyticsHelper {
|
||||
override fun logEvent(event: AnalyticsEvent) = Unit
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.analytics
|
||||
|
||||
import android.util.Log
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
private const val TAG = "StubAnalyticsHelper"
|
||||
|
||||
/**
|
||||
* An implementation of AnalyticsHelper just writes the events to logcat. Used in builds where no
|
||||
* analytics events should be sent to a backend.
|
||||
*/
|
||||
@Singleton
|
||||
class StubAnalyticsHelper @Inject constructor() : AnalyticsHelper {
|
||||
override fun logEvent(event: AnalyticsEvent) {
|
||||
Log.d(TAG, "Received analytics event: $event")
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.analytics
|
||||
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
|
||||
/**
|
||||
* Global key used to obtain access to the AnalyticsHelper through a CompositionLocal.
|
||||
*/
|
||||
val LocalAnalyticsHelper = staticCompositionLocalOf<AnalyticsHelper> {
|
||||
// Provide a default AnalyticsHelper which does nothing. This is so that tests and previews
|
||||
// do not have to provide one. For real app builds provide a different implementation.
|
||||
NoOpAnalyticsHelper()
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.analytics
|
||||
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
abstract class AnalyticsModule {
|
||||
@Binds
|
||||
abstract fun bindsAnalyticsHelper(analyticsHelperImpl: FirebaseAnalyticsHelper): AnalyticsHelper
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.analytics
|
||||
|
||||
import com.google.firebase.analytics.ktx.analytics
|
||||
import com.google.firebase.analytics.ktx.logEvent
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Implementation of `AnalyticsHelper` which logs events to a Firebase backend.
|
||||
*/
|
||||
@Singleton
|
||||
class FirebaseAnalyticsHelper @Inject constructor() : AnalyticsHelper {
|
||||
|
||||
private val firebaseAnalytics = Firebase.analytics
|
||||
|
||||
override fun logEvent(event: AnalyticsEvent) {
|
||||
firebaseAnalytics.logEvent(event.type) {
|
||||
for (extra in event.extras) {
|
||||
// Truncate parameter keys and values according to firebase maximum length values.
|
||||
param(
|
||||
key = extra.key.take(40),
|
||||
value = extra.value.take(100),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.data.repository
|
||||
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsEvent
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsEvent.Param
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper
|
||||
|
||||
fun AnalyticsHelper.logNewsResourceBookmarkToggled(newsResourceId: String, isBookmarked: Boolean) {
|
||||
val eventType = if (isBookmarked) "news_resource_saved" else "news_resource_unsaved"
|
||||
val paramKey = if (isBookmarked) "saved_news_resource_id" else "unsaved_news_resource_id"
|
||||
logEvent(
|
||||
AnalyticsEvent(
|
||||
type = eventType,
|
||||
extras = listOf(
|
||||
Param(key = paramKey, value = newsResourceId),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fun AnalyticsHelper.logTopicFollowToggled(followedTopicId: String, isFollowed: Boolean) {
|
||||
val eventType = if (isFollowed) "topic_followed" else "topic_unfollowed"
|
||||
val paramKey = if (isFollowed) "followed_topic_id" else "unfollowed_topic_id"
|
||||
logEvent(
|
||||
AnalyticsEvent(
|
||||
type = eventType,
|
||||
extras = listOf(
|
||||
Param(key = paramKey, value = followedTopicId),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fun AnalyticsHelper.logThemeChanged(themeName: String) =
|
||||
logEvent(
|
||||
AnalyticsEvent(
|
||||
type = "theme_changed",
|
||||
extras = listOf(
|
||||
Param(key = "theme_name", value = themeName),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
fun AnalyticsHelper.logDarkThemeConfigChanged(darkThemeConfigName: String) =
|
||||
logEvent(
|
||||
AnalyticsEvent(
|
||||
type = "dark_theme_config_changed",
|
||||
extras = listOf(
|
||||
Param(key = "dark_theme_config", value = darkThemeConfigName),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
fun AnalyticsHelper.logDynamicColorPreferenceChanged(useDynamicColor: Boolean) =
|
||||
logEvent(
|
||||
AnalyticsEvent(
|
||||
type = "dynamic_color_preference_changed",
|
||||
extras = listOf(
|
||||
Param(key = "dynamic_color_preference", value = useDynamicColor.toString()),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
fun AnalyticsHelper.logOnboardingStateChanged(shouldHideOnboarding: Boolean) {
|
||||
val eventType = if (shouldHideOnboarding) "onboarding_complete" else "onboarding_reset"
|
||||
logEvent(
|
||||
AnalyticsEvent(type = eventType),
|
||||
)
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.core.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsEvent
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsEvent.Param
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsEvent.ParamKeys
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsEvent.Types
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.LocalAnalyticsHelper
|
||||
|
||||
/**
|
||||
* Classes and functions associated with analytics events for the UI.
|
||||
*/
|
||||
fun AnalyticsHelper.logScreenView(screenName: String) {
|
||||
logEvent(
|
||||
AnalyticsEvent(
|
||||
type = Types.SCREEN_VIEW,
|
||||
extras = listOf(
|
||||
Param(ParamKeys.SCREEN_NAME, screenName),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fun AnalyticsHelper.logNewsResourceOpened(newsResourceId: String, newsResourceTitle: String) {
|
||||
logEvent(
|
||||
event = AnalyticsEvent(
|
||||
type = "news_resource_opened",
|
||||
extras = listOf(
|
||||
Param("opened_news_resource", newsResourceId),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A side-effect which records a screen view event.
|
||||
*/
|
||||
@Composable
|
||||
fun TrackScreenViewEvent(
|
||||
screenName: String,
|
||||
analyticsHelper: AnalyticsHelper = LocalAnalyticsHelper.current,
|
||||
) = DisposableEffect(Unit) {
|
||||
analyticsHelper.logScreenView(screenName)
|
||||
onDispose {}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.samples.apps.nowinandroid.sync.workers
|
||||
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsEvent
|
||||
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper
|
||||
|
||||
fun AnalyticsHelper.logSyncStarted() =
|
||||
logEvent(
|
||||
AnalyticsEvent(type = "network_sync_started"),
|
||||
)
|
||||
|
||||
fun AnalyticsHelper.logSyncFinished(syncedSuccessfully: Boolean) {
|
||||
val eventType = if (syncedSuccessfully) "network_sync_successful" else "network_sync_failed"
|
||||
logEvent(
|
||||
AnalyticsEvent(type = eventType),
|
||||
)
|
||||
}
|
Loading…
Reference in new issue