Skip to content

Commit

Permalink
3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
piano-analytics committed Jun 13, 2022
1 parent 48761d5 commit a890f05
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 10 deletions.
2 changes: 1 addition & 1 deletion PianoAnalytics-AppExtension.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PianoAnalytics-AppExtension'
s.version = '3.0.0'
s.version = '3.0.1'
s.summary = 'Piano Analytics solution for extension Apple devices'
s.homepage = 'https://github.com/at-internet/piano-analytics-apple'
s.documentation_url = 'https://developers.atinternet-solutions.com/piano-analytics'
Expand Down
2 changes: 1 addition & 1 deletion PianoAnalytics.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PianoAnalytics'
s.version = '3.0.0'
s.version = '3.0.1'
s.summary = 'Piano Analytics library for Apple devices'
s.homepage = 'https://github.com/at-internet/piano-analytics-apple'
s.documentation_url = 'https://developers.atinternet-solutions.com/piano-analytics'
Expand Down
51 changes: 46 additions & 5 deletions Sources/PianoAnalytics/Core/UserDefaultKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,61 @@

import Foundation

// MARK: Storage keys

enum PrivacyKeys: String, CaseIterable {
case PrivacyMode = "PAPrivacyMode"
case PrivacyModeExpirationTimestamp = "PAPrivacyModeExpirationTimestamp"
case PrivacyVisitorConsent = "PAPrivacyVisitorConsent"
case PrivacyVisitorId = "PAPrivacyUserId"
}

enum VisitorIdKeys: String, CaseIterable {
case VisitorUUID = "PAApplicationUniqueIdentifier"
case VisitorUUIDGenerationTimestamp = "PAUserIdGenerationTimestamp"
}

enum LifeCycleKeys: String, CaseIterable {
case FirstInitLifecycleDone = "PAFirstInitLifecycleDone"
case InitLifecycleDone = "PAInitLifecycleDone"
case FirstSession = "PAFirstLaunch"
case FirstSessionAfterUpdate = "PAFirstLaunchAfterUpdate"
case LastSessionDate = "PALastUse"
case FirstSessionDate = "PAFirstLaunchDate"
case SessionCount = "PALaunchCount"
case LastApplicationVersion = "PALastApplicationVersion"
case FirstSessionDateAfterUpdate = "PAApplicationUpdate"
case SessionCountSinceUpdate = "PALaunchCountSinceUpdate"
case DaysSinceFirstSession = "PADaysSinceFirstSession"
case DaysSinceUpdate = "PADaysSinceUpdate"
case DaysSinceLastSession = "PADaysSinceLastSession"
}

enum CrashKeys: String, CaseIterable {
case Crashed = "PACrashed"
case CrashInfo = "PACrashInfo"
}

enum UserKeys: String, CaseIterable {
case Users = "PAUsers"
case UserGenerationTimestamp = "PAUserGenerationTimestamp"
}

// MARK: Old storage keys (v2 SDK retrocompatibility)

enum ATPrivacyKeys: String {
case PrivacyMode = "ATPrivacyMode"
case PrivacyModeExpirationTimestamp = "ATPrivacyModeExpirationTimestamp"
case PrivacyVisitorConsent = "ATPrivacyVisitorConsent"
case PrivacyVisitorId = "ATPrivacyUserId"
}

