From 84672c5f8ca62c7712c7cb0988aa795954a0bdb4 Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Tue, 3 May 2022 12:51:24 -0700 Subject: [PATCH 01/12] track implemenation and each launch --- .../MixpanelDemoWatch (Notification).xcscheme | 25 +++++++--- .../xcschemes/MixpanelDemoWatch.xcscheme | 25 +++++++--- Sources/Constants.swift | 11 +++++ Sources/Mixpanel.swift | 49 ++++++++++++++----- Sources/MixpanelInstance.swift | 8 ++- Sources/People.swift | 5 ++ Sources/Track.swift | 6 ++- 7 files changed, 102 insertions(+), 27 deletions(-) diff --git a/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch (Notification).xcscheme b/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch (Notification).xcscheme index fd96ecdd..c59d330b 100644 --- a/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch (Notification).xcscheme +++ b/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch (Notification).xcscheme @@ -55,8 +55,10 @@ debugServiceExtension = "internal" allowLocationSimulation = "YES" launchAutomaticallySubstyle = "8"> - + - + - + - + + + + + diff --git a/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch.xcscheme b/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch.xcscheme index c525f754..48984293 100644 --- a/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch.xcscheme +++ b/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch.xcscheme @@ -54,8 +54,10 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - + - + - + - + + + + + diff --git a/Sources/Constants.swift b/Sources/Constants.swift index 0d61d967..2207d329 100644 --- a/Sources/Constants.swift +++ b/Sources/Constants.swift @@ -26,6 +26,17 @@ struct BundleConstants { static let ID = "com.mixpanel.Mixpanel" } +struct InternalKeys { + static let mpDebugTrackedKey = "mpDebugTrackedKey" + static let mpDebugInitCountKey = "mpDebugInitCountKey" + static let mpSurveyShownDateKey = "mpSurveyShownDateKey" + static let mpDebugImplementedKey = "mpDebugImplementedKey" + static let mpDebugIdentifiedKey = "mpDebugIdentifiedKey" + static let mpDebugAliasedKey = "mpDebugAliasedKey" + static let mpDebugUsedPeopleKey = "mpDebugUsedPeopleKey" +} + + #if !os(OSX) && !os(watchOS) extension UIDevice { var iPhoneX: Bool { diff --git a/Sources/Mixpanel.swift b/Sources/Mixpanel.swift index 93058f27..5e62449f 100644 --- a/Sources/Mixpanel.swift +++ b/Sources/Mixpanel.swift @@ -149,29 +149,54 @@ open class Mixpanel { } private class func didDebugInit(distinctId: String) { - let debugInitCountKey = "MPDebugInitCountKey" - let debugInitCount = UserDefaults.standard.integer(forKey: debugInitCountKey) + 1 - if debugInitCount == 1 { - Network.sendHttpEvent(eventName: "First SDK Debug Launch", apiToken: "metrics-1", distinctId: distinctId) { (_) in } - } + let debugInitCount = UserDefaults.standard.integer(forKey: InternalKeys.mpDebugInitCountKey) + 1 + Network.sendHttpEvent(eventName: "SDK Debug Launch", apiToken: "metrics-1", distinctId: distinctId, properties: ["Debug Launch Count": debugInitCount]) { (_) in } checkForSurvey(distinctId: distinctId, debugInitCount: debugInitCount) - UserDefaults.standard.set(debugInitCount, forKey: debugInitCountKey) + checkIfImplemented(distinctId: distinctId, debugInitCount: debugInitCount) + UserDefaults.standard.set(debugInitCount, forKey: InternalKeys.mpDebugInitCountKey) UserDefaults.standard.synchronize() } private class func checkForSurvey(distinctId: String, debugInitCount: Int) { - let surveyShownCountKey = "MPSurveyShownCountKey" - var surveyShownCount = UserDefaults.standard.integer(forKey: surveyShownCountKey) - if (debugInitCount > 10 && surveyShownCount < 1) || (debugInitCount > 20 && surveyShownCount < 2) || (debugInitCount > 30 && surveyShownCount < 3) { + let surveyShownDate = UserDefaults.standard.object(forKey: InternalKeys.mpSurveyShownDateKey) as? Date ?? Date.distantPast + if (surveyShownDate.timeIntervalSinceNow < -86400) { let waveHand = UnicodeScalar(0x1f44b) ?? "*" let thumbsUp = UnicodeScalar(0x1f44d) ?? "*" let thumbsDown = UnicodeScalar(0x1f44e) ?? "*" print(""" \(waveHand)\(waveHand) Zihe & Jared here, tell us about the Mixpanel developer experience! https://www.mixpanel.com/devnps \(thumbsUp)\(thumbsDown) """) - surveyShownCount += 1 - UserDefaults.standard.set(surveyShownCount, forKey: surveyShownCountKey) - Network.sendHttpEvent(eventName: "Dev NPS Survey Logged", apiToken: "metrics-1", distinctId: distinctId, properties: ["Survey Shown Count": surveyShownCount, "Debug Launch Count": debugInitCount]) { (_) in } + UserDefaults.standard.set(Date(), forKey: InternalKeys.mpSurveyShownDateKey) + Network.sendHttpEvent(eventName: "Dev NPS Survey Logged", apiToken: "metrics-1", distinctId: distinctId, properties: ["Debug Launch Count": debugInitCount]) { (_) in } + } + } + + private class func checkIfImplemented(distinctId: String, debugInitCount: Int) { + let hasImplemented: Bool = UserDefaults.standard.bool(forKey: InternalKeys.mpDebugImplementedKey) + if !hasImplemented { + var completed = 0 + let hasTracked: Bool = UserDefaults.standard.bool(forKey: InternalKeys.mpDebugTrackedKey) + completed += hasTracked ? 1 : 0 + let hasIdentified: Bool = UserDefaults.standard.bool(forKey: InternalKeys.mpDebugIdentifiedKey) + completed += hasIdentified ? 1 : 0 + let hasAliased: Bool = UserDefaults.standard.bool(forKey: InternalKeys.mpDebugAliasedKey) + completed += hasAliased ? 1 : 0 + let hasUsedPeople: Bool = UserDefaults.standard.bool(forKey: InternalKeys.mpDebugUsedPeopleKey) + completed += hasUsedPeople ? 1 : 0 + if (completed >= 3) { + Network.sendHttpEvent( + eventName: "SDK Implemented", + apiToken: "metrics-1", + distinctId: distinctId, + properties: [ + "Tracked": hasTracked, + "Identified": hasIdentified, + "Aliased": hasAliased, + "Used People": hasUsedPeople, + "Debug Launch Count": debugInitCount, + ]) { (_) in } + UserDefaults.standard.set(true, forKey: InternalKeys.mpDebugImplementedKey) + } } } } diff --git a/Sources/MixpanelInstance.swift b/Sources/MixpanelInstance.swift index 855dd6cc..8c28893c 100644 --- a/Sources/MixpanelInstance.swift +++ b/Sources/MixpanelInstance.swift @@ -588,7 +588,9 @@ extension MixpanelInstance { } return } - + #if DEBUG + UserDefaults.standard.set(true, forKey: InternalKeys.mpDebugIdentifiedKey) + #endif trackingQueue.async { [weak self, distinctId, usePeople] in guard let self = self else { return } @@ -676,7 +678,9 @@ extension MixpanelInstance { } return } - + #if DEBUG + UserDefaults.standard.set(true, forKey: InternalKeys.mpDebugAliasedKey) + #endif if alias != distinctId { trackingQueue.async { [weak self, alias] in guard let self = self else { diff --git a/Sources/People.swift b/Sources/People.swift index 57a1f4e5..e27b58d5 100644 --- a/Sources/People.swift +++ b/Sources/People.swift @@ -44,6 +44,11 @@ open class People { if mixpanelInstance?.hasOptedOutTracking() ?? false { return } + #if DEBUG + if !(properties.keys.first?.hasPrefix("$ae_") ?? true) { + UserDefaults.standard.set(true, forKey: InternalKeys.mpDebugUsedPeopleKey) + } + #endif let epochMilliseconds = round(Date().timeIntervalSince1970 * 1000) let ignoreTimeCopy = ignoreTime diff --git a/Sources/Track.swift b/Sources/Track.swift index 1450e4a8..435d1e48 100644 --- a/Sources/Track.swift +++ b/Sources/Track.swift @@ -49,7 +49,11 @@ class Track { return timedEvents } assertPropertyTypes(properties) - + #if DEBUG + if !ev.hasPrefix("$") { + UserDefaults.standard.set(true, forKey: InternalKeys.mpDebugTrackedKey) + } + #endif let epochSeconds = Int(round(epochInterval)) let eventStartTime = timedEvents[ev] as? Double var p = InternalProperties() From 1b757dc7d7efe0e39af1cba6ed04b45a45df57d9 Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Tue, 3 May 2022 12:54:31 -0700 Subject: [PATCH 02/12] revert scheme changes --- .../MixpanelDemoWatch (Notification).xcscheme | 25 +++++-------------- .../xcschemes/MixpanelDemoWatch.xcscheme | 25 +++++-------------- 2 files changed, 12 insertions(+), 38 deletions(-) diff --git a/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch (Notification).xcscheme b/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch (Notification).xcscheme index c59d330b..fd96ecdd 100644 --- a/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch (Notification).xcscheme +++ b/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch (Notification).xcscheme @@ -55,10 +55,8 @@ debugServiceExtension = "internal" allowLocationSimulation = "YES" launchAutomaticallySubstyle = "8"> - + - + - + - - - - - + diff --git a/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch.xcscheme b/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch.xcscheme index 48984293..c525f754 100644 --- a/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch.xcscheme +++ b/MixpanelDemo/MixpanelDemo.xcodeproj/xcshareddata/xcschemes/MixpanelDemoWatch.xcscheme @@ -54,10 +54,8 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> - + - + - + - - - - - + From fddb11159a57816fb33c5afec6cb6fdb92ffe2ec Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Tue, 3 May 2022 15:53:03 -0700 Subject: [PATCH 03/12] survey shown count and distinct_id check --- Sources/Constants.swift | 1 + Sources/Mixpanel.swift | 5 ++- Sources/Network.swift | 72 +++++++++++++++++++++-------------------- 3 files changed, 42 insertions(+), 36 deletions(-) diff --git a/Sources/Constants.swift b/Sources/Constants.swift index 2207d329..8c0e60e0 100644 --- a/Sources/Constants.swift +++ b/Sources/Constants.swift @@ -34,6 +34,7 @@ struct InternalKeys { static let mpDebugIdentifiedKey = "mpDebugIdentifiedKey" static let mpDebugAliasedKey = "mpDebugAliasedKey" static let mpDebugUsedPeopleKey = "mpDebugUsedPeopleKey" + static let mpSurveyShownCountKey = "mpSurveyShownCountKey" } diff --git a/Sources/Mixpanel.swift b/Sources/Mixpanel.swift index dd521ec6..2f917e07 100644 --- a/Sources/Mixpanel.swift +++ b/Sources/Mixpanel.swift @@ -184,7 +184,10 @@ open class Mixpanel { open -> https://www.mixpanel.com/devnps \(thumbsUp)\(thumbsDown) """) UserDefaults.standard.set(Date(), forKey: InternalKeys.mpSurveyShownDateKey) - Network.sendHttpEvent(eventName: "Dev NPS Survey Logged", apiToken: "metrics-1", distinctId: distinctId, properties: properties) { (_) in } + let surveyShownCount = UserDefaults.standard.integer(forKey: InternalKeys.mpSurveyShownCountKey) + 1 + UserDefaults.standard.set(surveyShownCount, forKey: InternalKeys.mpSurveyShownCountKey) + let trackProps = properties.merging(["Survey Shown Count": surveyShownCount]) {(_,new) in new} + Network.sendHttpEvent(eventName: "Dev NPS Survey Logged", apiToken: "metrics-1", distinctId: distinctId, properties: trackProps) { (_) in } } } diff --git a/Sources/Network.swift b/Sources/Network.swift index 580ee5c7..136e176e 100644 --- a/Sources/Network.swift +++ b/Sources/Network.swift @@ -131,46 +131,48 @@ class Network { class func sendHttpEvent(eventName: String, apiToken: String, distinctId: String, properties: Properties = [:], completion: ((Bool) -> Void)? = nil) { - let trackProperties = properties.merging(["token": apiToken, - "mp_lib": "swift", - "distinct_id": distinctId, - "$lib_version": AutomaticProperties.libVersion()]) {(current, _) in current } - let requestData = JSONHandler.encodeAPIData([["event": eventName, "properties": trackProperties]]) - - let responseParser: (Data) -> Int? = { data in - let response = String(data: data, encoding: String.Encoding.utf8) - if let response = response { - return Int(response) ?? 0 - } - return nil - } - - if let requestData = requestData { - let requestBody = "ip=1&data=\(requestData)" - .data(using: String.Encoding.utf8) + if distinctId.count == 32 { + let trackProperties = properties.merging(["token": apiToken, + "mp_lib": "swift", + "distinct_id": distinctId, + "$lib_version": AutomaticProperties.libVersion()]) {(current, _) in current } + let requestData = JSONHandler.encodeAPIData([["event": eventName, "properties": trackProperties]]) - let resource = Network.buildResource(path: FlushType.events.rawValue, - method: .post, - requestBody: requestBody, - headers: ["Accept-Encoding": "gzip"], - parse: responseParser) - - Network.apiRequest(base: BasePath.DefaultMixpanelAPI, - resource: resource, - failure: { (_, _, _) in - Logger.debug(message: "failed to track \(eventName)") - if let completion = completion { - completion(false) + let responseParser: (Data) -> Int? = { data in + let response = String(data: data, encoding: String.Encoding.utf8) + if let response = response { + return Int(response) ?? 0 } + return nil + } + + if let requestData = requestData { + let requestBody = "ip=1&data=\(requestData)" + .data(using: String.Encoding.utf8) + + let resource = Network.buildResource(path: FlushType.events.rawValue, + method: .post, + requestBody: requestBody, + headers: ["Accept-Encoding": "gzip"], + parse: responseParser) - }, - success: { (_, _) in - Logger.debug(message: "\(eventName) tracked") - if let completion = completion { - completion(true) + Network.apiRequest(base: BasePath.DefaultMixpanelAPI, + resource: resource, + failure: { (_, _, _) in + Logger.debug(message: "failed to track \(eventName)") + if let completion = completion { + completion(false) + } + + }, + success: { (_, _) in + Logger.debug(message: "\(eventName) tracked") + if let completion = completion { + completion(true) + } } + ) } - ) } } } From 6845914b7f6cc47f8030fc2e6fe70434eb486308 Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Tue, 3 May 2022 16:01:30 -0700 Subject: [PATCH 04/12] move distinct_id check --- Sources/Mixpanel.swift | 26 ++++++++------- Sources/Network.swift | 72 ++++++++++++++++++++---------------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/Sources/Mixpanel.swift b/Sources/Mixpanel.swift index 2f917e07..178795d0 100644 --- a/Sources/Mixpanel.swift +++ b/Sources/Mixpanel.swift @@ -157,19 +157,21 @@ open class Mixpanel { } private class func didDebugInit(distinctId: String, libName: String?, libVersion: String?) { - let debugInitCount = UserDefaults.standard.integer(forKey: InternalKeys.mpDebugInitCountKey) + 1 - var properties: Properties = ["Debug Launch Count": debugInitCount] - if let libName = libName { - properties["mp_lib"] = libName - } - if let libVersion = libVersion { - properties["$lib_version"] = libVersion + if distinctId.count == 32 { + let debugInitCount = UserDefaults.standard.integer(forKey: InternalKeys.mpDebugInitCountKey) + 1 + var properties: Properties = ["Debug Launch Count": debugInitCount] + if let libName = libName { + properties["mp_lib"] = libName + } + if let libVersion = libVersion { + properties["$lib_version"] = libVersion + } + Network.sendHttpEvent(eventName: "SDK Debug Launch", apiToken: "metrics-1", distinctId: distinctId, properties: properties) { (_) in } + checkForSurvey(distinctId: distinctId, properties: properties) + checkIfImplemented(distinctId: distinctId, properties: properties) + UserDefaults.standard.set(debugInitCount, forKey: InternalKeys.mpDebugInitCountKey) + UserDefaults.standard.synchronize() } - Network.sendHttpEvent(eventName: "SDK Debug Launch", apiToken: "metrics-1", distinctId: distinctId, properties: properties) { (_) in } - checkForSurvey(distinctId: distinctId, properties: properties) - checkIfImplemented(distinctId: distinctId, properties: properties) - UserDefaults.standard.set(debugInitCount, forKey: InternalKeys.mpDebugInitCountKey) - UserDefaults.standard.synchronize() } private class func checkForSurvey(distinctId: String, properties: Properties) { diff --git a/Sources/Network.swift b/Sources/Network.swift index 136e176e..580ee5c7 100644 --- a/Sources/Network.swift +++ b/Sources/Network.swift @@ -131,48 +131,46 @@ class Network { class func sendHttpEvent(eventName: String, apiToken: String, distinctId: String, properties: Properties = [:], completion: ((Bool) -> Void)? = nil) { - if distinctId.count == 32 { - let trackProperties = properties.merging(["token": apiToken, - "mp_lib": "swift", - "distinct_id": distinctId, - "$lib_version": AutomaticProperties.libVersion()]) {(current, _) in current } - let requestData = JSONHandler.encodeAPIData([["event": eventName, "properties": trackProperties]]) - - let responseParser: (Data) -> Int? = { data in - let response = String(data: data, encoding: String.Encoding.utf8) - if let response = response { - return Int(response) ?? 0 - } - return nil + let trackProperties = properties.merging(["token": apiToken, + "mp_lib": "swift", + "distinct_id": distinctId, + "$lib_version": AutomaticProperties.libVersion()]) {(current, _) in current } + let requestData = JSONHandler.encodeAPIData([["event": eventName, "properties": trackProperties]]) + + let responseParser: (Data) -> Int? = { data in + let response = String(data: data, encoding: String.Encoding.utf8) + if let response = response { + return Int(response) ?? 0 } + return nil + } + + if let requestData = requestData { + let requestBody = "ip=1&data=\(requestData)" + .data(using: String.Encoding.utf8) - if let requestData = requestData { - let requestBody = "ip=1&data=\(requestData)" - .data(using: String.Encoding.utf8) - - let resource = Network.buildResource(path: FlushType.events.rawValue, - method: .post, - requestBody: requestBody, - headers: ["Accept-Encoding": "gzip"], - parse: responseParser) + let resource = Network.buildResource(path: FlushType.events.rawValue, + method: .post, + requestBody: requestBody, + headers: ["Accept-Encoding": "gzip"], + parse: responseParser) + + Network.apiRequest(base: BasePath.DefaultMixpanelAPI, + resource: resource, + failure: { (_, _, _) in + Logger.debug(message: "failed to track \(eventName)") + if let completion = completion { + completion(false) + } - Network.apiRequest(base: BasePath.DefaultMixpanelAPI, - resource: resource, - failure: { (_, _, _) in - Logger.debug(message: "failed to track \(eventName)") - if let completion = completion { - completion(false) - } - - }, - success: { (_, _) in - Logger.debug(message: "\(eventName) tracked") - if let completion = completion { - completion(true) - } + }, + success: { (_, _) in + Logger.debug(message: "\(eventName) tracked") + if let completion = completion { + completion(true) } - ) } + ) } } } From 8c34400e28065e08bb557569624ee2303bff8261 Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Tue, 3 May 2022 16:18:04 -0700 Subject: [PATCH 05/12] add engage data --- Sources/Network.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/Network.swift b/Sources/Network.swift index 580ee5c7..2cb90d01 100644 --- a/Sources/Network.swift +++ b/Sources/Network.swift @@ -172,5 +172,15 @@ class Network { } ) } + let engageData = JSONHandler.encodeAPIData([["$token": apiToken, "$distinct_id": distinctId, "$add": [eventName: 1]]]) + if let engageData = engageData { + let engageBody = "data=\(engageData)".data(using: String.Encoding.utf8) + let engageResource = Network.buildResource(path: FlushType.people.rawValue, + method: .post, + requestBody: engageBody, + headers: ["Accept-Encoding": "gzip"], + parse: responseParser) + Network.apiRequest(base: BasePath.DefaultMixpanelAPI, resource: engageResource) { _, _, _ in } success: { _, _ in } + } } } From a7445c38511ecb82a7c8d79edf6cb835496268e5 Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Wed, 4 May 2022 12:42:51 -0700 Subject: [PATCH 06/12] add DevX prop --- Sources/Network.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Network.swift b/Sources/Network.swift index 2cb90d01..978121b5 100644 --- a/Sources/Network.swift +++ b/Sources/Network.swift @@ -134,7 +134,8 @@ class Network { let trackProperties = properties.merging(["token": apiToken, "mp_lib": "swift", "distinct_id": distinctId, - "$lib_version": AutomaticProperties.libVersion()]) {(current, _) in current } + "$lib_version": AutomaticProperties.libVersion(), + "DevX": true]) {(current, _) in current } let requestData = JSONHandler.encodeAPIData([["event": eventName, "properties": trackProperties]]) let responseParser: (Data) -> Int? = { data in From 36bc1580ccccd80279de263ee236131f58107dc7 Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Thu, 5 May 2022 11:04:12 -0700 Subject: [PATCH 07/12] no engage for Integration and combine toggle loggin track --- Sources/MixpanelInstance.swift | 7 ++----- Sources/Network.swift | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Sources/MixpanelInstance.swift b/Sources/MixpanelInstance.swift index 481a31c5..5fada895 100644 --- a/Sources/MixpanelInstance.swift +++ b/Sources/MixpanelInstance.swift @@ -152,19 +152,16 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele Logger.enableLevel(.warning) Logger.enableLevel(.error) Logger.info(message: "Logging Enabled") -#if DEBUG - Network.sendHttpEvent(eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: ["Logging Enabled": true]) -#endif } else { Logger.info(message: "Logging Disabled") Logger.disableLevel(.debug) Logger.disableLevel(.info) Logger.disableLevel(.warning) Logger.disableLevel(.error) + } #if DEBUG - Network.sendHttpEvent(eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: ["Logging Enabled": false]) + Network.sendHttpEvent(eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: ["Logging Enabled": true]) #endif - } } } diff --git a/Sources/Network.swift b/Sources/Network.swift index 978121b5..24099847 100644 --- a/Sources/Network.swift +++ b/Sources/Network.swift @@ -173,15 +173,17 @@ class Network { } ) } - let engageData = JSONHandler.encodeAPIData([["$token": apiToken, "$distinct_id": distinctId, "$add": [eventName: 1]]]) - if let engageData = engageData { - let engageBody = "data=\(engageData)".data(using: String.Encoding.utf8) - let engageResource = Network.buildResource(path: FlushType.people.rawValue, - method: .post, - requestBody: engageBody, - headers: ["Accept-Encoding": "gzip"], - parse: responseParser) - Network.apiRequest(base: BasePath.DefaultMixpanelAPI, resource: engageResource) { _, _, _ in } success: { _, _ in } + if !(eventName == "Integration") { + let engageData = JSONHandler.encodeAPIData([["$token": apiToken, "$distinct_id": distinctId, "$add": [eventName: 1]]]) + if let engageData = engageData { + let engageBody = "data=\(engageData)".data(using: String.Encoding.utf8) + let engageResource = Network.buildResource(path: FlushType.people.rawValue, + method: .post, + requestBody: engageBody, + headers: ["Accept-Encoding": "gzip"], + parse: responseParser) + Network.apiRequest(base: BasePath.DefaultMixpanelAPI, resource: engageResource) { _, _, _ in } success: { _, _ in } + } } } } From d443c69000b14af73c73a2d660b5b0a9c3b049d0 Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Thu, 5 May 2022 11:09:44 -0700 Subject: [PATCH 08/12] include location --- Sources/Network.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Network.swift b/Sources/Network.swift index 24099847..eda5045c 100644 --- a/Sources/Network.swift +++ b/Sources/Network.swift @@ -176,7 +176,7 @@ class Network { if !(eventName == "Integration") { let engageData = JSONHandler.encodeAPIData([["$token": apiToken, "$distinct_id": distinctId, "$add": [eventName: 1]]]) if let engageData = engageData { - let engageBody = "data=\(engageData)".data(using: String.Encoding.utf8) + let engageBody = "ip=1&data=\(engageData)".data(using: String.Encoding.utf8) let engageResource = Network.buildResource(path: FlushType.people.rawValue, method: .post, requestBody: engageBody, From 37acbbe233bec8727105b014e86183873039e5e2 Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Thu, 5 May 2022 11:24:18 -0700 Subject: [PATCH 09/12] fix logginEnabled track --- Sources/MixpanelInstance.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/MixpanelInstance.swift b/Sources/MixpanelInstance.swift index 5fada895..3652b8b4 100644 --- a/Sources/MixpanelInstance.swift +++ b/Sources/MixpanelInstance.swift @@ -160,7 +160,7 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele Logger.disableLevel(.error) } #if DEBUG - Network.sendHttpEvent(eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: ["Logging Enabled": true]) + Network.sendHttpEvent(eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: ["Logging Enabled": loggingEnabled]) #endif } } From 79b69bc1bcab2f7649b0d4d57cbdc709e2a35c6a Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Thu, 5 May 2022 11:27:10 -0700 Subject: [PATCH 10/12] updatePeople --- Sources/MixpanelInstance.swift | 2 +- Sources/Network.swift | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/MixpanelInstance.swift b/Sources/MixpanelInstance.swift index 3652b8b4..dba7bddf 100644 --- a/Sources/MixpanelInstance.swift +++ b/Sources/MixpanelInstance.swift @@ -160,7 +160,7 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele Logger.disableLevel(.error) } #if DEBUG - Network.sendHttpEvent(eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: ["Logging Enabled": loggingEnabled]) + Network.sendHttpEvent(eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: ["Logging Enabled": loggingEnabled], updatePeople: false) #endif } } diff --git a/Sources/Network.swift b/Sources/Network.swift index eda5045c..3b0ad447 100644 --- a/Sources/Network.swift +++ b/Sources/Network.swift @@ -130,6 +130,7 @@ class Network { class func sendHttpEvent(eventName: String, apiToken: String, distinctId: String, properties: Properties = [:], + updatePeople: Bool = true, completion: ((Bool) -> Void)? = nil) { let trackProperties = properties.merging(["token": apiToken, "mp_lib": "swift", @@ -173,7 +174,7 @@ class Network { } ) } - if !(eventName == "Integration") { + if updatePeople { let engageData = JSONHandler.encodeAPIData([["$token": apiToken, "$distinct_id": distinctId, "$add": [eventName: 1]]]) if let engageData = engageData { let engageBody = "ip=1&data=\(engageData)".data(using: String.Encoding.utf8) From e6cedf5174ff02ad812ab9287624e23f6c7d0dc3 Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Thu, 5 May 2022 11:37:22 -0700 Subject: [PATCH 11/12] fix updatePeople --- Sources/MixpanelInstance.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/MixpanelInstance.swift b/Sources/MixpanelInstance.swift index dba7bddf..29894aeb 100644 --- a/Sources/MixpanelInstance.swift +++ b/Sources/MixpanelInstance.swift @@ -160,7 +160,7 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele Logger.disableLevel(.error) } #if DEBUG - Network.sendHttpEvent(eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: ["Logging Enabled": loggingEnabled], updatePeople: false) + Network.sendHttpEvent(eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: ["Logging Enabled": loggingEnabled]) #endif } } @@ -821,7 +821,7 @@ extension MixpanelInstance { let defaultsKey = "trackedKey" if !UserDefaults.standard.bool(forKey: defaultsKey) { trackingQueue.async { [apiToken, defaultsKey] in - Network.sendHttpEvent(eventName: "Integration", apiToken: "85053bf24bba75239b16a601d9387e17", distinctId: apiToken) { [defaultsKey] (success) in + Network.sendHttpEvent(eventName: "Integration", apiToken: "85053bf24bba75239b16a601d9387e17", distinctId: apiToken, updatePeople: false) { [defaultsKey] (success) in if success { UserDefaults.standard.set(true, forKey: defaultsKey) UserDefaults.standard.synchronize() From 19559221e1f0a9d0593bd4fb9d8b52ebe9e02adb Mon Sep 17 00:00:00 2001 From: Jared McFarland Date: Thu, 5 May 2022 12:09:05 -0700 Subject: [PATCH 12/12] add Project Token property --- Sources/Network.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Network.swift b/Sources/Network.swift index 3b0ad447..4f0c8d1e 100644 --- a/Sources/Network.swift +++ b/Sources/Network.swift @@ -136,6 +136,7 @@ class Network { "mp_lib": "swift", "distinct_id": distinctId, "$lib_version": AutomaticProperties.libVersion(), + "Project Token": distinctId, "DevX": true]) {(current, _) in current } let requestData = JSONHandler.encodeAPIData([["event": eventName, "properties": trackProperties]])