Skip to content

Commit

Permalink
Added Event visualiser for clickstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
radityagumay committed Jun 27, 2022
1 parent e7c4495 commit 108d3e9
Show file tree
Hide file tree
Showing 101 changed files with 3,433 additions and 40 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
:clickstream-health-metrics:testReleaseUnitTest
:clickstream-health-metrics-noop:testReleaseUnitTest
:clickstream-health-metrics-api:testReleaseUnitTest
:clickstream-event-visualiser:testReleaseUnitTest
:clickstream-event-visualiser-noop:testReleaseUnitTest
:clickstream-event-visualiser-ui:testReleaseUnitTest
:clickstream-event-visualiser-ui-noop:testReleaseUnitTest
:app:testReleaseUnitTest

build:
Expand All @@ -58,44 +62,87 @@ jobs:
:clickstream-health-metrics:assembleRelease
:clickstream-health-metrics-noop:assembleRelease
:clickstream-health-metrics-api:assembleRelease
:clickstream-event-interceptor:assemble
:clickstream-event-visualiser:assembleRelease
:clickstream-event-visualiser-noop:assembleRelease
:clickstream-event-visualiser-ui:assembleRelease
:clickstream-event-visualiser-ui-noop:assembleRelease
:app:assembleRelease

- name: Archive clickstream aar
uses: actions/upload-artifact@v2
with:
name: clickstream
path: clickstream/build/outputs/aar/**.aar

- name: Archive clickstream-api aar
uses: actions/upload-artifact@v2
with:
name: clickstream-api
path: clickstream-api/build/outputs/aar/**.aar

- name: Archive clickstream-logger aar
uses: actions/upload-artifact@v2
with:
name: clickstream-logger
path: clickstream-logger/build/outputs/aar/**.aar

- name: Archive clickstream-lifecycle aar
uses: actions/upload-artifact@v2
with:
name: clickstream-lifecycle
path: clickstream-lifecycle/build/outputs/aar/**.aar

- name: Archive clickstream-util aar
uses: actions/upload-artifact@v2
with:
name: clickstream-util
path: clickstream-util/build/outputs/aar/**.aar

- name: Archive clickstream-health-metrics aar
uses: actions/upload-artifact@v2
with:
name: clickstream-health-metrics
path: clickstream-health-metrics/build/outputs/aar/**.aar

- name: Archive clickstream-health-metrics-noop aar
uses: actions/upload-artifact@v2
with:
name: clickstream-health-metrics-noop
path: clickstream-health-metrics-noop/build/outputs/aar/**.aar

- name: Archive clickstream-health-metrics-api aar
uses: actions/upload-artifact@v2
with:
name: clickstream-health-metrics-api
path: clickstream-health-metrics-api/build/outputs/aar/**.aar

- name: Archive clickstream-event-interceptor jar
uses: actions/upload-artifact@v2
with:
name: clickstream-event-interceptor
path: clickstream-event-interceptor/build/libs/**.jar

- name: Archive clickstream-event-visualiser aar
uses: actions/upload-artifact@v2
with:
name: clickstream-event-visualiser
path: clickstream-event-visualiser/build/outputs/aar/**.aar

- name: Archive clickstream-event-visualiser-noop aar
uses: actions/upload-artifact@v2
with:
name: clickstream-event-visualiser-noop
path: clickstream-event-visualiser-noop/build/outputs/aar/**.aar

- name: Archive clickstream-event-visualiser-ui aar
uses: actions/upload-artifact@v2
with:
name: clickstream-event-visualiser-ui
path: clickstream-event-visualiser-ui/build/outputs/aar/**.aar

- name: Archive clickstream-event-visualiser-ui-noop aar
uses: actions/upload-artifact@v2
with:
name: clickstream-event-visualiser-ui-noop
path: clickstream-event-visualiser-ui-noop/build/outputs/aar/**.aar
11 changes: 10 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
:clickstream-health-metrics:assembleRelease
:clickstream-health-metrics-noop:assembleRelease
:clickstream-health-metrics-api:assembleRelease
:clickstream-event-interceptor:assemble
:clickstream-event-visualiser:assembleRelease
:clickstream-event-visualiser-noop:assembleRelease
:clickstream-event-visualiser-ui:assembleRelease
- name: Publish to MavenCentral
run: ./gradlew :clickstream:publishReleasePublicationToSonatypeRepository
:clickstream-api:publishReleasePublicationToSonatypeRepository
Expand All @@ -37,7 +41,12 @@ jobs:
:clickstream-util:publishReleasePublicationToSonatypeRepository
:clickstream-health-metrics:publishReleasePublicationToSonatypeRepository
:clickstream-health-metrics-noop:publishReleasePublicationToSonatypeRepository
:clickstream-health-metrics-api:publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
:clickstream-health-metrics-api:publishReleasePublicationToSonatypeRepository
:clickstream-event-interceptor:publishReleasePublicationToSonatypeRepository
:clickstream-event-visualiser:publishReleasePublicationToSonatypeRepository
:clickstream-event-visualiser-noop:publishReleasePublicationToSonatypeRepository
:clickstream-event-visualiser-ui:publishReleasePublicationToSonatypeRepository
:clickstream-event-visualiser-ui-noop:publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
Expand Down
79 changes: 78 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ dependencies {
// Required
implementation 'com.gojek.clickstream:clickstream-android:[latest_version]'
implementation 'com.gojek.clickstream:clickstream-lifecycle:[latest_version]'

// Optional
implementation 'com.gojek.clickstream:clickstream-health-metrics:[latest_version]'
}
Expand Down Expand Up @@ -218,6 +218,83 @@ In order to running the sample app, please follow this instruction
| ------ | ------ |
| <img src="https://github.com/gojekfarm/clickstream-android/blob/main/docs/assets/clickstream_sample_1.jpg" width="300"/> | <img src="https://github.com/gojekfarm/clickstream-android/blob/main/docs/assets/clickstream_sample_2.jpg" width="300"/> |

## Event Visualiser

Event visualiser is an android tool to visualise the client events being sent to Clickstream.

### Adding dependency
Add following to your module's `build.gradle`.
```kotlin
dependencies {
val latest_version = "x.y.z"
implementation("com.gojek.clickstream:clickstream-event-visualiser:$latest_version")
implementation("com.gojek.clickstream:clickstream-event-visualiser-ui:$latest_version")
}
```
### Initialising
1. In your Application class, add `CSEventVisualiserInterceptor` to Clickstream.
2. Call `CSEventVisualiserUI.initialise(this)` to initialise Event visualiser.
```kotlin
class App : Application() {
/**/
private fun initClickStream() {
ClickStream.initialize(/**/).apply {
/**/
addInterceptor(CSEventVisualiserInterceptor.getInstance())
}.build()
CSEventVisualiserUI.initialise(this)
}
}
```

### Usage
1. Call `CSEventVisualiserUI.getInstance().show()`to show a floating window and start recording all the events from clickstream.
<p align="center">
<img src="https://github.com/gojek/clickstream-android/blob/task/clickstream-ev-ui/docs/assets/ev_window.jpg" width="300"/>
</p>

2. Click on Settings icon (top-left corner) to show a bottom sheet with all the actions that you can take with event visualiser.
<p align="center">
<img src="https://github.com/gojek/clickstream-android/blob/task/clickstream-ev-ui/docs/assets/ev_actions.jpg" width="300"/>
</p>

- START CAPTURING (Starts event recording in event visualiser)
- STOP CAPTURING (Stops event recording in event visualiser)
- CLEAR DATA (Clears the current data in event visualiser)
- CLOSE (Closes the event visualiser window)

3. Clicking on the window will land to event home screen where all unique events are listed. You can click on any event to check event details.

4. Events can have the following states -
* Scheduled - Events are scheduled (cached locally) by clickstream.
* Dispatched - Events are sent to racoon.
* Acknowledged - Events are acknowledged by racoon.

<p align="center">
<img src="https://github.com/gojek/clickstream-android/blob/task/clickstream-ev-ui/docs/assets/ev_home.jpg" width="300"/>
<img src="https://github.com/gojek/clickstream-android/blob/task/clickstream-ev-ui/docs/assets/ev_event_list.jpg" width="300"/>
<img src="https://github.com/gojek/clickstream-android/blob/task/clickstream-ev-ui/docs/assets/ev_event_detail.jpg" width="300"/>
</p>

### Excluding Event visualiser from release builds
Since Event visualiser is a debug tool that will be used by developers and testing teams only, it should ideally **NOT** be bundled with release builds.
For this purpose there are light-weight, alternative NoOp (No Operation) dependencies.

#### Configuring NoOp dependency

```kotlin
dependencies {
val latest_version = "x.y.z"
// Use main dependency for debug build types
debugImplementation("com.gojek.clickstream:clickstream-event-visualiser:$latest_version")
debugImplementation("com.gojek.clickstream:clickstream-event-visualiser-ui:$latest_version")

// Use NoOp dependency for release build types
releaseImplementation("com.gojek.clickstream:clickstream-event-visualiser-noop:$latest_version")
releaseImplementation("com.gojek.clickstream:clickstream-event-visualiser-ui-noop:$latest_version")

}
```

License
--------
Expand Down
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,14 @@ dependencies {

// Clickstream
implementation(projects.clickstream)
implementation(projects.clickstreamEventVisualiser)
implementation(projects.clickstreamEventVisualiserUi)
implementation(files("$rootDir/libs/proto-consumer-1.18.6.jar"))

// Common
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.1")
implementation("androidx.core:core-ktx:1.5.0")
implementation("androidx.fragment:fragment-ktx:1.4.1")
implementation("androidx.appcompat:appcompat:1.1.0-rc01")
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.constraintlayout:constraintlayout:2.0.2")
Expand Down
20 changes: 15 additions & 5 deletions app/src/main/java/com/clickstream/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import clickstream.ClickStream
import clickstream.config.CSConfiguration
import clickstream.connection.CSConnectionEvent
import clickstream.connection.CSSocketConnectionListener
import clickstream.eventvisualiser.CSEventVisualiserInterceptor
import clickstream.eventvisualiser.ui.CSEventVisualiserUI
import clickstream.lifecycle.impl.DefaultCSAppLifeCycleObserver
import clickstream.logger.CSLogLevel
import com.clickstream.app.config.AccountId
Expand Down Expand Up @@ -36,22 +38,30 @@ class App : Application() {
),
appLifeCycle = DefaultCSAppLifeCycleObserver(this)
)
.applyLogLevel()
.applySocketConnectionListener()
.build()
.applyLogLevel()
.addCSEVInterceptor()
.applySocketConnectionListener()
.build()
)

CSEventVisualiserUI.initialise(this)
}

private fun CSConfiguration.Builder.applyLogLevel(): CSConfiguration.Builder {
setLogLevel(CSLogLevel.DEBUG)
return this
}

private fun CSConfiguration.Builder.addCSEVInterceptor(): CSConfiguration.Builder {
addInterceptor(CSEventVisualiserInterceptor.getInstance())
return this
}

private fun CSConfiguration.Builder.applySocketConnectionListener(): CSConfiguration.Builder {
setSocketConnectionListener(object : CSSocketConnectionListener {
override fun onEventChanged(event: CSConnectionEvent) {
when(event) {
is CSConnectionEvent.OnConnectionClosed -> printMessage { "OnConnectionClosed due to ${event.shutdownReason}"}
when (event) {
is CSConnectionEvent.OnConnectionClosed -> printMessage { "OnConnectionClosed due to ${event.shutdownReason}" }
is CSConnectionEvent.OnConnectionClosing -> printMessage { "OnConnectionClosing due to ${event.shutdownReason}" }
is CSConnectionEvent.OnConnectionConnected -> printMessage { "Connected" }
is CSConnectionEvent.OnConnectionConnecting -> printMessage { "Connecting" }
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/clickstream/app/main/MainFragment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.clickstream.app.main

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -9,6 +10,7 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle.State.STARTED
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import clickstream.eventvisualiser.ui.CSEventVisualiserUI
import com.clickstream.app.databinding.FragmentMainBinding
import com.clickstream.app.main.MainIntent.InputIntent
import com.clickstream.app.main.MainIntent.InputIntent.AgeInputIntent.Companion.setupAgeInputFlow
Expand All @@ -19,7 +21,9 @@ import com.clickstream.app.main.MainIntent.InputIntent.PhoneInputIntent.Companio
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import reactivecircus.flowbinding.android.view.clicks

/**
* A simple [Fragment] subclass as the default destination in the navigation.
Expand All @@ -45,13 +49,21 @@ class MainFragment : Fragment() {

registerObserver()
vm.processIntents(flows())
vm.processIntents(binding.sendEvent.clicks().map { MainIntent.SendIntent })
showEventVisualiser()
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

private fun showEventVisualiser() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CSEventVisualiserUI.getInstance().show()
}
}

private fun registerObserver() {
lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(STARTED) {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/clickstream/app/main/MainModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.clickstream.app.main

import clickstream.eventvisualiser.CSEVEventObserver
import clickstream.eventvisualiser.CSEventVisualiser
import com.clickstream.app.helper.Dispatcher
import dagger.Module
import dagger.Provides
Expand All @@ -23,4 +25,7 @@ internal object MainModule {
get() = Dispatchers.Main
}
}

@Provides
fun getEventVisualiser(): CSEVEventObserver = CSEventVisualiser
}
Loading

0 comments on commit 108d3e9

Please sign in to comment.