Skip to content

Commit

Permalink
Merge pull request #20 from airrobe/eli/eventRenaming
Browse files Browse the repository at this point in the history
couple of fixes
  • Loading branch information
creative-dev-lab authored Jun 6, 2022
2 parents e664343 + e1e95e0 commit 6ad679e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 37 deletions.
8 changes: 3 additions & 5 deletions AirRobeDemo/AirRobeDemo/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, AirRobeEventDelegate {
print("confirmation rendered")
case .confirmationClick:
print("claim link click")
case .other:
print("other")
}

switch event.page_name {
Expand All @@ -58,9 +56,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, AirRobeEventDelegate {
// Initialize AirRobeWidget with appId and privacy policy link for The Iconic
AirRobeWidget.initialize(
config: AirRobeWidgetConfig(
appId: "c43f2be28f1f",
privacyPolicyURL: "https://www.theiconic.com.au/privacy-policy",
mode: .production
appId: "515b6ee129da",
privacyPolicyURL: "https://www.example.com/privacy-policy",
mode: .sandbox
)
)
AirRobeWidget.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ final class ProductPageViewController: UIViewController {

// Initialize airRobeOptIn view
airRobeOptIn.initialize(
brand: "Gucci",
material: "Leather",
category: cellViewModel.category,
department: "Womenswear",
priceCents: Double(String(cellViewModel.price.replacingOccurrences(of: "$", with: ""))) ?? 0.0
)

Expand Down
10 changes: 9 additions & 1 deletion Sources/AirRobeWidget/Config/AirRobeWidgetConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ public enum EventName: String {
case popupClose = "airrobe-widget-popup-close"
case confirmationRender = "airrobe-confirmation-render"
case confirmationClick = "airrobe-confirmation-click"
case other = "Other"
}

public enum TelemetryEventName: String {
case pageView = "pageview"
case optIn = "Opted in to AirRobe"
case optOut = "Opted out of AirRobe"
case expand = "Widget Expand Arrow Click"
case popupOpen = "Pop up click"
case confirmationClick = "Claim link click"
}

public enum PageName: String {
Expand Down
18 changes: 16 additions & 2 deletions Sources/AirRobeWidget/Service/AirRobeApiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,22 @@ final class AirRobeApiService: AirRobeNetworkClient {
return execute(endpoint.asURLRequest(), decodingType: AirRobeEmailCheckResponseModel.self)
}

func telemetryEvent(eventName: String, pageName: String) -> AnyPublisher<AirRobeTelemetryEventResponseModel, Error> {
var endpoint = AirRobeEndpoint.telemetryEvent(eventName: eventName, pageName: pageName)
func telemetryEvent(
eventName: String,
pageName: String,
brand: String? = nil,
material: String? = nil,
category: String? = nil,
department: String? = nil
) -> AnyPublisher<AirRobeTelemetryEventResponseModel, Error> {
var endpoint = AirRobeEndpoint.telemetryEvent(
eventName: eventName,
pageName: pageName,
brand: brand,
material: material,
category: category,
department: department
)
endpoint.requestBody = endpoint.requestBody.merging(additionalRequestBodyParams) { (current, _) in current }
#if DEBUG
dump(endpoint.asURLRequest())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ extension AirRobeEndpoint {
)
}

static func telemetryEvent(eventName: String, pageName: String) -> AirRobeEndpoint {
static func telemetryEvent(
eventName: String,
pageName: String,
brand: String? = nil,
material: String? = nil,
category: String? = nil,
department: String? = nil
) -> AirRobeEndpoint {
let requestBody: [String: Any] = [
"app_id": configuration?.appId ?? "",
"anonymous_id": UIDevice.current.identifierForVendor?.uuidString ?? "",
Expand All @@ -47,7 +54,11 @@ extension AirRobeEndpoint {
"source": AirRobeWidgetInfo.platform,
"version": AirRobeWidgetInfo.version,
"split_test_variant": "default",
"page_name": pageName
"page_name": pageName,
"brand": brand,
"material": material,
"category": category,
"department": department
]
]
return AirRobeEndpoint(
Expand Down
31 changes: 16 additions & 15 deletions Sources/AirRobeWidget/Utils/AirRobeUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ struct AirRobeUtils {
}
}

static func telemetryEvent(eventName: String, pageName: String) {
static func telemetryEvent(
eventName: String,
pageName: String,
brand: String? = nil,
material: String? = nil,
category: String? = nil,
department: String? = nil
) {
let apiService = AirRobeApiService()

let eventData = AirRobeEventData(
app_id: configuration?.appId ?? "",
anonymous_id: UIDevice.current.identifierForVendor?.uuidString ?? "",
session_id: sessionId,
event_name: EventName.init(rawValue: eventName) ?? .other,
source: AirRobeWidgetInfo.platform,
version: AirRobeWidgetInfo.version,
split_test_variant: "default",
page_name: PageName.init(rawValue: pageName) ?? .other
cancellable = apiService.telemetryEvent(
eventName: eventName,
pageName: pageName,
brand: brand,
material: material,
category: category,
department: department
)

cancellable = apiService.telemetryEvent(eventName: eventName, pageName: pageName)
.sink(receiveCompletion: { completion in
switch completion {
case .failure(let error):
Expand All @@ -58,7 +60,6 @@ struct AirRobeUtils {
}
}, receiveValue: {
print("Telemetry Event Succeed:", $0)
delegate?.onEventEmitted(event: eventData)
})
print("Telemetry Event => event: " + eventName + ", pageName: " + pageName)
}
Expand All @@ -68,7 +69,7 @@ struct AirRobeUtils {
app_id: configuration?.appId ?? "",
anonymous_id: UIDevice.current.identifierForVendor?.uuidString ?? "",
session_id: sessionId,
event_name: EventName.init(rawValue: eventName) ?? .other,
event_name: EventName.init(rawValue: eventName)!,
source: AirRobeWidgetInfo.platform,
version: AirRobeWidgetInfo.version,
split_test_variant: "default",
Expand Down
24 changes: 16 additions & 8 deletions Sources/AirRobeWidget/Views/OptInView/AirRobeOptInView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ final class AirRobeOptInView: UIView, NibLoadable {
alert.viewType = viewType
vc.present(alert, animated: true)
if viewType == .optIn {
AirRobeUtils.telemetryEvent(eventName: EventName.popupOpen.rawValue, pageName: PageName.product.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.popupOpen.rawValue, pageName: PageName.product.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.popupOpen.rawValue, pageName: PageName.product.rawValue)
} else {
AirRobeUtils.telemetryEvent(eventName: EventName.popupOpen.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.popupOpen.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.popupOpen.rawValue, pageName: PageName.cart.rawValue)
}
}

Expand All @@ -135,15 +137,19 @@ final class AirRobeOptInView: UIView, NibLoadable {
UserDefaults.standard.OptedIn = sender.isOn
if sender.isOn {
if viewType == .optIn {
AirRobeUtils.telemetryEvent(eventName: EventName.optIn.rawValue, pageName: PageName.product.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.optIn.rawValue, pageName: PageName.product.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.optIn.rawValue, pageName: PageName.product.rawValue)
} else {
AirRobeUtils.telemetryEvent(eventName: EventName.optIn.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.optIn.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.optIn.rawValue, pageName: PageName.cart.rawValue)
}
} else {
if viewType == .optIn {
AirRobeUtils.telemetryEvent(eventName: EventName.optOut.rawValue, pageName: PageName.product.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.optOut.rawValue, pageName: PageName.product.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.optOut.rawValue, pageName: PageName.product.rawValue)
} else {
AirRobeUtils.telemetryEvent(eventName: EventName.optOut.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.optOut.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.optOut.rawValue, pageName: PageName.cart.rawValue)
}
}
}
Expand All @@ -162,9 +168,11 @@ final class AirRobeOptInView: UIView, NibLoadable {
case .closed:
expandType = .opened
if viewType == .optIn {
AirRobeUtils.telemetryEvent(eventName: EventName.expand.rawValue, pageName: PageName.product.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.expand.rawValue, pageName: PageName.product.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.expand.rawValue, pageName: PageName.product.rawValue)
} else {
AirRobeUtils.telemetryEvent(eventName: EventName.expand.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.expand.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.expand.rawValue, pageName: PageName.cart.rawValue)
}
return 1.0
}
Expand Down
13 changes: 11 additions & 2 deletions Sources/AirRobeWidget/Views/OptInView/AirRobeOptInViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ final class AirRobeOptInViewModel {
return
}
if !alreadyInitialized {
AirRobeUtils.telemetryEvent(eventName: EventName.pageView.rawValue, pageName: PageName.product.rawValue)
AirRobeUtils.telemetryEvent(
eventName: TelemetryEventName.pageView.rawValue,
pageName: PageName.product.rawValue,
brand: brand,
material: material,
category: category,
department: department
)
AirRobeUtils.dispatchEvent(eventName: EventName.pageView.rawValue, pageName: PageName.product.rawValue)
alreadyInitialized = true
if category.isEmpty {
isAllSet = .paramIssue
Expand All @@ -75,7 +83,8 @@ final class AirRobeOptInViewModel {
return
}
if !alreadyInitialized {
AirRobeUtils.telemetryEvent(eventName: EventName.pageView.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.pageView.rawValue, pageName: PageName.cart.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.pageView.rawValue, pageName: PageName.cart.rawValue)
alreadyInitialized = true
if items.isEmpty {
isAllSet = .paramIssue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ final class AirRobeOrderConfirmationView: UIView, NibLoadable {
guard let url = url else {
return
}
AirRobeUtils.telemetryEvent(eventName: EventName.confirmationClick.rawValue, pageName: PageName.thankYou.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.confirmationClick.rawValue, pageName: PageName.thankYou.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.confirmationClick.rawValue, pageName: PageName.thankYou.rawValue)
AirRobeUtils.openUrl(url)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ final class AirRobeOrderConfirmationViewModel {

func initializeConfirmationWidget() {
if !alreadyInitialized {
AirRobeUtils.telemetryEvent(eventName: EventName.pageView.rawValue, pageName: PageName.thankYou.rawValue)
AirRobeUtils.telemetryEvent(eventName: TelemetryEventName.pageView.rawValue, pageName: PageName.thankYou.rawValue)
AirRobeUtils.dispatchEvent(eventName: EventName.pageView.rawValue, pageName: PageName.thankYou.rawValue)
alreadyInitialized = true
if orderId.isEmpty || email.isEmpty {
isAllSet = .paramIssue
Expand Down

0 comments on commit 6ad679e

Please sign in to comment.