GuruAnalytics_iOS/GuruAnalytics/Classes/Interface/GuruAnalytics.swift

159 lines
5.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//
// GuruAnalytics.swift
// GuruAnalytics_iOS
//
// Created by mayue on 2022/11/4.
//
import Foundation
public class GuruAnalytics: NSObject {
internal static var uploadPeriodInSecond: Double = 60
internal static var batchLimit: Int = 25
internal static var eventExpiredSeconds: Double = 7 * 24 * 60 * 60
internal static var initializeTimeout: Double = 5
internal static var saasXAPPID = ""
internal static var saasXDEVICEINFO = ""
internal static var loggerDebug = true
internal static var enableUpload = true
///
/// - Parameters:
/// - uploadPeriodInSecond:
/// - batchLimit:
/// - eventExpiredSeconds:
/// - initializeTimeout: user id/device id/firebase pseudo id
/// - saasXAPPID: headerX-APP-ID
/// - saasXDEVICEINFO: headerX-DEVICE-INFO
/// - loggerDebug: debug
@objc
public class func initializeLib(uploadPeriodInSecond: Double = 60,
batchLimit: Int = 25,
eventExpiredSeconds: Double = 7 * 24 * 60 * 60,
initializeTimeout: Double = 5,
saasXAPPID: String,
saasXDEVICEINFO: String,
loggerDebug: Bool = true) {
Self.uploadPeriodInSecond = uploadPeriodInSecond
Self.batchLimit = batchLimit
Self.eventExpiredSeconds = eventExpiredSeconds
Self.initializeTimeout = initializeTimeout
Self.saasXAPPID = saasXAPPID
Self.saasXDEVICEINFO = saasXDEVICEINFO
Self.loggerDebug = loggerDebug
_ = Manager.shared
}
/// event
@objc
public class func logEvent(_ name: String, parameters: [String : Any]?) {
Manager.shared.logEvent(name, parameters: parameters)
}
/// IDuid
@objc
public class func setUserID(_ userID: String?) {
setUserProperty(userID, forName: .uid)
}
/// IDIDiOSIDFVUUIDAndroidandroidID
@objc
public class func setDeviceId(_ deviceId: String?) {
setUserProperty(deviceId, forName: .deviceId)
}
/// adjust_idadjust
@objc
public class func setAdjustId(_ adjustId: String?) {
setUserProperty(adjustId, forName: .adjustId)
}
/// 广 ID/广 (IDFA)
@objc
public class func setAdId(_ adId: String?) {
setUserProperty(adId, forName: .adId)
}
/// pseudo_id
@objc
public class func setFirebaseId(_ firebaseId: String?) {
setUserProperty(firebaseId, forName: .firebaseId)
}
/// screen name
@objc
public class func setScreen(_ name: String) {
Manager.shared.setScreen(name)
}
/// userproperty
@objc
public class func setUserProperty(_ value: String?, forName name: String) {
Manager.shared.setUserProperty(value ?? "", forName: name)
}
/// userproperty
@objc
public class func removeUserProperties(forNames names: [String]) {
Manager.shared.removeUserProperties(forNames: names)
}
/// eventszip
/// zipCastbox123
@available(*, deprecated, renamed: "eventsLogsDirectory", message: "废弃使用eventsLogsDirectory方法获取日志文件目录URL")
@objc
public class func eventsLogsArchive(_ callback: @escaping (_ url: URL?) -> Void) {
Manager.shared.eventsLogsArchive(callback)
}
/// events
@objc
public class func eventsLogsDirectory(_ callback: @escaping (_ url: URL?) -> Void) {
Manager.shared.eventsLogsDirURL(callback)
}
/// events
/// host: abc.bbb.com, "https://abc.bbb.com", "http://abc.bbb.com"
@objc
public class func setEventsUploadEndPoint(host: String?) {
UserDefaults.eventsServerHost = host
}
/// events
/// - Parameter callback:
/// - callback parameters:
/// - uploadedEventsCount: event
/// - loggedEventsCount: event
@objc
@available(*, deprecated, message: "used for debug, will be removed on any future released versions")
public class func debug_eventsStatistics(_ callback: @escaping (_ uploadedEventsCount: Int, _ loggedEventsCount: Int) -> Void) {
Manager.shared.debug_eventsStatistics(callback)
}
///
/// - Parameter reportCallback:
/// - callback parameters:
/// - eventCode:
/// - info:
@objc
public class func registerInternalEventObserver(reportCallback: @escaping (_ eventCode: Int, _ info: String) -> Void) {
Manager.shared.registerInternalEventObserver(reportCallback: reportCallback)
}
/// user property
@objc
public class func getUserProperties() -> [String : String] {
return Manager.shared.getUserProperties()
}
/// true
/// true -
/// false -
@objc
public class func setEnableUpload(isOn: Bool = true) -> Void {
enableUpload = isOn
}
}