Skip to content

Commit

Permalink
Merge pull request #27 from crobox/feature/pageview-events
Browse files Browse the repository at this point in the history
Feature/pageview events
  • Loading branch information
toztemel authored Jul 24, 2024
2 parents 00f1db0 + a9b1951 commit 86bdf18
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 55 deletions.
82 changes: 81 additions & 1 deletion app/src/main/kotlin/com/crobox/sdk/testapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import com.crobox.sdk.common.LocaleCode
import com.crobox.sdk.config.CroboxConfig
import com.crobox.sdk.core.Crobox
import com.crobox.sdk.data.model.CartQueryParams
import com.crobox.sdk.data.model.CheckoutParams
import com.crobox.sdk.data.model.ClickQueryParams
import com.crobox.sdk.data.model.ErrorQueryParams
import com.crobox.sdk.data.model.PageType
import com.crobox.sdk.data.model.PageViewParams
import com.crobox.sdk.data.model.ProductParams
import com.crobox.sdk.data.model.PurchaseParams
import com.crobox.sdk.data.model.RequestQueryParams
import com.crobox.sdk.domain.PromotionsResponse
import com.crobox.sdk.presenter.PromotionCallback
Expand Down Expand Up @@ -66,7 +70,25 @@ class MainActivity : AppCompatActivity() {
)

// Sending Page View events
croboxInstance.pageViewEvent(indexPageParams)
croboxInstance.pageViewEvent(
indexPageParams,
PageViewParams(
pageTitle = "some page title",
product = ProductParams(
productId = "1",
price = 1.0,
quantity = 1,
otherProductIds = setOf("2", "3", "4")
),
searchTerms = "some search terms",
impressions = setOf(
ProductParams(productId = "5"),
ProductParams(productId = "6"),
ProductParams(productId = "7")
),
customProperties = mapOf(Pair("page-specific", "true"))
)
)

val detailPageParams = RequestQueryParams(
viewId = UUID.randomUUID(),
Expand Down Expand Up @@ -110,6 +132,64 @@ class MainActivity : AppCompatActivity() {
)
)

// Sending Checkout events
val checkoutPage = RequestQueryParams(
viewId = UUID.randomUUID(),
pageType = PageType.PageCheckout
)
// Sending Page View events
croboxInstance.checkoutEvent(
checkoutPage,
CheckoutParams(
products = setOf(
ProductParams(
productId = "1",
price = 1.0,
quantity = 1,
otherProductIds = setOf("3", "5", "7")
), ProductParams(
productId = "2",
price = 2.0,
quantity = 2,
otherProductIds = setOf("4", "6", "8")
)
),
step = "1",
customProperties = mapOf(Pair("page-specific", "true"))
)
)

// Sending Purchase Events
val pageComplete = RequestQueryParams(
viewId = UUID.randomUUID(),
pageType = PageType.PageComplete
)
// Sending Page View events
croboxInstance.purchaseEvent(
pageComplete,
PurchaseParams(
products = setOf(
ProductParams(
productId = "1",
price = 1.0,
quantity = 1,
otherProductIds = setOf("3", "5", "7")
), ProductParams(
productId = "2",
price = 2.0,
quantity = 2,
otherProductIds = setOf("4", "6", "8")
)
),
transactionId = "abc123",
affiliation = "google store",
coupon = "some coupon",
revenue = 5.0,
customProperties = mapOf(Pair("page-specific", "true"))
)
)


