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

feat: headers and query item capability added to proxy server #1

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
918d3ad
headers and query item capability added to proxy server
mohitanand-cred Dec 12, 2023
91c16b9
added header capability to other network requests
mohitanand-cred Dec 21, 2023
488edd8
automatically collecting common mobile events is a legacy feature so …
zihejia Jan 9, 2024
ec16672
Prevent crashes in unregisterSuperProperty
Jan 16, 2024
618d245
fix CI
zihejia Jan 17, 2024
a8c862f
Merge pull request #624 from mixpanel/zihe-fix-CI-flake
zihejia Jan 17, 2024
ffd0d35
Merge pull request #623 from daleswift/prevent-crash-unregisterSuperP…
zihejia Jan 17, 2024
5b375ea
Automatic Props
ay8s Jan 30, 2024
0f10d84
Import UIKit
ay8s Jan 30, 2024
3750264
Remoev print
ay8s Jan 30, 2024
9438b4a
Merge pull request #627 from ay8s/task/visionos
zihejia Feb 2, 2024
c432bc8
added comment for macos initialize function and separated MixpanelIns…
mohitanand-cred Feb 9, 2024
324d59f
add privacy manifest
jaredmixpanel Mar 14, 2024
e1d64e7
Merge pull request #633 from mixpanel/jared-add-privacy-manifest
jaredmixpanel Mar 14, 2024
5ba0816
Version 4.2.1
jaredmixpanel Mar 14, 2024
60e265a
Update docs
jaredmixpanel Mar 14, 2024
4fa0f5d
Update CHANGELOG
zihejia Mar 14, 2024
8c9b38a
move privacy manifest
jaredmixpanel Mar 18, 2024
6f0a966
Merge pull request #634 from mixpanel/jared-move-privacy-manifest
jaredmixpanel Mar 18, 2024
9f4de4f
Version 4.2.2
jaredmixpanel Mar 18, 2024
e133990
Update docs
jaredmixpanel Mar 18, 2024
09f6555
Update CHANGELOG
zihejia Mar 18, 2024
1aae2cc
make privacy manifest a resource
jaredmixpanel Mar 25, 2024
0f021d9
add to Copy Bundle Resources
jaredmixpanel Mar 25, 2024
6c592db
Merge pull request #636 from mixpanel/jared-privacy-resource
jaredmixpanel Mar 25, 2024
9450536
Version 4.2.3
jaredmixpanel Mar 25, 2024
f9c08fa
Update docs
jaredmixpanel Mar 25, 2024
fe2ed53
Update CHANGELOG
zihejia Mar 25, 2024
aeb303f
use resources_bundle in podspec
jaredmixpanel Mar 27, 2024
bf6c6f7
Merge pull request #638 from mixpanel/jared-pod-resources-bundle
jaredmixpanel Mar 27, 2024
8cc55a6
Version 4.2.4
jaredmixpanel Mar 27, 2024
c3be71e
Update docs
jaredmixpanel Mar 27, 2024
e84dcf7
Update CHANGELOG
zihejia Mar 27, 2024
68ea193
Merge branch 'master' of https://github.com/mixpanel/mixpanel-swift i…
mohitanand-cred Apr 7, 2024
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
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
#

## [v4.2.4](https://github.com/mixpanel/mixpanel-swift/tree/v4.2.4) (2024-03-27)

#

## [v4.2.3](https://github.com/mixpanel/mixpanel-swift/tree/v4.2.3) (2024-03-25)

### Fixes

