ClickStream是事件不可知论,实时数据摄入平台。 ClickStream允许应用程序维护长期运行的连接以实时发送数据。
“ clickstream”一词是用户在网站或移动应用程序中单击的方式留下的数字面包屑的踪迹。它充满了企业的宝贵客户信息,其分析和用法已成为强大的数据源。
要了解有关ClickStream的更多信息,您可以阅读我们的媒介帖子
ClickStream为事件摄入提供了最终解决方案。要设置后端基础设施,请查看浣熊


build.gradle您的项目的gradle。 buildscript {
repositories {
mavenCentral()
}
}build.gradle dependencies {
val version = " x.y.z "
// 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] '
}默认情况下,ClickStream嵌入了规则,因此不需要明确添加规则
-keep class * extends com.google.protobuf.GeneratedMessageLite { *; }
# Scarlet
-if interface * { @com.tinder.scarlet.ws.* <methods>; }
-keep,allowobfuscation interface <1>
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@com.tinder.scarlet.ws.* <methods>;
}
# Keep the ProcessLifecycleInitializer meta
-keepresourcexmlelements manifest/application/provider/meta-data@name=androidx.lifecycle.ProcessLifecycleInitializer
-keepresourcexmlelements manifest/application/provider/meta-data@value=androidx.startup
添加依赖项并同步您的Gradle项目后,下一步就是初始化ClickStream。
可以在背景线程或主线程上完成clickstream的初始化,应在应用程序类上进行调用。因此初始化仅发生一次。
要创建ClickStream实例,您可以执行以下设置:
class App : Application () {
override fun onCreate () {
initClickStream()
}
private fun initClickStream () {
ClickStream .initialize(
configuration = CSConfiguration . Builder (
context = context,
info = CSInfo (
appInfo = appInfo,
locationInfo = locationInfo,
deviceInfo = csDeviceInfo,
customerInfo = customerInfo,
sessionInfo = sessionInfo
),
config = getBuildConfig(config),
appLifeCycle = DefaultCSAppLifeCycleObserver (context),
healthGateway = DefaultOpCSHealthGateway .factory( /* args */ )
). apply {
setLogLevel( DEBUG )
/* */
setCSSocketConnectionListener(connectionListener())
}.build())
}
/* *
* @see [CSConnectionEvent] for more detail explanation
*/
private fun onConnectionListener (): CSSocketConnectionListener {
return object : CSSocketConnectionListener {
override fun onEventChanged ( event : CSConnectionEvent ) {
is OnConnectionConnecting -> {}
is OnConnectionConnected -> {}
is OnMessageReceived -> {}
is OnConnectionClosing -> {}
is OnConnectionClosed -> {}
is OnConnectionFailed -> {}
}
}
}
}保留ClickStream的配置。这些约束可以对库行为进行细粒度的控制,例如重试持续时间,应用程序在后台时的冲洗事件,等等。
| 描述 | 多变的 | 类型 | 默认值 |
|---|---|---|---|
| 在单个请求中结合的事件数量 | EventsPerbatch | int | 20 |
| 在两个请求之间延迟(以毫升为单位) | Batchperiod | 长的 | 10000 |
| 标志以实现强迫冲洗事件 | Flushonbackground | 布尔 | 错误的 |
| 等待插座断开的时间 | ConnectionTermertinationTimerWaittimeinmillis | 长的 | 5000 |
| 通过背景任务启用事件冲洗的标志 | BackowdTaskEnabled | 布尔 | 错误的 |
| 背景任务的初始延迟(以小时为单位) | Workrequestdelayinhr | 长的 | 1 |
保留有关网络相关的配置。例如,为网络渠道配置超时。
| 描述 | 多变的 | 类型 | 默认值 |
|---|---|---|---|
| Web插座服务器的端点 | 端点 | 细绳 | 没有默认值 |
| 连接okhttp使用的超时(以秒为单位) | ConnectTimeOut | 长的 | 10 |
| 读取OKHTTP使用的超时(秒) | ReadTimeOut | 长的 | 10 |
| 写入超时,要由Okhttp使用(以秒为单位) | writeTimeout | 长的 | 10 |
| 客户端发起的ping之间的间隔(以秒为单位) | pinginterval | 长的 | 1 |
| 最初的重试持续时间用于重试退向策略(以毫秒为单位) | 初始放电 | 长的 | 1000 |
| 重试退回策略的最大重试持续时间(以毫秒为单位) | maxConnectionRetryDurationm | 长的 | 6000 |
| 每个批次请求的最大检索 | maxRetriesperbatch | 长的 | 20 |
| 接收ACK请求的最大超时(以毫秒为单位) | MaxRequestAckTimeOut | 长的 | 10000 |
| 从客户端传递的okhttpclient实例 | OkhttpClient | OkhttpClient | 没有默认值 |
将班级名称保存为InstantEvent(QoS)或RealtimeEvent(QOS1)。
| 描述 | 多变的 | 类型 | 默认值 |
|---|---|---|---|
| 持有所有事件类型 | 事件类型 | 事件切割机 | [EventClassifier(标识符:“实时”,EventNames:[]),EventClassifier(标识符:“ Instant”,EventNames:[])] |
例如,在用户登录应用程序时,可以调用ClickStream的销毁实例。
ClickStream .release()由于ClickStream在客户端使用触发定义时,您可以构建Messagelite并直接通过ClickStreamSDK发送。
例如,您已经定义了一个名为Rating.java的原始定义,该定义具有以下属性
rating: Float
reason: String
因此,我们只能通过使用构建器模式来构建评级对象。
val event = Rating .newBuilder()
.setRating( 4.5 )
.setReason( " nice! " )
.build()
// wrap event in CSEvent
val csEvent = CSEvent (
guid = UUID .randomUUID().toString(),
timestamp = Timestamp .getDefaultInstance(),
message = event
)
// track the event
ClickStream .getInstance().trackEvent(csEvent)恭喜!你完成了!
为了运行示例应用程序,请遵循此说明
./gradlew :app:installDebug或通过Android Studio中的播放按钮| 图1 | 图2 |
|---|---|
![]() | ![]() |
Event Visualiser是一种可视化发送到ClickStream的客户端事件的Android工具。
添加以下内容到模块的build.gradle中。
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 " )
}CSEventVisualiserListener添加到ClickStream。CSEventVisualiserUI.initialise(this)以初始事件可视化器。 class App : Application () {
/* */
private fun initClickStream () {
ClickStream .initialize( /* */ ). apply {
/* */
addEventListener( CSEventVisualiserListener .getInstance())
}.build()
CSEventVisualiserUI .initialise( this )
}
}CSEventVisualiserUI.getInstance().show()显示浮动窗口,然后开始录制从clickstream中录制所有事件。 

单击窗口将降落到列出所有唯一事件的活动主屏幕。您可以单击任何事件以检查事件详细信息。
事件可以具有以下状态 -



由于事件可视化器是一种调试工具,只能由开发人员和测试团队使用,因此理想情况下,它不应与发布版本捆绑在一起。
为此,有轻重量的替代NOOP(无操作)依赖性。
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 " )
} Copyright 2022 GOJEK
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.