Skip to content

Commit

Permalink
1.6.14
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Korney committed Oct 18, 2023
1 parent 76067fe commit 8204121
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 157 deletions.
2 changes: 1 addition & 1 deletion AffiseAttributionLib.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Pod::Spec.new do |spec|
spec.name = "AffiseAttributionLib"
spec.version = ENV['LIB_VERSION'] || "1.6.13"
spec.version = ENV['LIB_VERSION'] || "1.6.14"
spec.summary = "Affise Attribution iOS library"
spec.description = "Affise SDK is a software you can use to collect app usage statistics, device identifiers, deeplink usage, track install referrer."
spec.homepage = "https://github.com/affise/sdk-ios"
Expand Down
10 changes: 5 additions & 5 deletions AffiseAttributionLib/Classes/ad/AffiseAdRevenue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ public final class AffiseAdRevenue: NSObject {
}

public func setRevenue(_ revenue: Float, _ currency: String) -> AffiseAdRevenue {
event
let _ = event
.addPredefinedParameter(.REVENUE, float: revenue)
.addPredefinedParameter(.CURRENCY, string: currency)
return self
}

public func setRevenue(_ revenue: Double, _ currency: String) -> AffiseAdRevenue {
event
let _ = event
.addPredefinedParameter(.REVENUE, float: Float(revenue))
.addPredefinedParameter(.CURRENCY, string: currency)
return self
}

public func setNetwork(_ network: String?) -> AffiseAdRevenue {
guard let value = network else { return self }
event.addPredefinedParameter(.NETWORK, string: value)
let _ = event.addPredefinedParameter(.NETWORK, string: value)
return self
}

public func setUnit(_ unit: String?) -> AffiseAdRevenue {
guard let value = unit else { return self }
event.addPredefinedParameter(.UNIT, string: value)
let _ = event.addPredefinedParameter(.UNIT, string: value)
return self
}

