Skip to content

Commit

Permalink
changes to fallabela
Browse files Browse the repository at this point in the history
  • Loading branch information
morisgateno-appsflyer committed Oct 14, 2024
1 parent c0dfeb4 commit cfe9272
Showing 1 changed file with 72 additions and 62 deletions.
134 changes: 72 additions & 62 deletions AppsFlyerAdobeExtension/Sources/AppsFlyerAdobeExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,67 +136,55 @@ extension AppsFlyerAdobeExtension {
if event.type == EventType.edge{
handleEdgeEvent(event: event)
return
}

// Bools
var isRevenueEvent = false
let bindActionEvents = (self.eventSettings == AppsFlyerConstants.ACTIONS || self.eventSettings == AppsFlyerConstants.ALL)
let bindStateEvents = (self.eventSettings == AppsFlyerConstants.STATES || self.eventSettings == AppsFlyerConstants.ALL)

print(event.description)
guard let eventData = event.data else {
logger("Couldn't extract event data")
return
}
let nestedData = eventData[AppsFlyerConstants.CONTEXT_DATA_KEY] as? [String : Any]
let eventState = eventData[AppsFlyerConstants.STATE_KEY] as? String
let eventAction = eventData[AppsFlyerConstants.ACTION_KEY] as? String

if eventAction == AppsFlyerConstants.APPSFLYER_ATTRIBUTION_DATA || eventAction == AppsFlyerConstants.APPSFLYER_ENGAGEMENT_DATA {
logger("Discarding event binding for AppsFlyer Attribution Data event")
return
}

let revenue = extractRevenue(nestedData)
let currency = extractCurrency(nestedData)

var afPayloadProperties : [String : Any]? = nil

if let revenue = revenue {
afPayloadProperties = nestedData
afPayloadProperties?[AppsFlyerConstants.AF_REVENUE] = revenue
afPayloadProperties?[AppsFlyerConstants.AF_CURRENCY] = currency
isRevenueEvent = true
}
if let eventAction = eventAction, bindActionEvents && eventAction.count != 0 {
if isRevenueEvent && afPayloadProperties != nil {
AppsFlyerLib.shared().logEvent(name: eventAction, values: afPayloadProperties!)
} else {
AppsFlyerLib.shared().logEvent(name: eventAction, values: nestedData)
}
}
if let eventState = eventState, bindStateEvents && eventState.count != 0 {
if isRevenueEvent && afPayloadProperties != nil {
AppsFlyerLib.shared().logEvent(name: eventState, values: afPayloadProperties!)
} else {
AppsFlyerLib.shared().logEvent(name: eventState, values: nestedData)
}
} else {
handleGenericEvent(event: event)
}
}

fileprivate func dictionaryManipulationForEdgeEvent(_ dict: [String : Any], _ eventName: inout String, _ eventNewData: inout [String : Any]) {
for (key, value) in dict {
if key == "eventName" {
if let eventNameValue = value as? String{
eventName = eventNameValue
}
} else if key == AppsFlyerConstants.CURRENCY_KEY {
eventNewData[AppsFlyerConstants.AF_CURRENCY] = value
} else if key == AppsFlyerConstants.REVENUE_KEY {
eventNewData[AppsFlyerConstants.AF_REVENUE] = value
} else {
eventNewData[key] = value
}
private func handleGenericEvent(event: Event){
// Bools
var isRevenueEvent = false
let bindActionEvents = (self.eventSettings == AppsFlyerConstants.ACTIONS || self.eventSettings == AppsFlyerConstants.ALL)
let bindStateEvents = (self.eventSettings == AppsFlyerConstants.STATES || self.eventSettings == AppsFlyerConstants.ALL)

print(event.description)
guard let eventData = event.data else {
logger("Couldn't extract event data")
return
}
let nestedData = eventData[AppsFlyerConstants.CONTEXT_DATA_KEY] as? [String : Any]
let eventState = eventData[AppsFlyerConstants.STATE_KEY] as? String
let eventAction = eventData[AppsFlyerConstants.ACTION_KEY] as? String

if eventAction == AppsFlyerConstants.APPSFLYER_ATTRIBUTION_DATA || eventAction == AppsFlyerConstants.APPSFLYER_ENGAGEMENT_DATA {
logger("Discarding event binding for AppsFlyer Attribution Data event")
return
}

let revenue = extractRevenue(nestedData)
let currency = extractCurrency(nestedData)

var afPayloadProperties : [String : Any]? = nil

if let revenue = revenue {
afPayloadProperties = nestedData
afPayloadProperties?[AppsFlyerConstants.AF_REVENUE] = revenue
afPayloadProperties?[AppsFlyerConstants.AF_CURRENCY] = currency
isRevenueEvent = true
}
if let eventAction = eventAction, bindActionEvents && eventAction.count != 0 {
if isRevenueEvent && afPayloadProperties != nil {
AppsFlyerLib.shared().logEvent(name: eventAction, values: afPayloadProperties!)
} else {
AppsFlyerLib.shared().logEvent(name: eventAction, values: nestedData)
}
}
if let eventState = eventState, bindStateEvents && eventState.count != 0 {
if isRevenueEvent && afPayloadProperties != nil {
AppsFlyerLib.shared().logEvent(name: eventState, values: afPayloadProperties!)
} else {
AppsFlyerLib.shared().logEvent(name: eventState, values: nestedData)
}
}
}

Expand All @@ -205,11 +193,11 @@ extension AppsFlyerAdobeExtension {
logger("Couldn't extract event data")
return
}
var eventName = ""
var eventName = event.name
if let dataDictionary = eventData["data"] as? [String: Any],
let eventAction = dataDictionary[AppsFlyerConstants.ACTION_KEY] as? String{
if eventAction == AppsFlyerConstants.APPSFLYER_ATTRIBUTION_DATA || eventAction == AppsFlyerConstants.APPSFLYER_ENGAGEMENT_DATA{
logger("Discarding event binding for AppsFlyer Attribution Data event")
let eventAction = dataDictionary[AppsFlyerConstants.ACTION_KEY] as? String {
if eventAction == AppsFlyerConstants.APPSFLYER_ATTRIBUTION_DATA || eventAction == AppsFlyerConstants.APPSFLYER_ENGAGEMENT_DATA {
logger("Discarding event binding for AppsFlyer Attribution/Engagement Data event")
return
}
}
Expand All @@ -222,6 +210,28 @@ extension AppsFlyerAdobeExtension {
}
AppsFlyerLib.shared().logEvent(eventName, withValues: eventNewData)
}

fileprivate func dictionaryManipulationForEdgeEvent(_ dict: [String : Any], _ eventName: inout String, _ eventNewData: inout [String : Any]) {
for (key, value) in dict {
if key == "eventName" {
if let eventNameValue = value as? String{
eventName = eventNameValue
}
} else if key == AppsFlyerConstants.CURRENCY_KEY || key == AppsFlyerConstants.REVENUE_KEY {
continue
} else {
eventNewData[key] = value
}
}

let revenue = extractRevenue(dict)
let currency = extractCurrency(dict)

if let revenue = revenue {
eventNewData[AppsFlyerConstants.AF_REVENUE] = revenue
eventNewData[AppsFlyerConstants.AF_CURRENCY] = currency
}
}
}

// MARK: internal methods
Expand Down

0 comments on commit cfe9272

Please sign in to comment.