mirror of
https://github.com/mixpanel/mixpanel-swift
synced 2026-04-21 13:37:18 +00:00
Revert "Integrate common SDK to use the Event bridge (#709)"
This reverts commit 3ad0fb8221.
This commit is contained in:
parent
3ad0fb8221
commit
cf5ad74ba6
8 changed files with 1 additions and 388 deletions
|
|
@ -11,7 +11,6 @@ Pod::Spec.new do |s|
|
|||
:tag => "v#{s.version}" }
|
||||
s.resource_bundles = {'Mixpanel' => ['Sources/Mixpanel/PrivacyInfo.xcprivacy']}
|
||||
s.dependency 'jsonlogic', '~> 1.2.0'
|
||||
s.dependency 'MixpanelSwiftCommon', '~> 1.0.0'
|
||||
s.ios.deployment_target = '12.0'
|
||||
s.ios.frameworks = 'UIKit', 'Foundation', 'CoreTelephony'
|
||||
s.ios.pod_target_xcconfig = {
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@
|
|||
16178FD22F687EE200E022F2 /* jsonlogic in Frameworks */ = {isa = PBXBuildFile; productRef = 17JSONLOGIC00000003 /* jsonlogic */; };
|
||||
16178FD32F687EE200E022F2 /* jsonlogic in Frameworks */ = {isa = PBXBuildFile; productRef = 17JSONLOGIC00000004 /* jsonlogic */; };
|
||||
16178FD42F687EE200E022F2 /* jsonlogic in Frameworks */ = {isa = PBXBuildFile; productRef = 17JSONLOGIC00000005 /* jsonlogic */; };
|
||||
1651FD822F83B6E30065BB7E /* MixpanelSwiftCommon in Frameworks */ = {isa = PBXBuildFile; productRef = 1651FD812F83B6E30065BB7E /* MixpanelSwiftCommon */; };
|
||||
1651FD852F83B6F10065BB7E /* MixpanelSwiftCommon in Frameworks */ = {isa = PBXBuildFile; productRef = 1651FD842F83B6F10065BB7E /* MixpanelSwiftCommon */; };
|
||||
1651FD872F83B6F50065BB7E /* MixpanelSwiftCommon in Frameworks */ = {isa = PBXBuildFile; productRef = 1651FD862F83B6F50065BB7E /* MixpanelSwiftCommon */; };
|
||||
1651FD892F83B6F80065BB7E /* MixpanelSwiftCommon in Frameworks */ = {isa = PBXBuildFile; productRef = 1651FD882F83B6F80065BB7E /* MixpanelSwiftCommon */; };
|
||||
171E4C122DAF108400B7CB11 /* FeatureFlags.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171E4C112DAF108400B7CB11 /* FeatureFlags.swift */; };
|
||||
171E4C132DAF108400B7CB11 /* FeatureFlags.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171E4C112DAF108400B7CB11 /* FeatureFlags.swift */; };
|
||||
171E4C142DAF108400B7CB11 /* FeatureFlags.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171E4C112DAF108400B7CB11 /* FeatureFlags.swift */; };
|
||||
|
|
@ -158,7 +154,6 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
16178FD42F687EE200E022F2 /* jsonlogic in Frameworks */,
|
||||
1651FD892F83B6F80065BB7E /* MixpanelSwiftCommon in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
@ -166,7 +161,6 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
1651FD822F83B6E30065BB7E /* MixpanelSwiftCommon in Frameworks */,
|
||||
16178FD12F687EE200E022F2 /* jsonlogic in Frameworks */,
|
||||
E15FF7C61D02C9E10076CDE3 /* CoreTelephony.framework in Frameworks */,
|
||||
);
|
||||
|
|
@ -177,7 +171,6 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
16178FD22F687EE200E022F2 /* jsonlogic in Frameworks */,
|
||||
1651FD852F83B6F10065BB7E /* MixpanelSwiftCommon in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
@ -186,20 +179,12 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
16178FD32F687EE200E022F2 /* jsonlogic in Frameworks */,
|
||||
1651FD872F83B6F50065BB7E /* MixpanelSwiftCommon in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
1651FD832F83B6F10065BB7E /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
17C654792BB1EF6700C8A126 /* Mixpanel */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
@ -230,7 +215,6 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
E115947F1CFF1491007F8B4F /* Mixpanel */,
|
||||
1651FD832F83B6F10065BB7E /* Frameworks */,
|
||||
E115947E1CFF1491007F8B4F /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -369,7 +353,6 @@
|
|||
name = Mixpanel_watchOS;
|
||||
packageProductDependencies = (
|
||||
17JSONLOGIC00000005 /* jsonlogic */,
|
||||
1651FD882F83B6F80065BB7E /* MixpanelSwiftCommon */,
|
||||
);
|
||||
productName = Mixpanel_watchOS;
|
||||
productReference = 86F86E81224404BD00B69832 /* Mixpanel.framework */;
|
||||
|
|
@ -391,7 +374,6 @@
|
|||
name = Mixpanel;
|
||||
packageProductDependencies = (
|
||||
17JSONLOGIC00000002 /* jsonlogic */,
|
||||
1651FD812F83B6E30065BB7E /* MixpanelSwiftCommon */,
|
||||
);
|
||||
productName = Mixpanel;
|
||||
productReference = E115947D1CFF1491007F8B4F /* Mixpanel.framework */;
|
||||
|
|
@ -413,7 +395,6 @@
|
|||
name = Mixpanel_tvOS;
|
||||
packageProductDependencies = (
|
||||
17JSONLOGIC00000003 /* jsonlogic */,
|
||||
1651FD842F83B6F10065BB7E /* MixpanelSwiftCommon */,
|
||||
);
|
||||
productName = Mixpanel_tvOS;
|
||||
productReference = E12782B31D4AB4B30025FB05 /* Mixpanel.framework */;
|
||||
|
|
@ -435,7 +416,6 @@
|
|||
name = Mixpanel_macOS;
|
||||
packageProductDependencies = (
|
||||
17JSONLOGIC00000004 /* jsonlogic */,
|
||||
1651FD862F83B6F50065BB7E /* MixpanelSwiftCommon */,
|
||||
);
|
||||
productName = Mixpanel_OSX;
|
||||
productReference = E1F15FC91E64A10700391AE3 /* Mixpanel.framework */;
|
||||
|
|
@ -484,7 +464,6 @@
|
|||
mainGroup = E11594731CFF1491007F8B4F;
|
||||
packageReferences = (
|
||||
17JSONLOGIC00000001 /* XCRemoteSwiftPackageReference "json-logic-swift" */,
|
||||
1651FD802F83B6E30065BB7E /* XCRemoteSwiftPackageReference "mixpanel-swift-common" */,
|
||||
);
|
||||
productRefGroup = E115947E1CFF1491007F8B4F /* Products */;
|
||||
projectDirPath = "";
|
||||
|
|
@ -1145,14 +1124,6 @@
|
|||
/* End XCConfigurationList section */
|
||||
|
||||
/* Begin XCRemoteSwiftPackageReference section */
|
||||
1651FD802F83B6E30065BB7E /* XCRemoteSwiftPackageReference "mixpanel-swift-common" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/mixpanel/mixpanel-swift-common";
|
||||
requirement = {
|
||||
kind = upToNextMajorVersion;
|
||||
minimumVersion = 1.0.0;
|
||||
};
|
||||
};
|
||||
17JSONLOGIC00000001 /* XCRemoteSwiftPackageReference "json-logic-swift" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/advantagefse/json-logic-swift";
|
||||
|
|
@ -1164,26 +1135,6 @@
|
|||
/* End XCRemoteSwiftPackageReference section */
|
||||
|
||||
/* Begin XCSwiftPackageProductDependency section */
|
||||
1651FD812F83B6E30065BB7E /* MixpanelSwiftCommon */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 1651FD802F83B6E30065BB7E /* XCRemoteSwiftPackageReference "mixpanel-swift-common" */;
|
||||
productName = MixpanelSwiftCommon;
|
||||
};
|
||||
1651FD842F83B6F10065BB7E /* MixpanelSwiftCommon */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 1651FD802F83B6E30065BB7E /* XCRemoteSwiftPackageReference "mixpanel-swift-common" */;
|
||||
productName = MixpanelSwiftCommon;
|
||||
};
|
||||
1651FD862F83B6F50065BB7E /* MixpanelSwiftCommon */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 1651FD802F83B6E30065BB7E /* XCRemoteSwiftPackageReference "mixpanel-swift-common" */;
|
||||
productName = MixpanelSwiftCommon;
|
||||
};
|
||||
1651FD882F83B6F80065BB7E /* MixpanelSwiftCommon */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 1651FD802F83B6E30065BB7E /* XCRemoteSwiftPackageReference "mixpanel-swift-common" */;
|
||||
productName = MixpanelSwiftCommon;
|
||||
};
|
||||
17JSONLOGIC00000002 /* jsonlogic */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 17JSONLOGIC00000001 /* XCRemoteSwiftPackageReference "json-logic-swift" */;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,6 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
171E4C1C2DB055BC00B7CB11 /* MixpanelFeatureFlagTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 171E4C1B2DB055A900B7CB11 /* MixpanelFeatureFlagTests.swift */; };
|
||||
174205522F15A7210031EEDC /* MixpanelDeviceIdProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174205512F15A7210031EEDC /* MixpanelDeviceIdProviderTests.swift */; };
|
||||
4A856A22C3D44379A5471460 /* MixpanelEventBridgeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C72DDD552B64791AD52E1DC /* MixpanelEventBridgeTests.swift */; };
|
||||
B1AB7B0E940444B7A9B0876A /* MixpanelEventBridgeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DA802B4623D45938280B06A /* MixpanelEventBridgeTests.swift */; };
|
||||
EC34FF3FE7F841898A805160 /* MixpanelEventBridgeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B34EFF52AF7D4D6BACA89305 /* MixpanelEventBridgeTests.swift */; };
|
||||
47BE9AE5B837EEAA088FB3FD /* MixpanelAutomaticEventsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0454269B91B8DAD46D580E9 /* MixpanelAutomaticEventsTests.swift */; };
|
||||
51DD568A1D3077390045D3DB /* LoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56891D3077390045D3DB /* LoggerTests.swift */; };
|
||||
60CB587123D77F9200F1632B /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60CB587023D77F9200F1632B /* LoginViewController.swift */; };
|
||||
|
|
@ -257,9 +254,6 @@
|
|||
/* Begin PBXFileReference section */
|
||||
171E4C1B2DB055A900B7CB11 /* MixpanelFeatureFlagTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MixpanelFeatureFlagTests.swift; sourceTree = "<group>"; };
|
||||
174205512F15A7210031EEDC /* MixpanelDeviceIdProviderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MixpanelDeviceIdProviderTests.swift; sourceTree = "<group>"; };
|
||||
7DA802B4623D45938280B06A /* MixpanelEventBridgeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MixpanelEventBridgeTests.swift; sourceTree = "<group>"; };
|
||||
8C72DDD552B64791AD52E1DC /* MixpanelEventBridgeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MixpanelEventBridgeTests.swift; sourceTree = "<group>"; };
|
||||
B34EFF52AF7D4D6BACA89305 /* MixpanelEventBridgeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MixpanelEventBridgeTests.swift; sourceTree = "<group>"; };
|
||||
51DD56891D3077390045D3DB /* LoggerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoggerTests.swift; sourceTree = "<group>"; };
|
||||
60CB587023D77F9200F1632B /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
|
||||
671EECAE21432E5F006DD9FA /* GroupsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupsViewController.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -450,7 +444,6 @@
|
|||
8654F2DB266ED85300ACEED5 /* Info.plist */,
|
||||
8654F2F72671636A00ACEED5 /* MixpanelDemoMacTests-Bridging-Header.h */,
|
||||
B0454269B91B8DAD46D580E9 /* MixpanelAutomaticEventsTests.swift */,
|
||||
8C72DDD552B64791AD52E1DC /* MixpanelEventBridgeTests.swift */,
|
||||
);
|
||||
path = MixpanelDemoMacTests;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -513,7 +506,6 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
86F86F1522460B3200B69832 /* MixpanelDemoTVTests.swift */,
|
||||
B34EFF52AF7D4D6BACA89305 /* MixpanelEventBridgeTests.swift */,
|
||||
86F86F1722460B3200B69832 /* Info.plist */,
|
||||
);
|
||||
path = MixpanelDemoTVTests;
|
||||
|
|
@ -613,7 +605,6 @@
|
|||
673ABE4221405A0500B1784B /* MixpanelGroupTests.swift */,
|
||||
862773E2206B3B1D00CBE79E /* MixpanelOptOutTests.swift */,
|
||||
E17AA05D1EC6234E0066EFE8 /* MixpanelAutomaticEventsTests.swift */,
|
||||
7DA802B4623D45938280B06A /* MixpanelEventBridgeTests.swift */,
|
||||
E1C61EBD1D22F9F60056C56C /* TestConstants.swift */,
|
||||
51DD56891D3077390045D3DB /* LoggerTests.swift */,
|
||||
E12BD03A1D8A14D6008989C9 /* Supporting Files */,
|
||||
|
|
@ -1061,7 +1052,6 @@
|
|||
8654F2FD2671636B00ACEED5 /* TestConstants.swift in Sources */,
|
||||
8654F3012671636B00ACEED5 /* MixpanelOptOutTests.swift in Sources */,
|
||||
47BE9AE5B837EEAA088FB3FD /* MixpanelAutomaticEventsTests.swift in Sources */,
|
||||
4A856A22C3D44379A5471460 /* MixpanelEventBridgeTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
@ -1096,7 +1086,6 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
86F86F1622460B3200B69832 /* MixpanelDemoTVTests.swift in Sources */,
|
||||
EC34FF3FE7F841898A805160 /* MixpanelEventBridgeTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
@ -1137,7 +1126,6 @@
|
|||
E15FF7EC1D0461130076CDE3 /* MixpanelDemoTests.swift in Sources */,
|
||||
171E4C1C2DB055BC00B7CB11 /* MixpanelFeatureFlagTests.swift in Sources */,
|
||||
174205522F15A7210031EEDC /* MixpanelDeviceIdProviderTests.swift in Sources */,
|
||||
B1AB7B0E940444B7A9B0876A /* MixpanelEventBridgeTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,96 +0,0 @@
|
|||
//
|
||||
// MixpanelEventBridgeTests.swift
|
||||
// MixpanelDemoMacTests
|
||||
//
|
||||
// Created by Mixpanel on 2026-04-07.
|
||||
// Copyright © 2026 Mixpanel. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import MixpanelSwiftCommon
|
||||
|
||||
@testable import Mixpanel
|
||||
|
||||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
class MixpanelEventBridgeTests: MixpanelBaseTests {
|
||||
|
||||
// MARK: - Event Bridge Notified on Track
|
||||
|
||||
func testEventBridgeNotifiedOnTrack() {
|
||||
let testMixpanel = Mixpanel.initialize(token: randomId(), trackAutomaticEvents: false)
|
||||
let eventName = "BridgeTestEvent_\(randomId())"
|
||||
let expectation = XCTestExpectation(description: "Event bridge is notified when event is tracked")
|
||||
|
||||
let stream = MixpanelEventBridge.shared.eventStream()
|
||||
let task = Task {
|
||||
for await event in stream {
|
||||
if event.eventName == eventName {
|
||||
expectation.fulfill()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testMixpanel.track(event: eventName)
|
||||
waitForTrackingQueue(testMixpanel)
|
||||
|
||||
wait(for: [expectation], timeout: 2.0)
|
||||
task.cancel()
|
||||
removeDBfile(apiToken: testMixpanel.apiToken)
|
||||
}
|
||||
|
||||
// MARK: - Event Bridge Receives Properties
|
||||
|
||||
func testEventBridgeReceivesEventProperties() {
|
||||
let testMixpanel = Mixpanel.initialize(token: randomId(), trackAutomaticEvents: false)
|
||||
let eventName = "BridgePropsTest_\(randomId())"
|
||||
let expectation = XCTestExpectation(
|
||||
description: "Event bridge receives event with correct properties")
|
||||
|
||||
let stream = MixpanelEventBridge.shared.eventStream()
|
||||
let task = Task {
|
||||
for await event in stream {
|
||||
if event.eventName == eventName {
|
||||
XCTAssertEqual(event.properties["testKey"] as? String, "testValue")
|
||||
expectation.fulfill()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testMixpanel.track(event: eventName, properties: ["testKey": "testValue"])
|
||||
waitForTrackingQueue(testMixpanel)
|
||||
|
||||
wait(for: [expectation], timeout: 2.0)
|
||||
task.cancel()
|
||||
removeDBfile(apiToken: testMixpanel.apiToken)
|
||||
}
|
||||
|
||||
// MARK: - Event Bridge Not Notified When Opted Out
|
||||
|
||||
func testEventBridgeNotNotifiedWhenOptedOut() {
|
||||
let testMixpanel = Mixpanel.initialize(
|
||||
token: randomId(), optOutTrackingByDefault: true, trackAutomaticEvents: false)
|
||||
let eventName = "BridgeOptOutTest_\(randomId())"
|
||||
let noEventExpectation = XCTestExpectation(
|
||||
description: "Event bridge should not be notified when tracking is opted out")
|
||||
noEventExpectation.isInverted = true
|
||||
|
||||
let stream = MixpanelEventBridge.shared.eventStream()
|
||||
let task = Task {
|
||||
for await event in stream {
|
||||
if event.eventName == eventName {
|
||||
noEventExpectation.fulfill()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testMixpanel.track(event: eventName)
|
||||
waitForTrackingQueue(testMixpanel)
|
||||
|
||||
wait(for: [noEventExpectation], timeout: 1.0)
|
||||
task.cancel()
|
||||
removeDBfile(apiToken: testMixpanel.apiToken)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
//
|
||||
// MixpanelEventBridgeTests.swift
|
||||
// MixpanelDemoTVTests
|
||||
//
|
||||
// Created by Mixpanel on 2026-04-07.
|
||||
// Copyright © 2026 Mixpanel. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import MixpanelSwiftCommon
|
||||
|
||||
@testable import Mixpanel
|
||||
|
||||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
class MixpanelEventBridgeTests: XCTestCase {
|
||||
|
||||
private func randomId() -> String {
|
||||
return String(format: "%08x%08x", arc4random(), arc4random())
|
||||
}
|
||||
|
||||
private func waitForTrackingQueue(_ mixpanel: MixpanelInstance) {
|
||||
mixpanel.trackingQueue.sync {
|
||||
mixpanel.networkQueue.sync { return }
|
||||
}
|
||||
mixpanel.trackingQueue.sync {
|
||||
mixpanel.networkQueue.sync { return }
|
||||
}
|
||||
}
|
||||
|
||||
private func removeDBfile(_ apiToken: String) {
|
||||
let manager = FileManager.default
|
||||
let url = manager.urls(for: .cachesDirectory, in: .userDomainMask).last
|
||||
guard let path = url?.appendingPathComponent("\(apiToken)_MPDB.sqlite").path else { return }
|
||||
guard manager.fileExists(atPath: path) else { return }
|
||||
try? manager.removeItem(atPath: path)
|
||||
}
|
||||
|
||||
// MARK: - Event Bridge Notified on Track
|
||||
|
||||
func testEventBridgeNotifiedOnTrack() {
|
||||
let testMixpanel = Mixpanel.initialize(token: randomId(), trackAutomaticEvents: false)
|
||||
let eventName = "BridgeTestEvent_\(randomId())"
|
||||
let expectation = XCTestExpectation(description: "Event bridge is notified when event is tracked")
|
||||
|
||||
let stream = MixpanelEventBridge.shared.eventStream()
|
||||
let task = Task {
|
||||
for await event in stream {
|
||||
if event.eventName == eventName {
|
||||
expectation.fulfill()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testMixpanel.track(event: eventName)
|
||||
waitForTrackingQueue(testMixpanel)
|
||||
|
||||
wait(for: [expectation], timeout: 2.0)
|
||||
task.cancel()
|
||||
removeDBfile(testMixpanel.apiToken)
|
||||
}
|
||||
|
||||
// MARK: - Event Bridge Receives Properties
|
||||
|
||||
func testEventBridgeReceivesEventProperties() {
|
||||
let testMixpanel = Mixpanel.initialize(token: randomId(), trackAutomaticEvents: false)
|
||||
let eventName = "BridgePropsTest_\(randomId())"
|
||||
let expectation = XCTestExpectation(
|
||||
description: "Event bridge receives event with correct properties")
|
||||
|
||||
let stream = MixpanelEventBridge.shared.eventStream()
|
||||
let task = Task {
|
||||
for await event in stream {
|
||||
if event.eventName == eventName {
|
||||
XCTAssertEqual(event.properties["testKey"] as? String, "testValue")
|
||||
expectation.fulfill()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testMixpanel.track(event: eventName, properties: ["testKey": "testValue"])
|
||||
waitForTrackingQueue(testMixpanel)
|
||||
|
||||
wait(for: [expectation], timeout: 2.0)
|
||||
task.cancel()
|
||||
removeDBfile(testMixpanel.apiToken)
|
||||
}
|
||||
|
||||
// MARK: - Event Bridge Not Notified When Opted Out
|
||||
|
||||
func testEventBridgeNotNotifiedWhenOptedOut() {
|
||||
let testMixpanel = Mixpanel.initialize(
|
||||
token: randomId(), trackAutomaticEvents: false, optOutTrackingByDefault: true)
|
||||
let eventName = "BridgeOptOutTest_\(randomId())"
|
||||
let noEventExpectation = XCTestExpectation(
|
||||
description: "Event bridge should not be notified when tracking is opted out")
|
||||
noEventExpectation.isInverted = true
|
||||
|
||||
let stream = MixpanelEventBridge.shared.eventStream()
|
||||
let task = Task {
|
||||
for await event in stream {
|
||||
if event.eventName == eventName {
|
||||
noEventExpectation.fulfill()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testMixpanel.track(event: eventName)
|
||||
waitForTrackingQueue(testMixpanel)
|
||||
|
||||
wait(for: [noEventExpectation], timeout: 1.0)
|
||||
task.cancel()
|
||||
removeDBfile(testMixpanel.apiToken)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
//
|
||||
// MixpanelEventBridgeTests.swift
|
||||
// MixpanelDemoTests
|
||||
//
|
||||
// Created by Mixpanel on 2026-04-07.
|
||||
// Copyright © 2026 Mixpanel. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import MixpanelSwiftCommon
|
||||
|
||||
@testable import Mixpanel
|
||||
|
||||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
|
||||
class MixpanelEventBridgeTests: MixpanelBaseTests {
|
||||
|
||||
// MARK: - Event Bridge Notified on Track
|
||||
|
||||
func testEventBridgeNotifiedOnTrack() {
|
||||
let testMixpanel = Mixpanel.initialize(token: randomId(), trackAutomaticEvents: false)
|
||||
let eventName = "BridgeTestEvent_\(randomId())"
|
||||
let expectation = XCTestExpectation(description: "Event bridge is notified when event is tracked")
|
||||
|
||||
let stream = MixpanelEventBridge.shared.eventStream()
|
||||
let task = Task {
|
||||
for await event in stream {
|
||||
if event.eventName == eventName {
|
||||
expectation.fulfill()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testMixpanel.track(event: eventName)
|
||||
waitForTrackingQueue(testMixpanel)
|
||||
|
||||
wait(for: [expectation], timeout: 2.0)
|
||||
task.cancel()
|
||||
removeDBfile(testMixpanel.apiToken)
|
||||
}
|
||||
|
||||
// MARK: - Event Bridge Receives Properties
|
||||
|
||||
func testEventBridgeReceivesEventProperties() {
|
||||
let testMixpanel = Mixpanel.initialize(token: randomId(), trackAutomaticEvents: false)
|
||||
let eventName = "BridgePropsTest_\(randomId())"
|
||||
let expectation = XCTestExpectation(
|
||||
description: "Event bridge receives event with correct properties")
|
||||
|
||||
let stream = MixpanelEventBridge.shared.eventStream()
|
||||
let task = Task {
|
||||
for await event in stream {
|
||||
if event.eventName == eventName {
|
||||
XCTAssertEqual(event.properties["testKey"] as? String, "testValue")
|
||||
expectation.fulfill()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testMixpanel.track(event: eventName, properties: ["testKey": "testValue"])
|
||||
waitForTrackingQueue(testMixpanel)
|
||||
|
||||
wait(for: [expectation], timeout: 2.0)
|
||||
task.cancel()
|
||||
removeDBfile(testMixpanel.apiToken)
|
||||
}
|
||||
|
||||
// MARK: - Event Bridge Not Notified When Opted Out
|
||||
|
||||
func testEventBridgeNotNotifiedWhenOptedOut() {
|
||||
let testMixpanel = Mixpanel.initialize(
|
||||
token: randomId(), trackAutomaticEvents: false, optOutTrackingByDefault: true)
|
||||
let eventName = "BridgeOptOutTest_\(randomId())"
|
||||
let noEventExpectation = XCTestExpectation(
|
||||
description: "Event bridge should not be notified when tracking is opted out")
|
||||
noEventExpectation.isInverted = true
|
||||
|
||||
let stream = MixpanelEventBridge.shared.eventStream()
|
||||
let task = Task {
|
||||
for await event in stream {
|
||||
if event.eventName == eventName {
|
||||
noEventExpectation.fulfill()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testMixpanel.track(event: eventName)
|
||||
waitForTrackingQueue(testMixpanel)
|
||||
|
||||
wait(for: [noEventExpectation], timeout: 1.0)
|
||||
task.cancel()
|
||||
removeDBfile(testMixpanel.apiToken)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,22 +15,15 @@ let package = Package(
|
|||
],
|
||||
dependencies: [
|
||||
.package(
|
||||
name: "jsonlogic",
|
||||
url: "https://github.com/advantagefse/json-logic-swift",
|
||||
from: "1.2.0"
|
||||
),
|
||||
.package(
|
||||
name: "MixpanelSwiftCommon",
|
||||
url: "https://github.com/mixpanel/mixpanel-swift-common.git",
|
||||
from: "1.0.0"
|
||||
)
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "Mixpanel",
|
||||
dependencies: [
|
||||
"MixpanelSwiftCommon",
|
||||
"jsonlogic",
|
||||
.product(name: "jsonlogic", package: "json-logic-swift")
|
||||
],
|
||||
path: "Sources",
|
||||
resources: [
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import MixpanelSwiftCommon
|
||||
|
||||
func += <K, V>(left: inout [K: V], right: [K: V]) {
|
||||
for (k, v) in right {
|
||||
|
|
@ -82,14 +81,6 @@ class Track {
|
|||
p += properties
|
||||
}
|
||||
|
||||
// Notify event bridge listeners (non-blocking)
|
||||
if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) {
|
||||
MixpanelEventBridge.shared.notifyListeners(
|
||||
eventName: ev,
|
||||
properties: p
|
||||
)
|
||||
}
|
||||
|
||||
// Check for first-time event matches
|
||||
if let mixpanelInstance = mixpanelInstance,
|
||||
let flagManager = mixpanelInstance.flags as? FeatureFlagManager {
|
||||
|
|
|
|||
Loading…
Reference in a new issue