Skip to content

Commit

Permalink
adding changes which is present in rename-sdk branch and in interna…
Browse files Browse the repository at this point in the history
…l clickstream
  • Loading branch information
RishavG96 committed Dec 14, 2023
1 parent 546fbc5 commit 36c93a8
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Clickstream.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "Clickstream"
s.version = "2.0.12"
s.version = "2.0.13"
s.summary = "Real time Analytics SDK"
s.description = "Clickstream is an event agnostic, real-time data ingestion analytics SDK"

Expand All @@ -28,7 +28,7 @@ Pod::Spec.new do |s|
s.frameworks = "UIKit", "Foundation", "CoreTelephony"
s.dependency "SwiftProtobuf", "~> 1.10"
s.dependency "ReachabilitySwift", "~> 5.0"
s.dependency "GRDB.swift", "~> 5.12"
s.dependency "GRDB.swift", "~> 6.7"

s.default_subspec = 'Core'

Expand Down
92 changes: 92 additions & 0 deletions Clickstream.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2016 Ashley Mills

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 2c97fb10dcb1fcd309b15a9c7e84ddc137998638

COCOAPODS: 1.12.0
COCOAPODS: 1.12.1
8 changes: 8 additions & 0 deletions Sources/Clickstream/Core/Interface/ClickStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public final class Clickstream {

static var updateConnectionStatus: Bool = false

static var timerCrashFixFlag: Bool = false

/// Use this property to pass application name without any space or special characters.
static var appPrefix: String = ""

Expand Down Expand Up @@ -167,6 +169,7 @@ public final class Clickstream {
eventClassification: ClickstreamEventClassification,
delegate: ClickstreamDelegate? = nil,
updateConnectionStatus: Bool = false,
timerCrashFixFlag: Bool = false,
appPrefix: String) throws -> Clickstream? {
do {
return try initializeClickstream(
Expand All @@ -175,6 +178,7 @@ public final class Clickstream {
eventClassification: eventClassification,
delegate: delegate,
updateConnectionStatus: updateConnectionStatus,
timerCrashFixFlag: timerCrashFixFlag,
appPrefix: appPrefix)
} catch {
print("Cannot initialise Clickstream. Dependencies could not be initialised.",.critical)
Expand All @@ -188,6 +192,7 @@ public final class Clickstream {
eventClassification: ClickstreamEventClassification,
delegate: ClickstreamDelegate? = nil,
updateConnectionStatus: Bool = false,
timerCrashFixFlag: Bool = false,
appPrefix: String) throws -> Clickstream? {
do {
return try initializeClickstream(
Expand All @@ -196,6 +201,7 @@ public final class Clickstream {
eventClassification: eventClassification,
delegate: delegate,
updateConnectionStatus: updateConnectionStatus,
timerCrashFixFlag: timerCrashFixFlag,
appPrefix: appPrefix)
} catch {
print("Cannot initialise Clickstream. Dependencies could not be initialised.",.critical)
Expand All @@ -210,6 +216,7 @@ public final class Clickstream {
eventClassification: ClickstreamEventClassification,
delegate: ClickstreamDelegate? = nil,
updateConnectionStatus: Bool = false,
timerCrashFixFlag: Bool = false,
appPrefix: String) throws -> Clickstream? {
let semaphore = DispatchSemaphore(value: 1)
defer {
Expand All @@ -223,6 +230,7 @@ public final class Clickstream {
Clickstream.configurations = configurations
Clickstream.eventClassifier = eventClassification
Clickstream.updateConnectionStatus = updateConnectionStatus
Clickstream.timerCrashFixFlag = timerCrashFixFlag
Clickstream.appPrefix = appPrefix.lowercased().replacingOccurrences(of: " ", with: "")

// All the dependency injections pertaining to the clickstream blocks happen here!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import Foundation
/// already resumed (noted by https://github.com/SiftScience/sift-ios/issues/52)
class RepeatingTimer {

let timeInterval: TimeInterval
static let shared = RepeatingTimer()

var timeInterval: TimeInterval = 0

private var suspensionCount = 0

private init() { }

init(timeInterval: TimeInterval) {
self.timeInterval = timeInterval
Expand Down Expand Up @@ -53,19 +59,33 @@ class RepeatingTimer {
if state.value == .resumed {
return
}
suspensionCount -= 1
state.mutate { state in
state = .resumed
}
timer.resume()
if Clickstream.timerCrashFixFlag {
if suspensionCount > 0 {
self.timer.resume()
}
} else {
timer.resume()
}
}

func suspend() {
if state.value == .suspended {
return
}
suspensionCount += 1
state.mutate { state in
state = .suspended
}
timer.suspend()
if Clickstream.timerCrashFixFlag {
if suspensionCount > 0 {
timer.suspend()
}
} else {
timer.suspend()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,28 @@ final class DefaultKeepAliveServiceWithSafeTimer: KeepAliveService {

@discardableResult
private func makeTimer() -> RepeatingTimer? {
let timerDuration = duration*reachability.connectionRetryCoefficient
timer = RepeatingTimer(timeInterval: timerDuration)
timer?.eventHandler = { [weak self] in
guard let checkedSelf = self else { return }
checkedSelf.performQueue.async {
checkedSelf.subscriber?()
if Clickstream.timerCrashFixFlag {
let timerDuration = duration*reachability.connectionRetryCoefficient
RepeatingTimer.shared.timeInterval = timerDuration
self.timer = RepeatingTimer.shared
timer?.eventHandler = { [weak self] in
guard let checkedSelf = self else { return }
checkedSelf.performQueue.async {
checkedSelf.subscriber?()
}
}
return timer
} else {
let timerDuration = duration*reachability.connectionRetryCoefficient
self.timer = RepeatingTimer(timeInterval: timerDuration)
timer?.eventHandler = { [weak self] in
guard let checkedSelf = self else { return }
checkedSelf.performQueue.async {
checkedSelf.subscriber?()
}
}
return timer
}
return timer
}

func stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import SwiftProtobuf
import UIKit

protocol EventDetailsModelInput: AnyObject {

Expand Down
2 changes: 1 addition & 1 deletion Sources/EventVisualizer/src/Helpers/CollectionMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public extension CollectionMapper {
func flattenRec(output: inout [String: Any], keyPath: String, value: Any) {
if let dict = value as? [String: Any] {
dict.forEach { key, value in
let calculatedKey = "\(keyPath).\(key)".replacingOccurrences(of: "_", with: "")
let calculatedKey = "\(keyPath).\(key)".replacingOccurrences(of: "_", with: "").replacingOccurrences(of: "storage.", with: "")
flattenRec(output: &output, keyPath: calculatedKey, value: value)
}
} else {
Expand Down
8 changes: 6 additions & 2 deletions Sources/EventVisualizer/src/Helpers/EventsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ extension EventsHelper: EventStateViewable {
/// - eventBatch: this is the eventBatchGuid for a particular event batch
/// - state: this is the state in which the event is in
public func updateStatus(providedEventGuid: String? = nil, eventBatchID eventBatch: String? = nil, state: EventState) {
if let providedEventGuid = providedEventGuid, let foundIndex = indexOfEvent(with: providedEventGuid) {
if let providedEventGuid = providedEventGuid,
let foundIndex = indexOfEvent(with: providedEventGuid),
foundIndex < EventsHelper.shared.eventsCaptured.count {

EventsHelper.shared.eventsCaptured[foundIndex].state = state
if let eventBatch = eventBatch {
Expand All @@ -100,7 +102,9 @@ extension EventsHelper: EventStateViewable {
} else if let eventBatch = eventBatch {
let foundIndexs = indexOfEventBatch(with: eventBatch)
for eventIndex in foundIndexs {
EventsHelper.shared.eventsCaptured[eventIndex].state = state
if eventIndex < EventsHelper.shared.eventsCaptured.count {
EventsHelper.shared.eventsCaptured[eventIndex].state = state
}
}
}
}
Expand Down

0 comments on commit 36c93a8

Please sign in to comment.