enum VisitorIdKeys: String, CaseIterable {
enum ATVisitorIdKeys: String, CaseIterable {
case VisitorUUID = "ATApplicationUniqueIdentifier"
case VisitorUUIDGenerationTimestamp = "ATUserIdGenerationTimestamp"
}

enum LifeCycleKeys: String, CaseIterable {
enum ATLifeCycleKeys: String, CaseIterable {
case FirstInitLifecycleDone = "ATFirstInitLifecycleDone"
case InitLifecycleDone = "ATInitLifecycleDone"
case FirstSession = "ATFirstLaunch"
Expand All @@ -53,12 +95,11 @@ enum LifeCycleKeys: String, CaseIterable {
case DaysSinceLastSession = "ATDaysSinceLastSession"
}

enum CrashKeys: String, CaseIterable {
enum ATCrashKeys: String, CaseIterable {
case Crashed = "ATCrashed"
case CrashInfo = "ATCrashInfo"
}

enum UserKeys: String, CaseIterable {
enum ATUserKeys: String, CaseIterable {
case Users = "ATUsers"
case UserGenerationTimestamp = "PAUserGenerationTimestamp"
}
13 changes: 13 additions & 0 deletions Sources/PianoAnalytics/Steps/CrashHandlingStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ final class CrashHandlingStep: Step {
private final var isCrashHandlingRegistered: Bool = false

private init(ps: PrivacyStep) {
let oldStorageKeyWithNew: [ATCrashKeys: CrashKeys] = [
ATCrashKeys.Crashed: CrashKeys.Crashed,
ATCrashKeys.CrashInfo: CrashKeys.CrashInfo
]
for (oldStorageKey, newStorageKey) in oldStorageKeyWithNew {
if (UserDefaults.standard.value(forKey: newStorageKey.rawValue) == nil) {
if let oldValue = UserDefaults.standard.value(forKey: oldStorageKey.rawValue) {
UserDefaults.standard.set(oldValue, forKey: newStorageKey.rawValue)
UserDefaults.standard.removeObject(forKey: oldStorageKey.rawValue)
}
}
}

self.privacyStep = ps
self.exceptionHandler = { exception in
let userDefaults = UserDefaults.standard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ final class InternalContextPropertiesStep: Step {
static let BrowserLanguagePropertiesFormat = "browser_language%@"

private static let Manufacturer = "Apple"
private static let EventCollectionVersion = "3.0.0"
private static let EventCollectionVersion = "3.0.1"

#if os(tvOS)
private static let Platform = "tvOS"
Expand Down
24 changes: 24 additions & 0 deletions Sources/PianoAnalytics/Steps/LifecycleStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ final class LifecycleStep: Step {
private final var sessionBackgroundDuration: Int?

private init(ps: PrivacyStep) {
let oldStorageKeyWithNew: [ATLifeCycleKeys: LifeCycleKeys] = [
ATLifeCycleKeys.FirstInitLifecycleDone: LifeCycleKeys.FirstInitLifecycleDone,
ATLifeCycleKeys.InitLifecycleDone: LifeCycleKeys.InitLifecycleDone,
ATLifeCycleKeys.FirstSession: LifeCycleKeys.FirstSession,
ATLifeCycleKeys.FirstSessionAfterUpdate: LifeCycleKeys.FirstSessionAfterUpdate,
ATLifeCycleKeys.LastSessionDate: LifeCycleKeys.LastSessionDate,
ATLifeCycleKeys.FirstSessionDate: LifeCycleKeys.FirstSessionDate,
ATLifeCycleKeys.SessionCount: LifeCycleKeys.SessionCount,
ATLifeCycleKeys.LastApplicationVersion: LifeCycleKeys.LastApplicationVersion,
ATLifeCycleKeys.FirstSessionDateAfterUpdate: LifeCycleKeys.FirstSessionDateAfterUpdate,
ATLifeCycleKeys.SessionCountSinceUpdate: LifeCycleKeys.SessionCountSinceUpdate,
ATLifeCycleKeys.DaysSinceFirstSession: LifeCycleKeys.DaysSinceFirstSession,
ATLifeCycleKeys.DaysSinceUpdate: LifeCycleKeys.DaysSinceUpdate,
ATLifeCycleKeys.DaysSinceLastSession: LifeCycleKeys.DaysSinceLastSession
]
for (oldStorageKey, newStorageKey) in oldStorageKeyWithNew {
if (UserDefaults.standard.value(forKey: newStorageKey.rawValue) == nil) {
if let oldValue = UserDefaults.standard.value(forKey: oldStorageKey.rawValue) {
UserDefaults.standard.set(oldValue, forKey: newStorageKey.rawValue)
UserDefaults.standard.removeObject(forKey: oldStorageKey.rawValue)
}
}
}

self.privacyStep = ps
self.computingMetrics = [daysSinceFirstSession, daysSinceLastSession, daysSinceUpdate]
let notificationCenter = NotificationCenter.default
Expand Down
15 changes: 15 additions & 0 deletions Sources/PianoAnalytics/Steps/PrivacyStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ final class PrivacyStep: Step {
private final let configurationStep: ConfigurationStep

init(_ cs: ConfigurationStep) {
let oldStorageKeyWithNew: [ATPrivacyKeys: PrivacyKeys] = [
ATPrivacyKeys.PrivacyMode: PrivacyKeys.PrivacyMode,
ATPrivacyKeys.PrivacyModeExpirationTimestamp: PrivacyKeys.PrivacyModeExpirationTimestamp,
ATPrivacyKeys.PrivacyVisitorConsent: PrivacyKeys.PrivacyVisitorConsent,
ATPrivacyKeys.PrivacyVisitorId: PrivacyKeys.PrivacyVisitorId
]
for (oldStorageKey, newStorageKey) in oldStorageKeyWithNew {
if (UserDefaults.standard.value(forKey: newStorageKey.rawValue) == nil) {
if let oldValue = UserDefaults.standard.value(forKey: oldStorageKey.rawValue) {
UserDefaults.standard.set(oldValue, forKey: newStorageKey.rawValue)
UserDefaults.standard.removeObject(forKey: oldStorageKey.rawValue)
}
}
}

self.configurationStep = cs
}

Expand Down
8 changes: 8 additions & 0 deletions Sources/PianoAnalytics/Steps/UsersStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ final class UsersStep: Step {
private var userRecognition: Bool = false

init(_ ps: PrivacyStep) {
if (UserDefaults.standard.value(forKey: UserKeys.Users.rawValue) == nil) {
if let oldValue = UserDefaults.standard.value(forKey: ATUserKeys.Users.rawValue) {
UserDefaults.standard.set(oldValue, forKey: UserKeys.Users.rawValue)
UserDefaults.standard.set(Int64(Date().timeIntervalSince1970) * 1000, forKey: UserKeys.UserGenerationTimestamp.rawValue)
UserDefaults.standard.removeObject(forKey: ATUserKeys.Users.rawValue)
}
}

self.privacyStep = ps
}

Expand Down
14 changes: 14 additions & 0 deletions Sources/PianoAnalytics/Steps/VisitorIDStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ final class VisitorIDStep: Step {
private final let privacyStep: PrivacyStep

private init(ps: PrivacyStep) {
let oldStorageKeyWithNew: [ATVisitorIdKeys: VisitorIdKeys] = [
ATVisitorIdKeys.VisitorUUID: VisitorIdKeys.VisitorUUID,
ATVisitorIdKeys.VisitorUUIDGenerationTimestamp: VisitorIdKeys.VisitorUUIDGenerationTimestamp
]
for (oldStorageKey, newStorageKey) in oldStorageKeyWithNew {
if (UserDefaults.standard.value(forKey: newStorageKey.rawValue) == nil) {
if let oldValue = UserDefaults.standard.value(forKey: oldStorageKey.rawValue) {
UserDefaults.standard.set(oldValue, forKey: newStorageKey.rawValue)
UserDefaults.standard.removeObject(forKey: oldStorageKey.rawValue)
}
}
}


self.privacyStep = ps
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/PianoAnalytics/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public final class User {

init(_ obj: [String: String]?) {
self.id = obj?[User.Id]
self.category = obj?[User.Category]
self.category = obj?[User.Category] != "" ? obj?[User.Category] : nil
}

final func toString() -> String {
guard let jsonData = PianoAnalyticsUtils.toJSONData([
User.Id: id,
User.Category: category
User.Category: category ?? ""
]) else {
return ""
}
Expand Down

0 comments on commit a890f05

Please sign in to comment.