Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all internal tracking and fix crashes caused by it #646

Merged
merged 2 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Swift Lint
run: swiftlint
- name: Run Test
working-directory: MixpanelDemo
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Swift Lint
run: swiftlint
- name: Run Test
working-directory: MixpanelDemo
run: |
Expand Down
12 changes: 9 additions & 3 deletions MixpanelDemo/MixpanelDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeamName = "Mixpanel, Inc.";
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.ApplePay = {
enabled = 0;
Expand Down Expand Up @@ -1841,10 +1840,10 @@
CODE_SIGN_ENTITLEMENTS = MixpanelDemo/MixpanelDemo.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 6;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = E8FVX7QLET;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = MixpanelDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -1899,8 +1898,12 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = AXVA7A4XGX;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"COCOAPODS=1",
Expand Down Expand Up @@ -1928,6 +1931,8 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = MixpanelDemoTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -1937,6 +1942,7 @@
LIBRARY_SEARCH_PATHS = "$(SRCROOT)/../Mixpanel";
PRODUCT_BUNDLE_IDENTIFIER = com.mixpanel.MixpanelDemoTests;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-O";
Expand Down
10 changes: 0 additions & 10 deletions Sources/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ struct BundleConstants {
static let ID = "com.mixpanel.Mixpanel"
}

struct InternalKeys {
static let mpDebugTrackedKey = "mpDebugTrackedKey"
static let mpDebugInitCountKey = "mpDebugInitCountKey"
static let mpDebugImplementedKey = "mpDebugImplementedKey"
static let mpDebugIdentifiedKey = "mpDebugIdentifiedKey"
static let mpDebugAliasedKey = "mpDebugAliasedKey"
static let mpDebugUsedPeopleKey = "mpDebugUsedPeopleKey"
}


#if !os(OSX) && !os(watchOS) && !os(visionOS)
extension UIDevice {
var iPhoneX: Bool {
Expand Down
89 changes: 1 addition & 88 deletions Sources/MixpanelInstance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
if (superProperties["$lib_version"] != nil) {
trackProps["$lib_version"] = self.superProperties["$lib_version"] as! String
}
// add headers
let headers = self.proxyServerDelegate?.mixpanelResourceForProxyServer(name)?.headers ?? [:]
Network.sendHttpEvent(serverURL: self.serverURL, headers: headers, eventName: "Toggle SDK Logging", apiToken: "metrics-1", distinctId: apiToken, properties: trackProps)
#endif
}
}
Expand Down Expand Up @@ -325,17 +322,6 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
self.serverURL = serverURL
}
self.proxyServerDelegate = proxyServerDelegate
#if DEBUG
//add headers here
let headers = proxyServerDelegate?.mixpanelResourceForProxyServer(name)?.headers ?? [:]
MixpanelInstance.didDebugInit(
serverURL: self.serverURL,
headers: headers,
distinctId: self.apiToken,
libName: superProperties?.get(key: "mp_lib", defaultValue: nil),
libVersion: superProperties?.get(key: "$lib_version", defaultValue: nil)
)
#endif
let label = "com.mixpanel.\(self.apiToken)"
trackingQueue = DispatchQueue(label: "\(label).tracking)", qos: .utility, autoreleaseFrequency: .workItem)
networkQueue = DispatchQueue(label: "\(label).network)", qos: .utility, autoreleaseFrequency: .workItem)
Expand Down Expand Up @@ -409,7 +395,6 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
#if !os(OSX) && !os(watchOS)
private func setupListeners() {
let notificationCenter = NotificationCenter.default
trackIntegration()
#if os(iOS) && !targetEnvironment(macCatalyst)
setCurrentRadio()
// Temporarily remove the ability to monitor the radio change due to a crash issue might relate to the api from Apple
Expand Down Expand Up @@ -646,54 +631,6 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele
}
#endif
#endif // os(iOS)
private class func didDebugInit(serverURL: String, headers: [String: String], distinctId: String, libName: String?, libVersion: String?) {
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
}
// add headers
Network.sendHttpEvent(serverURL: serverURL, headers: headers, eventName: "SDK Debug Launch", apiToken: "metrics-1", distinctId: distinctId, properties: properties) { (_) in }
checkIfImplemented(serverURL: serverURL, headers: headers, distinctId: distinctId, properties: properties)
UserDefaults.standard.set(debugInitCount, forKey: InternalKeys.mpDebugInitCountKey)
UserDefaults.standard.synchronize()
}
}