public func setPlacement(_ placement: String?) -> AffiseAdRevenue {
guard let value = placement else { return self }
event.addPredefinedParameter(.PLACEMENT, string: value)
let _ = event.addPredefinedParameter(.PLACEMENT, string: value)
return self
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import AffiseAttributionLib


public class ProvidersToJsonStringConverter: Converter {

public typealias T = [Provider]
Expand Down
12 changes: 3 additions & 9 deletions AffiseAttributionLib/Classes/events/EventsManager.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// EventsManager.swift
// app
//
// Created by Sergey Korney
//


/**
* Manager of Events
*
Expand Down Expand Up @@ -68,7 +60,9 @@ class EventsManager {
* Send event
*/
func sendEvents(withDelay: Bool = true) {
sendDataToServerUseCase.send(withDelay: withDelay)
DispatchQueue.global(qos:.background).sync {
sendDataToServerUseCase.send(withDelay: withDelay)
}
}

/**
Expand Down
22 changes: 2 additions & 20 deletions AffiseAttributionLib/Classes/events/base/Event.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// Event.swift
// app
//
// Created by Sergey Korney
//


/**
* Base event
*/
Expand Down Expand Up @@ -66,7 +58,6 @@ public class Event: NSObject {
* Add predefined [parameter] with [value] type String to event
*/
@objc
@discardableResult
public func addPredefinedParameter(_ parameter: PredefinedString, string: String) -> Event {
predefinedParameters.append((parameter.value(), string))
return self
Expand All @@ -76,7 +67,6 @@ public class Event: NSObject {
* Add predefined [parameter] with [value] type Array of String to event
*/
@objc
@discardableResult
public func addPredefinedParameter(_ parameter: PredefinedListString, listString: [String]) -> Event {
predefinedParameters.append((parameter.value(), listString))
return self
Expand All @@ -86,7 +76,6 @@ public class Event: NSObject {
* Add predefined [parameter] with [value] type Int64 to event
*/
@objc
@discardableResult
public func addPredefinedParameter(_ parameter: PredefinedLong, long: Int64) -> Event {
predefinedParameters.append((parameter.value(), long))
return self
Expand All @@ -96,7 +85,6 @@ public class Event: NSObject {
* Add predefined [parameter] with [value] type Float to event
*/
@objc
@discardableResult
public func addPredefinedParameter(_ parameter: PredefinedFloat, float: Float) -> Event {
predefinedParameters.append((parameter.value(), float))
return self
Expand All @@ -105,7 +93,6 @@ public class Event: NSObject {
/**
* Add predefined [parameter] with [value] type JSON to event
*/
@discardableResult
public func addPredefinedParameter(_ parameter: PredefinedObject, object: [(String, Any?)]) -> Event {
predefinedParameters.append((parameter.value(), object))
return self
Expand All @@ -114,16 +101,13 @@ public class Event: NSObject {
* Add predefined [parameter] with [value] type JSON to event
*/
@objc
@discardableResult
public func addPredefinedParameter(_ parameter: PredefinedObject, object: [[String: AnyObject]]) -> Event {
addPredefinedParameter(parameter, object: object.toFlatList())
return self
return addPredefinedParameter(parameter, object: object.toFlatList())
}

/**
* Add predefined [parameter] with [value] type Array of JSON to event
*/
@discardableResult
public func addPredefinedParameter(_ parameter: PredefinedListObject, listObject: [[(String, Any?)]]) -> Event {
predefinedParameters.append((parameter.value(), listObject))
return self
Expand All @@ -133,10 +117,8 @@ public class Event: NSObject {
* Add predefined [parameter] with [value] type Array of JSON to event
*/
@objc
@discardableResult
public func addPredefinedParameter(_ parameter: PredefinedListObject, listObject: [[String: AnyObject]]) -> Event {
addPredefinedParameter(parameter, listObject: listObject.toListOfList())
return self
return addPredefinedParameter(parameter, listObject: listObject.toListOfList())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class AffSDKVersionProvider: StringPropertyProvider {

override func provide() -> String? {
return "1.6.13"
return "1.6.14"
}

public override func getOrder() -> Float {
Expand Down
8 changes: 0 additions & 8 deletions AffiseAttributionLib/Classes/storages/EventsParams.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// EventsParams.swift
// AffiseAttributionLib
//
// Created by Sergey Korney
//


class EventsParams {
static let EVENTS_DIR_NAME = "affise-events"
static let EVENTS_SEND_COUNT = 100
Expand Down
10 changes: 1 addition & 9 deletions AffiseAttributionLib/Classes/storages/EventsStorageImpl.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// EventsStorageImpl.swift
// app
//
// Created by Sergey Korney
//


class EventsStorageImpl {

private let logsManager: LogsManager
Expand Down Expand Up @@ -110,7 +102,7 @@ extension EventsStorageImpl: EventsStorage {

let events = try directoryContents.filter({ fileURL in
let attr = try fileManager.attributesOfItem(atPath: fileURL.path)
let creationDate = (attr[.modificationDate] as! Date)
guard let creationDate = attr[.modificationDate] as? Date else { return true }
if (creationDate.timeIntervalSince1970 < Date().timeIntervalSinceNow - Double(EventsParams.EVENTS_STORE_TIME)) {
do {
try fileManager.removeItem(atPath: fileURL.path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ class IsFirstForUserUseCaseImpl {
/**
* Cache of already send events
*/
private var cache: Array<String> = []

private var cache: [String] = []
private let lockQueue = DispatchQueue(label: "com.affise.attribution", attributes: .concurrent)

init(isFirstForUserStorage: IsFirstForUserStorage) {
self.isFirstForUserStorage = isFirstForUserStorage
cache = isFirstForUserStorage.getEventsNames()
}

func cacheContains(_ value: String) -> Bool {
lockQueue.sync {
return cache.contains(value)
}
}

func cacheAppend(_ value: String) {
lockQueue.async(flags: .barrier) {
self.cache.append(value)
}
}
}

extension IsFirstForUserUseCaseImpl: IsFirstForUserUseCase {
Expand All @@ -25,11 +37,14 @@ extension IsFirstForUserUseCaseImpl: IsFirstForUserUseCase {
* Update IsFirstForUser
*/
func updateEvent(_ event: Event) {
let eventClass = String(describing: type(of: event))
if (self.cache.contains(eventClass)) {
var eventClass = event.getName()
if let subtype = (event as? BaseSubscriptionEvent)?.subtype() {
eventClass = subtype
}
if (self.cacheContains(eventClass) || self.cacheContains(String(describing: type(of: event)))) {
event.setFirstForUser(false)
} else {
self.cache.append(eventClass)
self.cacheAppend(eventClass)
self.isFirstForUserStorage.add(eventClass)
event.setFirstForUser(true)
}
Expand All @@ -55,10 +70,10 @@ extension IsFirstForUserUseCaseImpl: IsFirstForUserUseCase {
return event
}

if (self.cache.contains(eventClass)) {
if (self.cacheContains(eventClass)) {
dict[Parameters.AFFISE_EVENT_FIRST_FOR_USER] = false
} else {
self.cache.append(eventClass)
self.cacheAppend(eventClass)
self.isFirstForUserStorage.add(eventClass)
dict[Parameters.AFFISE_EVENT_FIRST_FOR_USER] = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// SendDataToServerUseCaseImpl.swift
// app
//
// Created by Sergey Korney
//


internal class SendDataToServerUseCaseImpl {

private static let TIME_DELAY_SENDING: TimeInterval = 15
Expand Down Expand Up @@ -40,8 +32,21 @@ internal class SendDataToServerUseCaseImpl {
/**
* Flags to status is sending from current url
*/
private var isSend = Dictionary(uniqueKeysWithValues: CloudConfig.urls.map{ ($0, false) })
private var isSendThreadUnsafe: [String:Bool] = Dictionary(uniqueKeysWithValues: CloudConfig.urls.map{ ($0, false) })
private let lockQueue = DispatchQueue(label: "com.affise.attribution", attributes: .concurrent)

func getIsSend(_ key: String) -> Bool {
lockQueue.sync {
guard let result = isSendThreadUnsafe[key] else { return false }
return result
}
}

func setIsSend(_ key: String, _ value: Bool) {
lockQueue.async(flags: .barrier) {
self.isSendThreadUnsafe[key] = value
}
}

/**
* Sending for url
Expand Down Expand Up @@ -104,12 +109,13 @@ extension SendDataToServerUseCaseImpl: SendDataToServerUseCase {
return
}
let globalQueue = DispatchQueue.global(qos:.background)

//For all urls
CloudConfig.urls.forEach { it in
//Check if sending on this url
if (isSend[it] == false) {
if (getIsSend(it) == false) {
//Lock sending to this url
isSend[it] = true
setIsSend(it, true)

globalQueue.async { [weak self] in
if (withDelay) {
Expand All @@ -119,7 +125,7 @@ extension SendDataToServerUseCaseImpl: SendDataToServerUseCase {
self?.send(url: it)

//Unlock sending to this url
self?.isSend[it] = false
self?.setIsSend(it, false)
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions AffiseAttributionLib/Classes/usecase/StoreEventUseCaseImpl.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// StoreEventUseCaseImpl.swift
// app
//
// Created by Sergey Korney
//


class StoreEventUseCaseImpl {
private let repository: EventsRepository
private let eventsManager: EventsManager
Expand Down Expand Up @@ -54,7 +46,7 @@ extension StoreEventUseCaseImpl: StoreEventUseCase {
func storeEvent(event: Event) {

if (isTrackingEnabled()) {
DispatchQueue.global(qos:.background).async { [weak self] in
DispatchQueue.global(qos:.background).sync { [weak self] in
//Update event for isFirstForUser
self?.isFirstForUserUseCase.updateEvent(event)

Expand All @@ -69,7 +61,7 @@ extension StoreEventUseCaseImpl: StoreEventUseCase {

func storeWebEvent(event: String) {
if (isTrackingEnabled() || event != GDPREvent.EVENT_NAME) {
DispatchQueue.global(qos:.background).async { [weak self] in
DispatchQueue.global(qos:.background).sync { [weak self] in
//Update event for isFirstForUser
let updatedEvent = self?.isFirstForUserUseCase.updateWebEvent(event) ?? event

Expand Down
2 changes: 1 addition & 1 deletion AffiseInternal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |spec|
spec.name = "AffiseInternal"
spec.version = ENV['LIB_VERSION'] || "1.6.13"
spec.version = ENV['LIB_VERSION'] || "1.6.14"
spec.summary = "Affise Internal library"
spec.description = "Affise Internal wrapper library for crossplatform"
spec.homepage = "https://github.com/affise/sdk-ios"
Expand Down
Loading

0 comments on commit 8204121

Please sign in to comment.