-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add option to disable screen view usage #474
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
550e220
feat: screen view usage
mrehan27 a55ecbb
chore: update java sample app with screen view configuration (#475)
mrehan27 5514d11
pr comment
mrehan27 6655fd4
pr suggestions
mrehan27 14ffd19
chore: update screenview to sealed class (#477)
mrehan27 0a6fdb3
Merge branch 'main' into rehan/mbl-755-screen-config-sdk
Shahroz16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
datapipelines/src/main/kotlin/io/customer/datapipelines/config/ScreenView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.customer.datapipelines.config | ||
|
||
/** | ||
* Enum class to define how CustomerIO SDK should handle screen view events. | ||
*/ | ||
enum class ScreenView { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious why we are opting for making this an enum instead of:
|
||
/** | ||
* Screen view events are sent to destinations for analytics purposes. | ||
*/ | ||
Analytics, | ||
|
||
/** | ||
* Screen view events are kept on device only. They are used to display in-app messages based on page rules. Events are not sent to our back end servers. | ||
*/ | ||
InApp; | ||
|
||
companion object { | ||
/** | ||
* Returns the [ScreenView] enum constant for the given name. | ||
* Returns fallback if the specified enum type has no constant with the given name. | ||
* Defaults to [Analytics]. | ||
*/ | ||
@JvmOverloads | ||
fun getScreenView(screenView: String?, fallback: ScreenView = Analytics): ScreenView { | ||
return values().firstOrNull { it.name.equals(screenView, ignoreCase = true) } ?: fallback | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
datapipelines/src/main/kotlin/io/customer/datapipelines/plugins/ScreenFilterPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.customer.datapipelines.plugins | ||
|
||
import com.segment.analytics.kotlin.core.Analytics | ||
import com.segment.analytics.kotlin.core.BaseEvent | ||
import com.segment.analytics.kotlin.core.ScreenEvent | ||
import com.segment.analytics.kotlin.core.platform.EventPlugin | ||
import com.segment.analytics.kotlin.core.platform.Plugin | ||
import io.customer.datapipelines.config.ScreenView | ||
|
||
/** | ||
* Plugin to filter screen events based on the configuration provided by customer app. | ||
* This plugin is used to filter out screen events that should not be processed further. | ||
*/ | ||
class ScreenFilterPlugin(private val screenViewUse: ScreenView) : EventPlugin { | ||
mrehan27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
override lateinit var analytics: Analytics | ||
override val type: Plugin.Type = Plugin.Type.Enrichment | ||
|
||
override fun screen(payload: ScreenEvent): BaseEvent? { | ||
// Filter out screen events based on the configuration provided by customer app | ||
// Using when expression so it enforce right check for all possible values of ScreenView in future | ||
return when (screenViewUse) { | ||
ScreenView.Analytics -> payload | ||
// Do not send screen events to server if ScreenView is not Analytics | ||
ScreenView.InApp -> null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
datapipelines/src/test/java/io/customer/datapipelines/plugins/ScreenFilterPluginTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.customer.datapipelines.plugins | ||
|
||
import io.customer.commontest.config.TestConfig | ||
import io.customer.commontest.extensions.random | ||
import io.customer.datapipelines.config.ScreenView | ||
import io.customer.datapipelines.testutils.core.DataPipelinesTestConfig | ||
import io.customer.datapipelines.testutils.core.JUnitTest | ||
import io.customer.datapipelines.testutils.core.testConfiguration | ||
import io.customer.datapipelines.testutils.extensions.shouldMatchTo | ||
import io.customer.datapipelines.testutils.utils.OutputReaderPlugin | ||
import io.customer.datapipelines.testutils.utils.screenEvents | ||
import io.customer.sdk.data.model.CustomAttributes | ||
import org.amshove.kluent.shouldBeEmpty | ||
import org.amshove.kluent.shouldBeEqualTo | ||
import org.amshove.kluent.shouldHaveSingleItem | ||
import org.junit.jupiter.api.Test | ||
|
||
class ScreenFilterPluginTest : JUnitTest() { | ||
private lateinit var outputReaderPlugin: OutputReaderPlugin | ||
|
||
override fun setup(testConfig: TestConfig) { | ||
// Keep setup empty to avoid calling super.setup() as it will initialize the SDK | ||
// and we want to test the SDK with different configurations in each test | ||
} | ||
|
||
private fun setupWithConfig(screenViewUse: ScreenView, testConfig: DataPipelinesTestConfig = testConfiguration {}) { | ||
super.setup( | ||
testConfiguration { | ||
analytics { add(ScreenFilterPlugin(screenViewUse = screenViewUse)) } | ||
} + testConfig | ||
) | ||
|
||
outputReaderPlugin = OutputReaderPlugin() | ||
analytics.add(outputReaderPlugin) | ||
} | ||
|
||
@Test | ||
fun process_givenScreenViewUseAnalytics_expectScreenEventWithoutPropertiesProcessed() { | ||
setupWithConfig(screenViewUse = ScreenView.Analytics) | ||
|
||
val givenScreenTitle = String.random | ||
sdkInstance.screen(givenScreenTitle) | ||
|
||
val result = outputReaderPlugin.screenEvents.shouldHaveSingleItem() | ||
result.name shouldBeEqualTo givenScreenTitle | ||
result.properties.shouldBeEmpty() | ||
} | ||
|
||
@Test | ||
fun process_givenScreenViewUseAnalytics_expectScreenEventWithPropertiesProcessed() { | ||
setupWithConfig(screenViewUse = ScreenView.Analytics) | ||
|
||
val givenScreenTitle = String.random | ||
val givenProperties: CustomAttributes = mapOf("source" to "push", "discount" to 10) | ||
sdkInstance.screen(givenScreenTitle, givenProperties) | ||
|
||
val screenEvent = outputReaderPlugin.screenEvents.shouldHaveSingleItem() | ||
screenEvent.name shouldBeEqualTo givenScreenTitle | ||
screenEvent.properties shouldMatchTo givenProperties | ||
} | ||
|
||
@Test | ||
fun process_givenScreenViewUseInApp_expectAllScreenEventsIgnored() { | ||
setupWithConfig(screenViewUse = ScreenView.InApp) | ||
|
||
for (i in 1..5) { | ||
sdkInstance.screen(String.random) | ||
} | ||
|
||
outputReaderPlugin.allEvents.shouldBeEmpty() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean it's a mutually exclusive choice? I can either choose analytics or in-app? But what if a customer needs both?