Skip to content

Commit

Permalink
2.0.1 (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: Christina <[email protected]>
  • Loading branch information
christinasund and Christina authored Nov 10, 2020
1 parent a848cf0 commit c41fa6c
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 56 deletions.
50 changes: 32 additions & 18 deletions Sources/FirebaseRemoteCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class FirebaseRemoteCommand: RemoteCommand {
payload[FirebaseConstants.Keys.eventParams] = eventKeyFromJSON
}
guard let params = payload[FirebaseConstants.Keys.eventParams] as? [String: Any] else {
firebaseInstance.logEvent(eventName, nil)
firebaseInstance.logEvent(eventName, items(from: payload))
return
}
if let items = params[FirebaseConstants.Keys.paramItems] as? [[String: Any]] {
Expand All @@ -88,14 +88,8 @@ public class FirebaseRemoteCommand: RemoteCommand {
tempItems.append(item)
}
normalizedParams[FirebaseConstants.Keys.items] = tempItems
} else if let items = params.extractItems(), items.count > 0 {
normalizedParams[FirebaseConstants.Keys.items] = items
} else if let items = params.itemsToArray().extractItems(), items.count > 0 {
normalizedParams[FirebaseConstants.Keys.items] = items
}
normalizedParams += eventParameters
.map(params)
.filterOldItems()
normalizedParams += items(from: params)
firebaseInstance.logEvent(eventName, normalizedParams)
case .setScreenName:
guard let screenName = payload[FirebaseConstants.Keys.screenName] as? String else {
Expand Down Expand Up @@ -132,6 +126,30 @@ public class FirebaseRemoteCommand: RemoteCommand {
}
}
}

func items(from payload: [String: Any]) -> [String: Any] {
var result = [String: Any]()

func prepare(items: [String: Any]) -> [String: Any] {
var result = [String: Any]()
if let items = items.extractItems(), items.count > 0 {
result[FirebaseConstants.Keys.items] = items
} else if let items = items.itemsToArray().extractItems(), items.count > 0 {
result[FirebaseConstants.Keys.items] = items
}
return result
}

if let jsonItems = payload[FirebaseConstants.Keys.items] as? [String: Any] {
result = prepare(items: jsonItems)
} else {
result = prepare(items: payload)
}
result += eventParameters
.map(payload)
.filterOldItems()
return result
}

