Skip to content

Commit

Permalink
[feat]: add new added events
Browse files Browse the repository at this point in the history
  • Loading branch information
NoMoreViolence committed Dec 19, 2024
1 parent 3852cf1 commit feee1ce
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 68 deletions.
11 changes: 5 additions & 6 deletions BluxClient/Classes/BluxClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,14 @@ struct PropertiesWrapper<T: Codable>: Codable {
}
}

public static func sendRequestData(_ data: [Event]) {
EventService.sendRequest(data)
InappService.handleInappEvent(data)
public static func sendRequestData(_ events: [Event]) {
EventService.sendRequest(events)
InappService.handleInappEvent(events)
}

/// Send Request
public static func sendRequest(_ request: EventRequest) {
let requestData = request.getPayload()
sendRequestData(requestData)
public static func sendRequest(_ eventRequest: EventRequest) {
sendRequestData(eventRequest.getPayload())
}

/// Set the handler when notification is clicked
Expand Down
2 changes: 1 addition & 1 deletion BluxClient/Classes/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Tommy on 6/4/24.
//
import UIKit
import WebKit
@preconcurrency import WebKit

@available(iOSApplicationExtension, unavailable)
final class WebViewController: UIViewController, WKNavigationDelegate,
Expand Down
12 changes: 6 additions & 6 deletions BluxClient/Classes/request/events/AddCartaddEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ public class AddCartaddEvent: EventRequest {

init(builder: Builder) throws {
super.init()
self.events.append(
try Event(eventType: builder.eventType)
try self.events.append(
Event(eventType: builder.eventType)
.setItemId(builder.itemId)
.setCustomEventProperties(builder.customEventProperties)
)
}

public class Builder {
var itemId: String
var eventType: String = AddCartaddEvent.DEFAULT_EVENT_TYPE
var customEventProperties: [String: String]? = nil
fileprivate let eventType: String = AddCartaddEvent.DEFAULT_EVENT_TYPE

fileprivate var itemId: String
fileprivate var customEventProperties: [String: String]? = nil

public init(itemId: String) {
self.itemId = itemId
Expand All @@ -31,4 +32,3 @@ public class AddCartaddEvent: EventRequest {
}
}
}

12 changes: 9 additions & 3 deletions BluxClient/Classes/request/events/AddCustomEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ public class AddCustomEvent: EventRequest {
}

public class Builder {
var itemId: String?
var eventType: String
var customEventProperties: [String: String]? = nil
fileprivate let eventType: String

fileprivate var itemId: String?
fileprivate var customEventProperties: [String: String]? = nil

public init(eventType: String) {
self.eventType = eventType
}

public func itemId(_ itemId: String) -> Builder {
self.itemId = itemId
return self
}

public func customEventProperties(
_ customEventProperties: [String: String]
) -> Builder {
Expand Down
50 changes: 50 additions & 0 deletions BluxClient/Classes/request/events/AddInstantImpression.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Foundation

public class AddInstantImpressionEvent: EventRequest {
private static let DEFAULT_EVENT_TYPE = "instant_impression"

init(builder: Builder) throws {
super.init()
try self.events.append(
Event(eventType: builder.eventType)
.setItemId(builder.itemId)
.setPage(builder.page)
.setSection(builder.section)
.setPosition(builder.position)
.setRecommendationId(builder.recommendationId ?? "")
.setCustomEventProperties(builder.customEventProperties ?? [:])
)
}

public class Builder {
fileprivate let eventType: String = DEFAULT_EVENT_TYPE
fileprivate let itemId: String
fileprivate let page: String
fileprivate let section: String
fileprivate let position: Double

fileprivate var recommendationId: String? = nil
fileprivate var customEventProperties: [String: String]? = nil

public init(itemId: String, page: String, section: String, position: Double) {
self.itemId = itemId
self.page = page
self.section = section
self.position = position
}

public func recommendationId(_ recommendationId: String) -> Builder {
self.recommendationId = recommendationId
return self
}

public func customEventProperties(_ customEventProperties: [String: String]) -> Builder {
self.customEventProperties = customEventProperties
return self
}

public func build() throws -> AddInstantImpressionEvent {
return try AddInstantImpressionEvent(builder: self)
}
}
}
12 changes: 6 additions & 6 deletions BluxClient/Classes/request/events/AddLikeEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ public class AddLikeEvent: EventRequest {

init(builder: Builder) throws {
super.init()
self.events.append(
try Event(eventType: builder.eventType)
try self.events.append(
Event(eventType: builder.eventType)
.setItemId(builder.itemId)
.setCustomEventProperties(builder.customEventProperties)
)
}

public class Builder {
var itemId: String
var eventType: String = AddLikeEvent.DEFAULT_EVENT_TYPE
var customEventProperties: [String: String]? = nil
fileprivate let eventType: String = DEFAULT_EVENT_TYPE
fileprivate let itemId: String

fileprivate var customEventProperties: [String: String]? = nil

public init(itemId: String) {
self.itemId = itemId
Expand All @@ -31,4 +32,3 @@ public class AddLikeEvent: EventRequest {
}
}
}

17 changes: 8 additions & 9 deletions BluxClient/Classes/request/events/AddPageViewEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ public class AddPageViewEvent: EventRequest {

init(builder: Builder) throws {
super.init()
self.events.append(
try Event(eventType: builder.eventType)
.setPage(builder.page)
.setCustomEventProperties(builder.customEventProperties)
try self.events.append(
Event(eventType: builder.eventType)
.setPage(builder.page)
.setCustomEventProperties(builder.customEventProperties)
)
}

public class Builder {
var eventType: String = AddPageViewEvent.DEFAULT_EVENT_TYPE
var page: String
var customEventProperties: [String: String]? = nil
fileprivate let eventType: String = DEFAULT_EVENT_TYPE
fileprivate let page: String

fileprivate var customEventProperties: [String: String]? = nil

public init(page: String) {
self.page = page
}


public func customEventProperties(_ customEventProperties: [String: String]) -> Builder {
self.customEventProperties = customEventProperties
return self
Expand All @@ -32,4 +32,3 @@ public class AddPageViewEvent: EventRequest {
}
}
}

30 changes: 30 additions & 0 deletions BluxClient/Classes/request/events/AddPageVisitEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation

public class AddPageVisitEvent: EventRequest {
private static let DEFAULT_EVENT_TYPE: String = "page_visit"

init(builder: Builder) throws {
super.init()
self.events.append(
Event(eventType: builder.eventType)
.setCustomEventProperties(builder.customEventProperties)
)
}

public class Builder {
fileprivate let eventType: String = DEFAULT_EVENT_TYPE

fileprivate var customEventProperties: [String: String]? = nil

public init() {}

public func customEventProperties(_ customEventProperties: [String: String]) -> Builder {
self.customEventProperties = customEventProperties
return self
}

public func build() throws -> AddPageVisitEvent {
return try AddPageVisitEvent(builder: self)
}
}
}
50 changes: 50 additions & 0 deletions BluxClient/Classes/request/events/AddPersistentImpression.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Foundation

public class AddPersistentImpressionEvent: EventRequest {
private static let DEFAULT_EVENT_TYPE = "persistent_impression"

init(builder: Builder) throws {
super.init()
try self.events.append(
Event(eventType: builder.eventType)
.setItemId(builder.itemId)
.setPage(builder.page)
.setSection(builder.section)
.setPosition(builder.position)
.setRecommendationId(builder.recommendationId ?? "")
.setCustomEventProperties(builder.customEventProperties ?? [:])
)
}

public class Builder {
fileprivate let eventType: String = DEFAULT_EVENT_TYPE
fileprivate let itemId: String
fileprivate let page: String
fileprivate let section: String
fileprivate let position: Double

fileprivate var recommendationId: String? = nil
fileprivate var customEventProperties: [String: String]? = nil

public init(itemId: String, page: String, section: String, position: Double) {
self.itemId = itemId
self.page = page
self.section = section
self.position = position
}

public func recommendationId(_ recommendationId: String) -> Builder {
self.recommendationId = recommendationId
return self
}

public func customEventProperties(_ customEventProperties: [String: String]) -> Builder {
self.customEventProperties = customEventProperties
return self
}

public func build() throws -> AddPersistentImpressionEvent {
return try AddPersistentImpressionEvent(builder: self)
}
}
}
37 changes: 29 additions & 8 deletions BluxClient/Classes/request/events/AddProductDetailViewEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,44 @@ public class AddProductDetailViewEvent: EventRequest {

init(builder: Builder) throws {
super.init()
self.events.append(
try Event(eventType: builder.eventType)
.setItemId(builder.itemId)
.setCustomEventProperties(builder.customEventProperties)
try self.events.append(
Event(eventType: builder.eventType)
.setItemId(builder.itemId)
.setPrevPage(builder.prevPage)
.setPrevSection(builder.prevSection)
.setRecommendationId(builder.recommendationId)
.setCustomEventProperties(builder.customEventProperties)
)
}

public class Builder {
var itemId: String
var eventType: String = AddProductDetailViewEvent.DEFAULT_EVENT_TYPE
var customEventProperties: [String: String]? = nil
fileprivate let eventType: String = AddProductDetailViewEvent.DEFAULT_EVENT_TYPE
fileprivate let itemId: String

fileprivate var prevPage: String? = nil
fileprivate var prevSection: String? = nil
fileprivate var recommendationId: String? = nil
fileprivate var customEventProperties: [String: String]? = nil

public init(itemId: String) {
self.itemId = itemId
}

public func prevPage(_ prevPage: String) -> Builder {
self.prevPage = prevPage
return self
}

public func prevSection(_ prevSection: String) -> Builder {
self.prevSection = prevSection
return self
}

public func recommendationId(_ recommendationId: String) -> Builder {
self.recommendationId = recommendationId
return self
}

public func customEventProperties(_ customEventProperties: [String: String]) -> Builder {
self.customEventProperties = customEventProperties
return self
Expand All @@ -31,4 +53,3 @@ public class AddProductDetailViewEvent: EventRequest {
}
}
}

16 changes: 6 additions & 10 deletions BluxClient/Classes/request/events/AddPurchaseEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@ public class AddPurchaseEvent: EventRequest {
}

public class Builder {
var events: [Event] = []
var eventType: String = AddPurchaseEvent.DEFAULT_EVENT_TYPE
var customEventProperties: [String: String]? = nil
fileprivate var events: [Event] = []

public init() {

}
public init() {}

public func addPurchase(itemId: String, price: Double, quantity: Int, customEventProperties: [String: String]? = nil) throws -> Builder {
guard (quantity > 0) else {
public func addPurchase(itemId: String, price: Double, quantity: Int, orderId: String? = nil, customEventProperties: [String: String]? = nil) throws -> Builder {
guard quantity > 0 else {
throw BluxError.InvalidQuantity
}

var customEventPropertiesWithQuantity = customEventProperties ?? [:]
customEventPropertiesWithQuantity["quantity"] = "\(quantity)"

let event = try Event(eventType: eventType)
let event = try Event(eventType: DEFAULT_EVENT_TYPE)
.setItemId(itemId)
.setPrice(price * Double(quantity))
.setOrderId(orderId)
.setCustomEventProperties(customEventPropertiesWithQuantity)

self.events.append(event)
Expand All @@ -39,4 +36,3 @@ public class AddPurchaseEvent: EventRequest {
}
}
}

Loading

0 comments on commit feee1ce

Please sign in to comment.