Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions sdk/src/main/kotlin/com/crobox/sdk/core/Crobox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class Crobox private constructor(config: CroboxConfig) {
presenter.event(
eventType = EventType.Click,
queryParams = queryParams,
additionalParams = clickQueryParams
additionalParams = clickQueryParams,
errorQueryParams = ErrorQueryParams("sdk", "click")
)
}

Expand All @@ -99,7 +100,8 @@ class Crobox private constructor(config: CroboxConfig) {
presenter.event(
eventType = EventType.AddCart,
queryParams = queryParams,
additionalParams = cartQueryParams
additionalParams = cartQueryParams,
errorQueryParams = ErrorQueryParams("sdk", "addcart")
)
}

Expand All @@ -116,7 +118,8 @@ class Crobox private constructor(config: CroboxConfig) {
presenter.event(
eventType = EventType.RemoveCart,
queryParams = queryParams,
additionalParams = cartQueryParams
additionalParams = cartQueryParams,
errorQueryParams = ErrorQueryParams("sdk", "rmcart")
)
}

Expand Down Expand Up @@ -148,7 +151,8 @@ class Crobox private constructor(config: CroboxConfig) {
presenter.event(
eventType = EventType.PageView,
queryParams = queryParams,
additionalParams = pageViewParams
additionalParams = pageViewParams,
errorQueryParams = ErrorQueryParams("sdk", "pageview")
)
}

Expand All @@ -162,7 +166,8 @@ class Crobox private constructor(config: CroboxConfig) {
presenter.event(
eventType = EventType.Checkout,
queryParams = queryParams,
additionalParams = checkoutParams
additionalParams = checkoutParams,
errorQueryParams = ErrorQueryParams("sdk", "checkout")
)
}

Expand All @@ -176,7 +181,8 @@ class Crobox private constructor(config: CroboxConfig) {
presenter.event(
eventType = EventType.Purchase,
queryParams = queryParams.copy(pageType = PageType.PageComplete),
additionalParams = purchaseParams
additionalParams = purchaseParams,
errorQueryParams = ErrorQueryParams("sdk", "purchase")
)
}

Expand All @@ -193,7 +199,8 @@ class Crobox private constructor(config: CroboxConfig) {
presenter.event(
eventType = EventType.CustomEvent,
queryParams = queryParams,
additionalParams = customQueryParams
additionalParams = customQueryParams,
errorQueryParams = ErrorQueryParams("sdk", "custom")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ enum class EventType(internal val type: String) {
data class ErrorQueryParams(
val tag: String? = null,
val name: String? = null,
val message: String? = null,
var message: String? = null,
val file: String? = null,
val line: Int? = null,
)
Expand Down
39 changes: 35 additions & 4 deletions sdk/src/main/kotlin/com/crobox/sdk/presenter/CroboxAPIPresenter.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.crobox.sdk.presenter

import com.crobox.sdk.BuildConfig
import com.crobox.sdk.common.CroboxDebug
import com.crobox.sdk.common.CroboxEncoder
import com.crobox.sdk.config.CroboxConfig
Expand Down Expand Up @@ -69,7 +70,8 @@ internal class CroboxAPIPresenter(private val config: CroboxConfig) {
}

fun event(
eventType: EventType, queryParams: RequestQueryParams, additionalParams: Any?
eventType: EventType, queryParams: RequestQueryParams, additionalParams: Any?,
errorQueryParams: ErrorQueryParams? = null
) {

val parameters = eventQuery(queryParams, additionalParams, eventType)
Expand All @@ -81,19 +83,48 @@ internal class CroboxAPIPresenter(private val config: CroboxConfig) {
) {
try {
if (!response.isSuccessful) {
CroboxDebug.eventError(response.body().toString())
notifyError(eventType, queryParams, errorQueryParams, response.body().toString())
}
} catch (ex: Exception) {
CroboxDebug.eventError(response.body().toString())
notifyError(
eventType,
queryParams,
errorQueryParams,
response.body().toString()
)
}
}

override fun onFailure(call: Call<Void?>, t: Throwable) {
CroboxDebug.eventError(t.message.toString())
notifyError(
eventType,
queryParams,
errorQueryParams,
t.message.toString()
)
}
})
}

private fun notifyError(
eventType: EventType, queryParams: RequestQueryParams,
errorQueryParams: ErrorQueryParams?,
message: String
) {
if (eventType == EventType.Error) {
return; //We don't want to have error loop cycle
}
if (BuildConfig.DEBUG) {
CroboxDebug.eventError(message)
}
if(errorQueryParams != null) errorQueryParams.message = message
event(
eventType = EventType.Error,
queryParams = queryParams,
additionalParams = errorQueryParams
)
}

private fun eventQuery(
queryParams: RequestQueryParams, additionalParams: Any?, eventType: EventType
): Map<String, Any> {
Expand Down