private class func checkIfImplemented(serverURL: String, headers: [String: String], distinctId: String, properties: Properties) {
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) {
let trackProps = properties.merging([
"Tracked": hasTracked,
"Identified": hasIdentified,
"Aliased": hasAliased,
"Used People": hasUsedPeople,
]) {(_,new) in new}
// add headers
Network.sendHttpEvent(
serverURL: serverURL, headers: headers,
eventName: "SDK Implemented",
apiToken: "metrics-1",
distinctId: distinctId,
properties: trackProps) { (_) in }
UserDefaults.standard.set(true, forKey: InternalKeys.mpDebugImplementedKey)
}
}
}

}

Expand Down Expand Up @@ -742,9 +679,6 @@ 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 }

Expand Down Expand Up @@ -843,9 +777,7 @@ 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 {
Expand Down Expand Up @@ -977,25 +909,6 @@ extension MixpanelInstance {
}
}
}

func trackIntegration() {
if hasOptedOutTracking() {
return
}
let defaultsKey = "trackedKey"
if !UserDefaults.standard.bool(forKey: defaultsKey) {
trackingQueue.async { [apiToken, defaultsKey, serverURL, name] in
// add headers
let headers = self.proxyServerDelegate?.mixpanelResourceForProxyServer(name)?.headers ?? [:]
Network.sendHttpEvent(serverURL: serverURL, headers: headers, eventName: "Integration", apiToken: "85053bf24bba75239b16a601d9387e17", distinctId: apiToken, updatePeople: false) { [defaultsKey] (success) in
if success {
UserDefaults.standard.set(true, forKey: defaultsKey)
UserDefaults.standard.synchronize()
}
}
}
}
}
}

extension MixpanelInstance {
Expand Down
69 changes: 0 additions & 69 deletions Sources/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,74 +132,5 @@ class Network {
headers: headers,
parse: parse)
}

class func sendHttpEvent(serverURL: String,
headers: [String: String],
eventName: String,
apiToken: String,
distinctId: String,
properties: Properties = [:],
updatePeople: Bool = true,
completion: ((Bool) -> Void)? = nil) {
let trackProperties = properties.merging(["token": apiToken,
"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] as [String : Any]])

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 resourceHeaders: [String: String] = ["Accept-Encoding": "gzip"].merging(headers) {(_,new) in new }

let resource = Network.buildResource(path: FlushType.events.rawValue,
method: .post,
requestBody: requestBody,
headers: resourceHeaders,
parse: responseParser)

Network.apiRequest(base: serverURL,
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)
}
}
)
}
if updatePeople {
let engageData = JSONHandler.encodeAPIData([["$token": apiToken, "$distinct_id": distinctId, "$add": [eventName: 1]] as [String : Any]])
if let engageData = engageData {
let resourceHeaders: [String: String] = ["Accept-Encoding": "gzip"].merging(headers) {(_,new) in new }

let engageBody = "ip=1&data=\(engageData)".data(using: String.Encoding.utf8)
let engageResource = Network.buildResource(path: FlushType.people.rawValue,
method: .post,
requestBody: engageBody,
headers: resourceHeaders,
parse: responseParser)
Network.apiRequest(base: serverURL, resource: engageResource) { _, _, _ in } success: { _, _ in }
}
}
}
}

5 changes: 0 additions & 5 deletions Sources/People.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ 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

Expand Down
5 changes: 0 additions & 5 deletions Sources/Track.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ class Track {
return timedEvents
}
assertPropertyTypes(properties)
#if DEBUG
if !ev.hasPrefix("$") {
UserDefaults.standard.set(true, forKey: InternalKeys.mpDebugTrackedKey)
}
#endif
let epochMilliseconds = round(epochInterval * 1000)
let eventStartTime = timedEvents[ev] as? Double
var p = InternalProperties()
Expand Down
Loading