Skip to content

Commit

Permalink
added more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Espinola committed Jun 26, 2024
1 parent 6a2805a commit f9e7f04
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 12 deletions.
17 changes: 11 additions & 6 deletions Sources/API/ATTNAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final class ATTNAPI: ATTNAPIProtocol {
getGeoAdjustedDomain(domain: domain) { [weak self] geoAdjustedDomain, error in
if let error = error {
Loggers.network.error("Error sending user identity: \(error.localizedDescription)")
return
}

guard let geoAdjustedDomain = geoAdjustedDomain else { return }
Expand Down Expand Up @@ -90,16 +91,18 @@ fileprivate extension ATTNAPI {
return
}

Loggers.event.trace("Building Event URL: \(url)")

var urlRequest = URLRequest(url: url)
urlRequest.httpMethod = "POST"

let task = urlSession.dataTask(with: urlRequest) { data, response, error in
if let error = error {
Loggers.network.error("Error sending for event '\(request.eventNameAbbreviation)'. Error: '\(error.localizedDescription)'")
Loggers.event.error("Error sending for event '\(request.eventNameAbbreviation)'. Error: '\(error.localizedDescription)'")
} else if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode > 400 {
Loggers.network.error("Error sending the event. Incorrect status code: '\(httpResponse.statusCode)'")
Loggers.event.error("Error sending the event. Incorrect status code: '\(httpResponse.statusCode)'")
} else {
Loggers.network.trace("Successfully sent event of type '\(request.eventNameAbbreviation)'")
Loggers.event.trace("Successfully sent event of type '\(request.eventNameAbbreviation)'")
}

callback?(data, url, response, error)
Expand All @@ -114,16 +117,18 @@ fileprivate extension ATTNAPI {
return
}

Loggers.event.trace("Building Identity Event URL: \(url)")

var request = URLRequest(url: url)
request.httpMethod = "POST"

let task = urlSession.dataTask(with: request) { data, response, error in
if let error = error {
Loggers.network.error("Error sending user identity. Error: '\(error.localizedDescription)'")
Loggers.event.error("Error sending user identity. Error: '\(error.localizedDescription)'")
} else if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode > 400 {
Loggers.network.error("Error sending the event. Incorrect status code: '\(httpResponse.statusCode)'")
Loggers.event.error("Error sending the event. Incorrect status code: '\(httpResponse.statusCode)'")
} else {
Loggers.network.trace("Successfully sent user identity event")
Loggers.event.trace("Successfully sent user identity event")
}

callback?(data, url, response, error)
Expand Down
6 changes: 5 additions & 1 deletion Sources/ATTNUserAgentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ATTNUserAgentBuilder: ATTNUserAgentBuilderProtocol {

func buildUserAgent() -> String {
// We replace the spaces with dashes for the app name because spaces in a User-Agent represent a new "product", so app names that have spaces are harder to parse if we don't replace spaces with dashes
String(
let userAgent = String(
format: "%@/%@.%@ (%@; %@ %@) %@/%@",
appInfo.getFormattedAppName(),
appInfo.getAppVersion(),
Expand All @@ -31,5 +31,9 @@ class ATTNUserAgentBuilder: ATTNUserAgentBuilderProtocol {
appInfo.getSdkName(),
appInfo.getSdkVersion()
)

Loggers.event.debug("Created User Agent: \(userAgent)")

return userAgent
}
}
5 changes: 5 additions & 0 deletions Sources/ATTNVisitorService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ struct ATTNVisitorService {
return createNewVisitorId()
}

Loggers.event.info("Obtained existing visitor id: \(existingVisitorId, privacy: .public)")

return existingVisitorId
}

func createNewVisitorId() -> String {
let newVisitorId = generateVisitorId()
persistentStorage.save(newVisitorId as NSObject, forKey: Constants.visitorIdKey)

Loggers.event.info("Generated new visitor id: \(newVisitorId, privacy: .public)")

return newVisitorId
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Helpers/ATTNJsonUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
import Foundation

protocol ATTNJsonUtilsProtocol {
static func convertObjectToJson(_ object: Any) throws -> String?
static func convertObjectToJson(_ object: Any, file: String, function: String) throws -> String?
}

struct ATTNJsonUtils: ATTNJsonUtilsProtocol {
private init() { }

static func convertObjectToJson(_ object: Any) throws -> String? {
static func convertObjectToJson(_ object: Any, file: String = #file, function: String = #function) throws -> String? {
do {
let jsonData = try JSONSerialization.data(withJSONObject: object, options: [])
guard let jsonString = String(data: jsonData, encoding: .utf8) else {
Loggers.event.error("Could not encode JSON data to a string.")
Loggers.event.error("Could not encode JSON data to a string. Function:\(function), File:\(file)")
return nil
}
return jsonString
Expand Down
2 changes: 1 addition & 1 deletion Sources/Helpers/Extension/ATTNEvent+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
extension ATTNEvent {
func convertEventToRequests() -> [ATTNEventRequest] {
guard let provider = self as? ATTNEventRequestProvider else {
Loggers.event.error("ERROR: Unknown event type: \(type(of: self))")
Loggers.event.error("Unknown event type: \(type(of: self)). It can not be converted to EventRequest.")
return []
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Helpers/Extension/ATTNSDK+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extension ATTNSDK {
func initializeSkipFatigueOnCreatives() {
if let skipFatigueValue = ProcessInfo.processInfo.environment[ATTNConstants.skipFatigueEnvKey] {
self.skipFatigueOnCreative = skipFatigueValue.booleanValue
Loggers.creative.info("SKIP_FATIGUE_ON_CREATIVE: \(skipFatigueValue)")
} else {
self.skipFatigueOnCreative = false
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Public/ATTNEventTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class ATTNEventTracker: NSObject {
@objc(setupWithSdk:)
public static func setup(with sdk: ATTNSDK) {
_sharedInstance = ATTNEventTracker(sdk: sdk)
Loggers.event.debug("ATTNEventTracker was initialized with SDK")
}

@available(swift, deprecated: 0.6, message: "Please use record(event: ATTNEvent) instead.")
Expand Down
2 changes: 1 addition & 1 deletion Sources/Public/SDK/ATTNSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class ATTNSDK: NSObject {
@objc public var skipFatigueOnCreative: Bool = false

public init(domain: String, mode: ATTNSDKMode) {
Loggers.creative.trace("Init attentive_ios_sdk v\(ATTNConstants.sdkVersion)")
Loggers.creative.trace("Init ATTNSDKFramework v\(ATTNConstants.sdkVersion). Mode: \(mode.rawValue)")
self.domain = domain
self.mode = mode

Expand Down
1 change: 1 addition & 0 deletions Sources/URLProviders/ATTNCreativeUrlProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct ATTNCreativeUrlProvider: ATTNCreativeUrlProviding {

if configuration.skipFatigue {
queryItems.append(URLQueryItem(name: "skipFatigue", value: configuration.skipFatigue.stringValue))
Loggers.creative.info("Skip Fatigue is enabled. Keep in mind it should be disable for production.")
}

if let creativeId = configuration.creativeId {
Expand Down

0 comments on commit f9e7f04

Please sign in to comment.