Skip to content

Commit

Permalink
Update parameter mappings within logEvent to send parameters outside …
Browse files Browse the repository at this point in the history
…of expected param_ prefix (#6)

Co-authored-by: Christina <[email protected]>
  • Loading branch information
christinasund and Christina authored Jun 25, 2020
1 parent 649001e commit 53f66dc
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 110 deletions.
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" "6.24.0"
binary "https://dl.google.com/dl/firebase/ios/carthage/FirebaseAnalyticsBinary.json" "6.27.0"
binary "https://tags.tiqcdn.com/dle/tealiummobile/tealium-ios-carthage/tealium-carthage-plcrashreporter.json?_cb=2" "1.4.0"
github "tealium/tealium-swift" "1.9.4"
github "tealium/tealium-swift" "1.9.5"
30 changes: 15 additions & 15 deletions Sources/FirebaseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import Foundation

enum FirebaseConstants {

static let commandName = "command_name"
static let separator: Character = ","
static let commandId = "firebaseAnalytics"
static let description = "Firebase Remote Command"
static let errorPrefix = "Tealium Firebase: "

enum Keys: String {
case commandName = "command_name"
case sessionTimeout = "firebase_session_timeout_seconds"
case minSeconds = "firebase_session_minimum_seconds"
case analyticsEnabled = "firebase_analytics_enabled"
case logLevel = "firebase_log_level"
case eventName = "firebase_event_name"
case eventParams = "firebase_event_params"
case screenName = "firebase_screen_name"
case screenClass = "firebase_screen_class"
case userPropertyName = "firebase_property_name"
case userPropertyValue = "firebase_property_value"
case userId = "firebase_user_id"
case paramItems = "param_items"
case items = "items"
enum Keys {
static let sessionTimeout = "firebase_session_timeout_seconds"
static let minSeconds = "firebase_session_minimum_seconds"
static let analyticsEnabled = "firebase_analytics_enabled"
static let logLevel = "firebase_log_level"
static let eventName = "firebase_event_name"
static let eventParams = "firebase_event_params"
static let screenName = "firebase_screen_name"
static let screenClass = "firebase_screen_class"
static let userPropertyName = "firebase_property_name"
static let userPropertyValue = "firebase_property_value"
static let userId = "firebase_user_id"
static let paramItems = "param_items"
static let items = "items"
}

enum Commands: String {
Expand Down
60 changes: 27 additions & 33 deletions Sources/FirebaseRemoteCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FirebaseRemoteCommand {
return TealiumRemoteCommand(commandId: FirebaseConstants.commandId,
description: FirebaseConstants.description) { response in
let payload = response.payload()
guard let command = payload[.commandName] as? String else {
guard let command = payload[FirebaseConstants.commandName] as? String else {
return
}
let commands = command.split(separator: FirebaseConstants.separator)
Expand All @@ -50,64 +50,66 @@ public class FirebaseRemoteCommand {
var firebaseSessionTimeout: TimeInterval?
var firebaseSessionMinimumSeconds: TimeInterval?
var firebaseAnalyticsEnabled: Bool?
if let sessionTimeout = payload[.sessionTimeout] as? String {
if let sessionTimeout = payload[FirebaseConstants.Keys.sessionTimeout] as? String {
firebaseSessionTimeout = TimeInterval(sessionTimeout)
}
if let sessionMinimumSeconds = payload[.minSeconds] as? String {
if let sessionMinimumSeconds = payload[FirebaseConstants.Keys.minSeconds] as? String {
firebaseSessionMinimumSeconds = TimeInterval(sessionMinimumSeconds)
}
if let analyticsEnabled = payload[.analyticsEnabled] as? String {
if let analyticsEnabled = payload[FirebaseConstants.Keys.analyticsEnabled] as? String {
firebaseAnalyticsEnabled = Bool(analyticsEnabled)
}
if let logLevel = payload[.logLevel] as? String {
if let logLevel = payload[FirebaseConstants.Keys.logLevel] as? String {
firebaseLogLevel = self.parseLogLevel(logLevel)
}
self.firebaseTracker.createAnalyticsConfig(firebaseSessionTimeout, firebaseSessionMinimumSeconds, firebaseAnalyticsEnabled, firebaseLogLevel)
case .logEvent:
guard let name = payload[.eventName] as? String else {
guard let name = payload[FirebaseConstants.Keys.eventName] as? String else {
return
}
let eventName = self.mapEvent(name)
var normalizedParams = [String: Any]()
guard let params = payload[.eventParams] as? [String: Any] else {
guard let params = payload[FirebaseConstants.Keys.eventParams] as? [String: Any] else {
return self.firebaseTracker.logEvent(eventName, nil)
}
if let items = params[.paramItems] as? [[String: Any]] {
if let items = params[FirebaseConstants.Keys.paramItems] as? [[String: Any]] {
var tempItems = [[String: Any]]()
var item = [String: Any]()
items.forEach {
item = eventParameters.map($0)
item = $0.mapParams()
tempItems.append(item)
}
normalizedParams[.items] = tempItems
normalizedParams[FirebaseConstants.Keys.items] = tempItems
}
normalizedParams += params.mapParams().filter {
$0.key != FirebaseConstants.Keys.paramItems
}
normalizedParams += eventParameters.map(params)
self.firebaseTracker.logEvent(eventName, normalizedParams)
case .setScreenName:
guard let screenName = payload[.screenName] as? String else {
guard let screenName = payload[FirebaseConstants.Keys.screenName] as? String else {
if firebaseLogLevel == .debug {
print("\(FirebaseConstants.errorPrefix)`screen_name` required for setScreenName.")
}
return
}
let screenClass = payload[.screenClass] as? String
let screenClass = payload[FirebaseConstants.Keys.screenClass] as? String
self.firebaseTracker.setScreenName(screenName, screenClass)
case .setUserProperty:
guard let propertyName = payload[.userPropertyName] as? String else {
guard let propertyName = payload[FirebaseConstants.Keys.userPropertyName] as? String else {
if firebaseLogLevel == .debug {
print("\(FirebaseConstants.errorPrefix)`firebase_property_name` required for setUserProperty.")
}
return
}
guard let propertyValue = payload[.userPropertyValue] as? String else {
guard let propertyValue = payload[FirebaseConstants.Keys.userPropertyValue] as? String else {
if firebaseLogLevel == .debug {
print("\(FirebaseConstants.errorPrefix)`firebase_property_value` required for setUserProperty.")
}
return
}
self.firebaseTracker.setUserProperty(propertyName, value: propertyValue)
case .setUserId:
guard let userId = payload[.userId] as? String else {
guard let userId = payload[FirebaseConstants.Keys.userId] as? String else {
if firebaseLogLevel == .debug {
print("\(FirebaseConstants.errorPrefix)`firebase_user_id` required for setUserId.")
}
Expand Down Expand Up @@ -183,7 +185,7 @@ public class FirebaseRemoteCommand {
return eventsMap[eventName] ?? eventName
}

let eventParameters = [
static let eventParameters = [
"param_achievement_id": AnalyticsParameterAchievementID,
"param_ad_network_click_id": AnalyticsParameterAdNetworkClickID,
"param_affiliation": AnalyticsParameterAffiliation,
Expand Down Expand Up @@ -245,26 +247,18 @@ public class FirebaseRemoteCommand {
"param_virtual_currency_name": AnalyticsParameterVirtualCurrencyName,
"param_user_signup_method": AnalyticsUserPropertySignUpMethod
]

static func mapParam(_ param: String) -> String {
FirebaseRemoteCommand.eventParameters[param] ?? param
}

}

fileprivate extension Dictionary where Key == String, Value == String {
func map(_ payload: [String: Any]) -> [String: Any] {
extension Dictionary where Key == String, Value == Any {
func mapParams() -> [String: Any] {
return self.reduce(into: [String: Any]()) { result, dictionary in
if payload[dictionary.key] != nil {
result[dictionary.value] = payload[dictionary.key]
}
}
}
}

fileprivate extension Dictionary where Key: ExpressibleByStringLiteral {
subscript(key: FirebaseConstants.Keys) -> Value? {
get {
return self[key.rawValue as! Key]
}
set {
self[key.rawValue as! Key] = newValue
let newKey = FirebaseRemoteCommand.mapParam(dictionary.key)
result[newKey] = dictionary.value
}
}
}
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 = "1.1.0"
s.version = "1.1.1"
s.summary = "Tealium Swift and Firebase integration"
s.description = <<-DESC
Tealium's integration with Firebase for iOS.
Expand All @@ -19,7 +19,7 @@ Pod::Spec.new do |s|
s.social_media_url = "https://twitter.com/tealium"

# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.swift_version = "4.2"
s.swift_version = "5.0"
s.platform = :ios, "10.0"
s.ios.deployment_target = "10.0"

Expand All @@ -35,6 +35,6 @@ Pod::Spec.new do |s|
s.ios.dependency 'tealium-swift/TealiumRemoteCommands', '~> 1.9'
s.ios.dependency 'tealium-swift/TealiumDelegate', '~> 1.9'
s.ios.dependency 'tealium-swift/TealiumTagManagement', '~> 1.9'
s.dependency 'Firebase', '~> 6.24'
s.dependency 'FirebaseAnalytics', '~> 6.5'
s.dependency 'Firebase', '~> 6.2'
s.dependency 'FirebaseAnalytics', '~> 6.6'
end
1 change: 1 addition & 0 deletions TealiumFirebase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = CF17EB4A22F0E3D700C6086B;
productRefGroup = CF17EB5522F0E3D700C6086B /* Products */;
Expand Down
4 changes: 2 additions & 2 deletions TealiumFirebaseExample/Podfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '10.0'

target 'TealiumFirebaseExample' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for TealiumFirebaseExample
pod 'TealiumFirebase', '~> 1.1'
pod 'TealiumFirebase', :path=> '../'
pod 'tealium-swift/TealiumLogger', '~> 1.9'
pod 'tealium-swift/TealiumAppData', '~> 1.9'
pod 'tealium-swift/TealiumDeviceData', '~> 1.9'
Expand Down
48 changes: 24 additions & 24 deletions TealiumFirebaseExample/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
PODS:
- Firebase (6.24.0):
- Firebase/Core (= 6.24.0)
- Firebase/Core (6.24.0):
- Firebase (6.26.0):
- Firebase/Core (= 6.26.0)
- Firebase/Core (6.26.0):
- Firebase/CoreOnly
- FirebaseAnalytics (= 6.5.0)
- Firebase/CoreOnly (6.24.0):
- FirebaseCore (= 6.7.0)
- FirebaseAnalytics (6.5.0):
- FirebaseAnalytics (= 6.6.0)
- Firebase/CoreOnly (6.26.0):
- FirebaseCore (= 6.7.2)
- FirebaseAnalytics (6.6.0):
- FirebaseCore (~> 6.7)
- FirebaseInstallations (~> 1.2)
- GoogleAppMeasurement (= 6.5.0)
- FirebaseInstallations (~> 1.3)
- GoogleAppMeasurement (= 6.6.0)
- GoogleUtilities/AppDelegateSwizzler (~> 6.0)
- GoogleUtilities/MethodSwizzler (~> 6.0)
- GoogleUtilities/Network (~> 6.0)
- "GoogleUtilities/NSData+zlib (~> 6.0)"
- nanopb (~> 1.30905.0)
- FirebaseCore (6.7.0):
- FirebaseCore (6.7.2):
- FirebaseCoreDiagnostics (~> 1.3)
- FirebaseCoreDiagnosticsInterop (~> 1.2)
- GoogleUtilities/Environment (~> 6.5)
Expand All @@ -27,18 +27,18 @@ PODS:
- GoogleUtilities/Logger (~> 6.5)
- nanopb (~> 1.30905.0)
- FirebaseCoreDiagnosticsInterop (1.2.0)
- FirebaseInstallations (1.2.0):
- FirebaseInstallations (1.3.0):
- FirebaseCore (~> 6.6)
- GoogleUtilities/Environment (~> 6.6)
- GoogleUtilities/UserDefaults (~> 6.6)
- PromisesObjC (~> 1.2)
- GoogleAppMeasurement (6.5.0):
- GoogleAppMeasurement (6.6.0):
- GoogleUtilities/AppDelegateSwizzler (~> 6.0)
- GoogleUtilities/MethodSwizzler (~> 6.0)
- GoogleUtilities/Network (~> 6.0)
- "GoogleUtilities/NSData+zlib (~> 6.0)"
- nanopb (~> 1.30905.0)
- GoogleDataTransport (6.1.0)
- GoogleDataTransport (6.2.1)
- GoogleDataTransportCCTSupport (3.1.0):
- GoogleDataTransport (~> 6.1)
- nanopb (~> 1.30905.0)
Expand Down Expand Up @@ -82,9 +82,9 @@ PODS:
- tealium-swift/Core
- tealium-swift/TealiumTagManagement (1.9.4):
- tealium-swift/Core
- TealiumFirebase (1.1.0):
- Firebase (~> 6.24)
- FirebaseAnalytics (~> 6.5)
- TealiumFirebase (1.1.1):
- Firebase (~> 6.2)
- FirebaseAnalytics (~> 6.6)
- tealium-swift/Core (~> 1.9)
- tealium-swift/TealiumDelegate (~> 1.9)
- tealium-swift/TealiumRemoteCommands (~> 1.9)
Expand Down Expand Up @@ -118,21 +118,21 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
Firebase: b28e55c60efd98963cd9011fe2fac5a10c2ba124
FirebaseAnalytics: 7386fc2176e3f93ad8ef34b5b1f2b33a891e4962
FirebaseCore: e610482f64097b0e9f056cd97bc6b33dfabcbb6a
Firebase: 7cf5f9c67f03cb3b606d1d6535286e1080e57eb6
FirebaseAnalytics: 96634d356482d4f3af8fe459a0ebf19a99c71b75
FirebaseCore: f42e5e5f382cdcf6b617ed737bf6c871a6947b17
FirebaseCoreDiagnostics: 4a773a47bd83bbd5a9b1ccf1ce7caa8b2d535e67
FirebaseCoreDiagnosticsInterop: 296e2c5f5314500a850ad0b83e9e7c10b011a850
FirebaseInstallations: 2119fb3e46b0a88bfdbf12562f855ee3252462fa
GoogleAppMeasurement: 4c644d86835d827bab30ab6aabb9ecaf1f500735
GoogleDataTransport: f6f8eba931df03ebd2232ff4645aa85f8f47b5ab
FirebaseInstallations: 6f5f680e65dc374397a483c32d1799ba822a395b
GoogleAppMeasurement: 67458367830514fb20fd9e233496f1eef9d90185
GoogleDataTransport: 9a8a16f79feffc7f42096743de2a7c4815e84020
GoogleDataTransportCCTSupport: d70a561f7d236af529fee598835caad5e25f6d3d
GoogleUtilities: 39530bc0ad980530298e9c4af8549e991fd033b1
nanopb: c43f40fadfe79e8b8db116583945847910cbabc9
PromisesObjC: c119f3cd559f50b7ae681fa59dc1acd19173b7e6
tealium-swift: c478175eadd99de290a65c5c2cc38a7bb86ac28c
TealiumFirebase: e85bf3e7fc73eea3f6bfc07bbb4ae6a5a63ec411
TealiumFirebase: 708529ed17cda7c60016bda700c1611f3b2bc4cd

PODFILE CHECKSUM: 393c580155612651d05ca3506f7427eb51a6c6c0
PODFILE CHECKSUM: 7d856fa4357cf2dd7d577dfa2f1f6eaa8baa0e3c

COCOAPODS: 1.9.1
Loading

0 comments on commit 53f66dc

Please sign in to comment.