- Make privacy manifest a resource [\#636](https://github.com/mixpanel/mixpanel-swift/pull/636)

#

## [v4.2.2](https://github.com/mixpanel/mixpanel-swift/tree/v4.2.2) (2024-03-18)

#

## [v4.2.1](https://github.com/mixpanel/mixpanel-swift/tree/v4.2.1) (2024-03-14)

### Enhancements

- Add privacy manifest [\#633](https://github.com/mixpanel/mixpanel-swift/pull/633)
- visionOS Operating System & Version along with Automatic Events [\#627](https://github.com/mixpanel/mixpanel-swift/pull/627)

### Fixes

- Prevent crashes in unregisterSuperProperty [\#623](https://github.com/mixpanel/mixpanel-swift/pull/623)

#

## [v4.2.0](https://github.com/mixpanel/mixpanel-swift/tree/v4.2.0) (2023-11-13)

### Enhancements
Expand Down Expand Up @@ -394,6 +423,14 @@ When you call the API `createAlias`, there is an implicit `identify` call inside














Expand Down
2 changes: 1 addition & 1 deletion Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.2.0</string>
<string>4.2.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
3 changes: 2 additions & 1 deletion Mixpanel-swift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Mixpanel-swift'
s.version = '4.2.0'
s.version = '4.2.4'
s.module_name = 'Mixpanel'
s.license = 'Apache License, Version 2.0'
s.summary = 'Mixpanel tracking library for iOS (Swift)'
Expand All @@ -9,6 +9,7 @@ Pod::Spec.new do |s|
s.author = { 'Mixpanel, Inc' => '[email protected]' }
s.source = { :git => 'https://github.com/mixpanel/mixpanel-swift.git',
:tag => "v#{s.version}" }
s.resource_bundles = {'Mixpanel' => ['Sources/Mixpanel/PrivacyInfo.xcprivacy']}
s.ios.deployment_target = '11.0'
s.ios.frameworks = 'UIKit', 'Foundation', 'CoreTelephony'
s.ios.pod_target_xcconfig = {
Expand Down
18 changes: 18 additions & 0 deletions Mixpanel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
17C6547A2BB1F15C00C8A126 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */; };
17C6547B2BB1F16000C8A126 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */; };
17C6547C2BB1F16400C8A126 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */; };
17C6547D2BB1F16800C8A126 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */; };
51DD567C1D306B740045D3DB /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56791D306B740045D3DB /* Logger.swift */; };
51DD56831D306B7B0045D3DB /* PrintLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56801D306B7B0045D3DB /* PrintLogging.swift */; };
51DD56841D306B7B0045D3DB /* FileLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56811D306B7B0045D3DB /* FileLogging.swift */; };
Expand Down Expand Up @@ -95,6 +99,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = Sources/Mixpanel/PrivacyInfo.xcprivacy; sourceTree = SOURCE_ROOT; };
51DD56791D306B740045D3DB /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
51DD56801D306B7B0045D3DB /* PrintLogging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintLogging.swift; sourceTree = "<group>"; };
51DD56811D306B7B0045D3DB /* FileLogging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileLogging.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -157,6 +162,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
17C654792BB1EF6700C8A126 /* Mixpanel */ = {
isa = PBXGroup;
children = (
1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */,
);
path = Mixpanel;
sourceTree = "<group>";
};
51DD56771D306B620045D3DB /* Log */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -208,6 +221,7 @@
E11594881CFF14D3007F8B4F /* Source */ = {
isa = PBXGroup;
children = (
17C654792BB1EF6700C8A126 /* Mixpanel */,
E189D8FB1D5A6943007F3F29 /* Networking */,
51DD56771D306B620045D3DB /* Log */,
E189D8FA1D5A692A007F3F29 /* Utilities */,
Expand Down Expand Up @@ -427,27 +441,31 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
17C6547D2BB1F16800C8A126 /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
E115947B1CFF1491007F8B4F /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
17C6547A2BB1F15C00C8A126 /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
E12782B11D4AB4B30025FB05 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
17C6547B2BB1F16000C8A126 /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
E1F15FC71E64A10700391AE3 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
17C6547C2BB1F16400C8A126 /* PrivacyInfo.xcprivacy in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion MixpanelDemo/MixpanelDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down
29 changes: 17 additions & 12 deletions MixpanelDemo/MixpanelDemoTests/MixpanelDemoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -969,25 +969,28 @@ class MixpanelDemoTests: MixpanelBaseTests {

func testMultipleInstancesWithSameTokenButDifferentInstanceName() {
let testToken = randomId()
let instance1 = Mixpanel.initialize(token: testToken, trackAutomaticEvents: true, flushInterval: 60, instanceName: "instance1")
let instance2 = Mixpanel.initialize(token: testToken, trackAutomaticEvents: true, flushInterval: 60, instanceName: "instance2")
let instanceName1 = randomId()
let instanceName2 = randomId()
let instance1 = Mixpanel.initialize(token: testToken, trackAutomaticEvents: true, flushInterval: 60, instanceName: instanceName1)
let instance2 = Mixpanel.initialize(token: testToken, trackAutomaticEvents: true, flushInterval: 60, instanceName: instanceName2)

XCTAssertNotEqual(instance1.distinctId, instance2.distinctId)
instance1.identify(distinctId: "user1")
instance1.track(event: "test")
waitForTrackingQueue(instance1)
waitForTrackingQueue(instance2)

XCTAssertEqual(instance1.distinctId, "user1")
XCTAssertEqual(instance1.userId, "user1")
let events = eventQueue(token: "instance1")
let events = eventQueue(token: instanceName1)
let properties = events.last?["properties"] as? InternalProperties
// TODO: Need to figure out why this test is flaky
// event property should have the current distinct id
//XCTAssertEqual(properties?["distinct_id"] as? String, "user1")
XCTAssertEqual(properties?["distinct_id"] as? String, "user1")

instance1.people.set(property: "p1", to: "a")
waitForTrackingQueue(instance1)

let peopleQueue_value = peopleQueue(token: "instance1")
waitForTrackingQueue(instance2)

let peopleQueue_value = peopleQueue(token: instanceName1)
let setValue = peopleQueue_value.last!["$set"] as! InternalProperties
XCTAssertEqual(setValue["p1"] as? String, "a", "custom people property not queued")

Expand All @@ -996,26 +999,28 @@ class MixpanelDemoTests: MixpanelBaseTests {

instance2.identify(distinctId: "user2")
instance2.track(event: "test2")
waitForTrackingQueue(instance1)
waitForTrackingQueue(instance2)
XCTAssertEqual(instance2.distinctId, "user2")
XCTAssertEqual(instance2.userId, "user2")
let events2 = eventQueue(token: "instance2")
let events2 = eventQueue(token: instanceName2)
let properties2 = events2.last?["properties"] as? InternalProperties
// event property should have the current distinct id
XCTAssertEqual(properties2?["distinct_id"] as? String, "user2")

instance2.people.set(property: "p2", to: "b")
waitForTrackingQueue(instance1)
waitForTrackingQueue(instance2)

let peopleQueue2_value = peopleQueue(token: "instance2")
let peopleQueue2_value = peopleQueue(token: instanceName2)
XCTAssertEqual(peopleQueue2_value.last?["$distinct_id"] as? String,
"user2", "distinct id not set properly on the people record")

let setValue2 = peopleQueue2_value.last!["$set"] as! InternalProperties
XCTAssertEqual(setValue2["p2"] as? String, "b", "custom people property not queued")

removeDBfile("instance1")
removeDBfile("instance2")
removeDBfile(instanceName1)
removeDBfile(instanceName2)
}

func testReadWriteMultiThreadShouldNotCrash() {
Expand Down
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ let package = Package(
targets: [
.target(
name: "Mixpanel",
path: "Sources"
path: "Sources",
resources: [
.copy("Mixpanel/PrivacyInfo.xcprivacy")
]
)
]
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import Mixpanel
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
...
Mixpanel.initialize(token: "MIXPANEL_TOKEN", trackAutomaticEvents: true)
Mixpanel.initialize(token: "MIXPANEL_TOKEN", trackAutomaticEvents: false)
...
}
```
Expand Down Expand Up @@ -104,7 +104,7 @@ import Mixpanel
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
...
Mixpanel.initialize(token: "MIXPANEL_TOKEN", trackAutomaticEvents: true)
Mixpanel.initialize(token: "MIXPANEL_TOKEN", trackAutomaticEvents: false)
Mixpanel.mainInstance().track(event: "Sign Up", properties: [
"source": "Pat's affiliate site",
"Opted out of email": true
Expand Down
2 changes: 1 addition & 1 deletion Sources/AutomaticEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protocol AEDelegate: AnyObject {
func increment(property: String, by: Double)
}

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
import Foundation
import UIKit
import StoreKit
Expand Down
8 changes: 6 additions & 2 deletions Sources/AutomaticProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || os(visionOS)
import UIKit
#elseif os(macOS)
import Cocoa
Expand Down Expand Up @@ -58,6 +58,9 @@ class AutomaticProperties {
let screenSize = watchDevice.screenBounds.size
p["$screen_width"] = Int(screenSize.width)
p["$screen_height"] = Int(screenSize.height)
#elseif os(visionOS)
p["$os"] = "visionOS"
p["$os_version"] = UIDevice.current.systemVersion
#endif

let infoDict = Bundle.main.infoDictionary ?? [:]
Expand All @@ -68,6 +71,7 @@ class AutomaticProperties {
p["$lib_version"] = AutomaticProperties.libVersion()
p["$manufacturer"] = "Apple"
p["$model"] = AutomaticProperties.deviceModel()

return p
}()

Expand Down Expand Up @@ -144,7 +148,7 @@ class AutomaticProperties {
}

class func libVersion() -> String {
return "4.2.0"
return "4.2.4"
}

}
13 changes: 8 additions & 5 deletions Sources/Flush.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class Flush: AppLifecycle {
flushIntervalReadWriteLock = DispatchQueue(label: "com.mixpanel.flush_interval.lock", qos: .utility, attributes: .concurrent, autoreleaseFrequency: .workItem)
}

func flushQueue(_ queue: Queue, type: FlushType) {
func flushQueue(_ queue: Queue, type: FlushType, headers: [String: String], queryItems: [URLQueryItem]) {
if flushRequest.requestNotAllowed() {
return
}
flushQueueInBatches(queue, type: type)
flushQueueInBatches(queue, type: type, headers: headers, queryItems: queryItems)
}

func startFlushTimer() {
Expand Down Expand Up @@ -95,7 +95,7 @@ class Flush: AppLifecycle {
}
}

func flushQueueInBatches(_ queue: Queue, type: FlushType) {
func flushQueueInBatches(_ queue: Queue, type: FlushType, headers: [String: String], queryItems: [URLQueryItem]) {
var mutableQueue = queue
while !mutableQueue.isEmpty {
let batchSize = min(mutableQueue.count, flushBatchSize)
Expand All @@ -115,8 +115,10 @@ class Flush: AppLifecycle {
}
#endif // os(iOS)
let success = flushRequest.sendRequest(requestData,
type: type,
useIP: useIPAddressForGeoLocation)
type: type,
useIP: useIPAddressForGeoLocation,
headers: headers,
queryItems: queryItems)
#if os(iOS)
if !MixpanelInstance.isiOSAppExtension() {
delegate?.updateNetworkActivityIndicator(false)
Expand Down Expand Up @@ -156,3 +158,4 @@ class Flush: AppLifecycle {
}

}

13 changes: 10 additions & 3 deletions Sources/FlushRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class FlushRequest: Network {

func sendRequest(_ requestData: String,
type: FlushType,
useIP: Bool) -> Bool {
useIP: Bool,
headers: [String: String],
queryItems: [URLQueryItem] = []) -> Bool {

let responseParser: (Data) -> Int? = { data in
let response = String(data: data, encoding: String.Encoding.utf8)
Expand All @@ -31,12 +33,16 @@ class FlushRequest: Network {
return nil
}

let resourceHeaders: [String: String] = ["Content-Type": "application/json"].merging(headers) {(_,new) in new }

let ipString = useIP ? "1" : "0"
var resourceQueryItems: [URLQueryItem] = [URLQueryItem(name: "ip", value: ipString)]
resourceQueryItems.append(contentsOf: queryItems)
let resource = Network.buildResource(path: type.rawValue,
method: .post,
requestBody: requestData.data(using: .utf8),
queryItems: [URLQueryItem(name: "ip", value: ipString)],
headers: ["Content-Type": "application/json"],
queryItems: resourceQueryItems,
headers: resourceHeaders,
parse: responseParser)
var result = false
let semaphore = DispatchSemaphore(value: 0)
Expand Down Expand Up @@ -97,3 +103,4 @@ class FlushRequest: Network {
}

}

Loading