func parseLogLevel(_ logLevel: String) -> FirebaseLoggerLevel {
switch logLevel {
Expand Down Expand Up @@ -163,26 +181,24 @@ public class FirebaseRemoteCommand: RemoteCommand {
"event_app_open": AnalyticsEventAppOpen,
"event_begin_checkout": AnalyticsEventBeginCheckout,
"event_campaign_details": AnalyticsEventCampaignDetails,
"event_checkout_progress": AnalyticsEventCheckoutProgress,
"event_earn_virtual_currency": AnalyticsEventEarnVirtualCurrency,
"event_ecommerce_purchase": AnalyticsEventEcommercePurchase,
"event_generate_lead": AnalyticsEventGenerateLead,
"event_join_group": AnalyticsEventJoinGroup,
"event_level_end": AnalyticsEventLevelEnd,
"event_level_start": AnalyticsEventLevelStart,
"event_level_up": AnalyticsEventLevelUp,
"event_login": AnalyticsEventLogin,
"event_post_score": AnalyticsEventPostScore,
"event_present_offer": AnalyticsEventPresentOffer,
"event_present_offer": AnalyticsEventViewPromotion,
"event_ecommerce_purchase": AnalyticsEventPurchase,
"event_purchase": AnalyticsEventPurchase,
"event_purchase_refund": AnalyticsEventPurchaseRefund,
"event_purchase_refund": AnalyticsEventRefund,
"event_refund": AnalyticsEventRefund,
"event_remove_cart": AnalyticsEventRemoveFromCart,
"event_search": AnalyticsEventSearch,
"event_select_content": AnalyticsEventSelectContent,
"event_select_item": AnalyticsEventSelectItem,
"event_select_promotion": AnalyticsEventSelectPromotion,
"event_set_checkout_option": AnalyticsEventSetCheckoutOption,
"event_share": AnalyticsEventShare,
"event_signup": AnalyticsEventSignUp,
"event_spend_virtual_currency": AnalyticsEventSpendVirtualCurrency,
Expand All @@ -203,8 +219,6 @@ public class FirebaseRemoteCommand: RemoteCommand {
"param_cp1": AnalyticsParameterCP1,
"param_campaign": AnalyticsParameterCampaign,
"param_character": AnalyticsParameterCharacter,
"param_checkout_option": AnalyticsParameterCheckoutOption,
"param_checkout_step": AnalyticsParameterCheckoutStep,
"param_content": AnalyticsParameterContent,
"param_content_type": AnalyticsParameterContentType,
"param_coupon": AnalyticsParameterCoupon,
Expand All @@ -221,10 +235,10 @@ public class FirebaseRemoteCommand: RemoteCommand {
"param_item_brand": AnalyticsParameterItemBrand,
"param_item_category": AnalyticsParameterItemCategory,
"param_item_id": AnalyticsParameterItemID,
"param_item_list": AnalyticsParameterItemList,
"param_item_list": AnalyticsParameterItemListName,
"param_item_list_id": AnalyticsParameterItemListID,
"param_item_list_name": AnalyticsParameterItemListName,
"param_item_location_id": AnalyticsParameterItemLocationID,
"param_item_location_id": AnalyticsParameterLocationID,
"param_item_name": AnalyticsParameterItemName,
"param_item_variant": AnalyticsParameterItemVariant,
"param_level": AnalyticsParameterLevel,
Expand All @@ -246,7 +260,7 @@ public class FirebaseRemoteCommand: RemoteCommand {
"param_search_term": AnalyticsParameterSearchTerm,
"param_shipping": AnalyticsParameterShipping,
"param_shipping_tier": AnalyticsParameterShippingTier,
"param_signup_method": AnalyticsParameterSignUpMethod,
"param_signup_method": AnalyticsParameterMethod,
"param_source": AnalyticsParameterSource,
"param_start_date": AnalyticsParameterStartDate,
"param_success": AnalyticsParameterSuccess,
Expand Down
8 changes: 4 additions & 4 deletions TealiumFirebase.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Pod::Spec.new do |s|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.name = "TealiumFirebase"
s.module_name = "TealiumFirebase"
s.version = "2.0.0"
s.version = "2.0.1"
s.summary = "Tealium Swift and Firebase integration"
s.description = <<-DESC
Tealium's integration with Firebase for iOS.
Expand Down Expand Up @@ -35,9 +35,9 @@ Pod::Spec.new do |s|

# ――― Dependencies ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.static_framework = true
s.ios.dependency 'tealium-swift/Core', '~> 2.1'
s.ios.dependency 'tealium-swift/RemoteCommands', '~> 2.1'
s.ios.dependency 'tealium-swift/TagManagement', '~> 2.1'
s.ios.dependency 'tealium-swift/Core', '~> 2'
s.ios.dependency 'tealium-swift/RemoteCommands', '~> 2'
s.ios.dependency 'tealium-swift/TagManagement', '~> 2'
s.dependency 'Firebase', '~> 6.3'
s.dependency 'FirebaseAnalytics', '~> 6.6'
end
10 changes: 5 additions & 5 deletions TealiumFirebaseExample/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ PODS:
- tealium-swift/Core
- tealium-swift/TagManagement (2.1.0):
- tealium-swift/Core
- TealiumFirebase (2.0.0):
- TealiumFirebase (2.0.1):
- Firebase (~> 6.3)
- FirebaseAnalytics (~> 6.6)
- tealium-swift/Core (~> 2.1)
- tealium-swift/RemoteCommands (~> 2.1)
- tealium-swift/TagManagement (~> 2.1)
- tealium-swift/Core (~> 2)
- tealium-swift/RemoteCommands (~> 2)
- tealium-swift/TagManagement (~> 2)

DEPENDENCIES:
- tealium-swift/Lifecycle (~> 2.1)
Expand Down Expand Up @@ -110,7 +110,7 @@ SPEC CHECKSUMS:
nanopb: 59317e09cf1f1a0af72f12af412d54edf52603fc
PromisesObjC: b14b1c6b68e306650688599de8a45e49fae81151
tealium-swift: a670c2c6f3e7e5d775d9507387e8858a8541e526
TealiumFirebase: 26353b61e3c87074e9ba98a8960fcb2268aa9f35
TealiumFirebase: fdd2c059462b674fe9b6304e3308b4a6f089d45e

PODFILE CHECKSUM: 1f04dcf554d5230ff57cbd50804514a1b168ea96

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
20 changes: 10 additions & 10 deletions TealiumFirebaseExample/TealiumFirebaseExample/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@
"currency_code": "event.param_currency",
"travel_destination": "event.param_destination",
"end_date": "event.param_end_date",
"flight_number": "pevent.param_flight_number",
"flight_number": "event.param_flight_number",
"group_id": "event.param_group_id",
"current_index": "param_index",
"product_brand": "event.param_item_brand",
"product_category": "event.param_item_category",
"product_id": "event.param_item_id",
"product_list": "event.param_item_list",
"product_location_id": "event.param_item_location_id",
"product_name": "event.param_item_name",
"product_variant": "event.param_item_variant",
"product_brand": "items.param_item_brand",
"product_category": "items.param_item_category",
"product_id": "items.param_item_id",
"product_unit_price": "items.param_price",
"product_quantity": "items.param_quantity",
"product_list": "items.param_item_list",
"product_location_id": "items.param_item_location_id",
"product_name": "items.param_item_name",
"product_variant": "items.param_item_variant",
"current_level": "event.param_level",
"most_recent_location": "event.param_location",
"campaign_medium": "event.param_medium",
"number_nights": "event.param_number_nights",
"number_pax": "event.param_number_pax",
"number_rooms": "event.param_number_rooms",
"travel_origin": "event.param_origin",
"product_unit_price": "event.param_price",
"product_quantity": "event.param_quantity",
"score": "event.param_score",
"search_keyword": "event.param_search_term",
"order_shipping_amount": "event.param_shipping",
Expand Down
42 changes: 35 additions & 7 deletions Tests/FirebaseCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class FirebaseCommandTests: XCTestCase {
"event_app_open",
"event_begin_checkout",
"event_campaign_details",
"event_checkout_progress",
"event_earn_virtual_currency",
"event_ecommerce_purchase",
"event_generate_lead",
Expand All @@ -68,7 +67,6 @@ class FirebaseCommandTests: XCTestCase {
"event_remove_cart",
"event_search",
"event_select_content",
"event_set_checkout_option",
"event_share","event_signup",
"event_spend_virtual_currency",
"event_tutorial_begin",
Expand All @@ -84,24 +82,22 @@ class FirebaseCommandTests: XCTestCase {
AnalyticsEventAppOpen,
AnalyticsEventBeginCheckout,
AnalyticsEventCampaignDetails,
AnalyticsEventCheckoutProgress,
AnalyticsEventEarnVirtualCurrency,
AnalyticsEventEcommercePurchase,
AnalyticsEventPurchase,
AnalyticsEventGenerateLead,
AnalyticsEventJoinGroup,
AnalyticsEventLevelEnd,
AnalyticsEventLevelStart,
AnalyticsEventLevelUp,
AnalyticsEventLogin,
AnalyticsEventPostScore,
AnalyticsEventPresentOffer,
AnalyticsEventViewPromotion,
AnalyticsEventPurchase,
AnalyticsEventPurchaseRefund,
AnalyticsEventRefund,
AnalyticsEventRefund,
AnalyticsEventRemoveFromCart,
AnalyticsEventSearch,
AnalyticsEventSelectContent,
AnalyticsEventSetCheckoutOption,
AnalyticsEventShare,
AnalyticsEventSignUp,
AnalyticsEventSpendVirtualCurrency,
Expand Down Expand Up @@ -153,4 +149,36 @@ class FirebaseCommandTests: XCTestCase {
}

}

func testItemsFromPayload() {
let payload = ["items": [
"param_item_id": ["abc123","xyz456"],
"param_item_name": ["cool running shoes", "cool shirt"],
"param_quantity": [1, 2],
"param_item_category": ["shoes", "shirts"],
"param_item_variant": ["abc-blue-123", "xyz-red-456"],
"param_item_brand": ["acme", "roadrunner"],
"param_price": [10.99, 14.99]]]

let expected: [String: Any] = ["items": [
["item_id": "abc123",
"item_name": "cool running shoes",
"quantity": 1,
"item_category": "shoes",
"item_variant": "abc-blue-123",
"item_brand": "acme",
"price": 10.99],
["item_id": "xyz456",
"item_name": "cool shirt",
"quantity": 2,
"item_category": "shirts",
"item_variant": "xyz-red-456",
"item_brand": "roadrunner",
"price": 14.99]]]

let actual = firebaseCommand.items(from: payload)

XCTAssertTrue(NSDictionary(dictionary: actual).isEqual(to: expected))

}
}
Loading

0 comments on commit c41fa6c

Please sign in to comment.