Skip to content

Commit

Permalink
Merge branch 'task/show-timestamp-in-ev-details' of github.com:gojek/…
Browse files Browse the repository at this point in the history
…clickstream-ios into task/show-timestamp-in-ev-details
  • Loading branch information
AbhijeetMallick committed Jan 8, 2024
2 parents c8ec0d6 + 619fd0a commit 8cafb88
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 60 deletions.
2 changes: 1 addition & 1 deletion 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 = "1.1.22"
s.version = "2.0.14"
s.summary = "Real time Analytics SDK"
s.description = "Clickstream is an event agnostic, real-time data ingestion analytics SDK"

Expand Down
129 changes: 92 additions & 37 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.
13 changes: 6 additions & 7 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- GRDB.swift (6.14.0):
- GRDB.swift/standard (= 6.14.0)
- GRDB.swift/standard (6.14.0)
- GRDB.swift (6.15.1):
- GRDB.swift/standard (= 6.15.1)
- GRDB.swift/standard (6.15.1)
- ReachabilitySwift (5.0.0)
- SwiftProtobuf (1.21.0)
- SwiftProtobuf (1.22.0)

DEPENDENCIES:
- GRDB.swift (~> 6.7)
Expand All @@ -13,14 +13,13 @@ DEPENDENCIES:
SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- GRDB.swift
trunk:
- ReachabilitySwift
- SwiftProtobuf

SPEC CHECKSUMS:
GRDB.swift: d31072a99e8d3d9f5410f1a938018ccb51b881e2
GRDB.swift: a6b7e9900aa300d0cbf1f1c5f47b8f32ae51e30c
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7
SwiftProtobuf: 40bd808372cb8706108f22d28f8ab4a6b9bc6989

PODFILE CHECKSUM: 2c97fb10dcb1fcd309b15a9c7e84ddc137998638

Expand Down
1 change: 1 addition & 0 deletions Sources/Clickstream/Core/Data/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ enum Constants {
}

enum EventVisualizer {
static var eventGID = "eventGuid"
static var eventGuid = "meta.eventGuid"
static var guid = "guid"
static var eventTimestamp = "eventTimestamp"
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ final class EventsListViewModel: EventsListViewModelInput {
let timestamp = message.asDictionary["\(Constants.EventVisualizer.deviceTimestamp)"] as? Date {
eventTimeStamp = "\(timestamp)"
state = EventsHelper.shared.getState(of: eventGuid)
} else if let eventGuid = message.asDictionary["storage.meta.storage.\(Constants.EventVisualizer.eventGID)"] as? String,
let timestamp = message.asDictionary["storage.\(Constants.EventVisualizer.eventTimestamp)"] as? SwiftProtobuf.Google_Protobuf_Timestamp {
eventTimeStamp = "\(timestamp.date)"
state = EventsHelper.shared.getState(of: eventGuid)
}
}
return EventDisplayKeys(eventTimeStamp: eventTimeStamp, state: state)
Expand Down
17 changes: 12 additions & 5 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 All @@ -113,12 +117,15 @@ extension EventsHelper: EventStateViewable {
if let currentEventGuid = flattenedDict[Constants.EventVisualizer.eventGuid] as? String, currentEventGuid == eventGuid {
return index
} else if let currentEventGuid = flattenedDict["storage.\(Constants.EventVisualizer.eventGuid)"] as? String,
currentEventGuid == eventGuid {
currentEventGuid == eventGuid {
return index
} else if let currentEventGuid = flattenedDict[Constants.EventVisualizer.guid] as? String,
currentEventGuid == eventGuid {
return index
}
return index
} else if let currentEventGuid = flattenedDict["storage.meta.storage.\(Constants.EventVisualizer.eventGID)"] as? String,
currentEventGuid == eventGuid {
return index
}
}
}
return nil
Expand Down

0 comments on commit 8cafb88

Please sign in to comment.