// A stub implementation for promotion response handling
val stubPromotionCallback = object : PromotionCallback {
val TAG = "PromotionCallback"
Expand Down
46 changes: 40 additions & 6 deletions sdk/src/main/kotlin/com/crobox/sdk/core/Crobox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ package com.crobox.sdk.core

import com.crobox.sdk.common.CroboxDebug
import com.crobox.sdk.config.CroboxConfig
import com.crobox.sdk.data.model.*
import com.crobox.sdk.data.model.CartQueryParams
import com.crobox.sdk.data.model.CheckoutParams
import com.crobox.sdk.data.model.ClickQueryParams
import com.crobox.sdk.data.model.CustomQueryParams
import com.crobox.sdk.data.model.ErrorQueryParams
import com.crobox.sdk.data.model.EventType
import com.crobox.sdk.data.model.PageType
import com.crobox.sdk.data.model.PageViewParams
import com.crobox.sdk.data.model.PurchaseParams
import com.crobox.sdk.data.model.RequestQueryParams
import com.crobox.sdk.presenter.CroboxAPIPresenter
import com.crobox.sdk.presenter.PromotionCallback

Expand Down Expand Up @@ -135,18 +144,43 @@ class Crobox private constructor(config: CroboxConfig) {
* @param queryParams Common query parameters, shared by the requests sent from the same page view
* @param pageViewParams Event specific query parameters for Page View Events
*/
fun pageViewEvent(
queryParams: RequestQueryParams,
pageViewParams: PageViewParams? = null
) {
fun pageViewEvent(queryParams: RequestQueryParams, pageViewParams: PageViewParams? = null) {
presenter.event(
eventType = EventType.PageView,
queryParams = queryParams,
additionalParams = pageViewParams
)
}

/**
/**
* For reporting checkout events
*
* @param queryParams Common query parameters, shared by the requests sent from the same page view
* @param checkoutParams Event specific query parameters for Checkout Events
*/
fun checkoutEvent(queryParams: RequestQueryParams, checkoutParams: CheckoutParams) {
presenter.event(
eventType = EventType.Checkout,
queryParams = queryParams,
additionalParams = checkoutParams
)
}

/**
* For reporting purchase events
*
* @param queryParams Common query parameters, shared by the requests sent from the same page view
* @param purchaseParams Event specific query parameters for Purchase Events
*/
fun purchaseEvent(queryParams: RequestQueryParams, purchaseParams: PurchaseParams) {
presenter.event(
eventType = EventType.Purchase,
queryParams = queryParams.copy(pageType = PageType.PageComplete),
additionalParams = purchaseParams
)
}

/**
* For reporting custom events
*
* @param queryParams Common query parameters, shared by the requests sent from the same page view
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.crobox.sdk.data.model

import java.util.*
import java.util.UUID
import java.util.concurrent.atomic.AtomicInteger

/**
Expand Down Expand Up @@ -32,11 +32,13 @@ enum class PageType(val value: Int) {
PageSearch(7);
}

enum class EventType(val type: String) {
enum class EventType(internal val type: String) {
Click("click"), // Click
AddCart("cart"), // Add to Shopping Cart
RemoveCart("rmcart"), // Remove from Shopping Cart
PageView("pageview"), // PageView
Checkout("pageview"), // PageView
Purchase("pageview"), // PageView
Error("error"), // Error
CustomEvent("event") // CustomEvent
}
Expand Down Expand Up @@ -103,11 +105,65 @@ data class CustomQueryParams(
)

/**
* Type specific parameters for general-purpose Custom events
*
* @param name Event name
* Type specific parameters for Page View events
*
* @param pageTitle Optional Page title
* @param product Optional product specific parameters
* @param searchTerms Optional search terms that led the viewer to this product
* @param impressions Optional list of products that are viewed in the same page
* @param customProperties Optional set of general purpose custom properties, for example to help identifying certain traits of the page
*/
data class PageViewParams(
val name: String? = null
val pageTitle: String? = null,
val product: ProductParams? = null,
val searchTerms: String? = null,
val impressions: Set<ProductParams>? = null,
val customProperties: Map<String, String>? = emptyMap()
)

/**
* Type specific parameters for Purchase events
*
* @param products Optional set of products purchased
* @param transactionId Optional transaction identifier
* @param affiliation Optional store or affiliation from which this transaction occurred (e.g. Google Store)
* @param coupon Optional coupon
* @param revenue Optional the total associated with the transaction
* @param customProperties Optional set of general purpose custom properties, for example to help identifying certain traits of the page
*/
data class PurchaseParams(
val products: Set<ProductParams>? = null,
val transactionId: String? = null,
val affiliation: String? = null,
val coupon: String? = null,
val revenue: Double? = null,
val customProperties: Map<String, String>? = emptyMap()
)

/**
* Type specific parameters for Checkout events
*
* @param products Optional set of products to be purchased
* @param step Optional number representing a step in the checkout process
* @param customProperties Optional set of general purpose custom properties, for example to help identifying certain traits of the page
*/
data class CheckoutParams(
val products: Set<ProductParams>? = null,
val step: String? = null,
val customProperties: Map<String, String>? = emptyMap()
)

/**
* Product specific parameters for various events
*
* @param productId Product identifier
* @param price Optional Product price
* @param quantity Optional quantity
* @param otherProductIds Optional set of accompanying productIds which this particular product belongs to
*/
data class ProductParams(
val productId: String,
val price: Double? = null,
val quantity: Int? = null,
val otherProductIds: Set<String>? = emptySet()
)
Loading

0 comments on commit 86bdf18

Please sign in to comment.