Skip to content

Commit 96440d8

Browse files
Initial commit
1 parent ea0d2cf commit 96440d8

File tree

4 files changed

+99
-3
lines changed

4 files changed

+99
-3
lines changed

Package.resolved

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,36 @@ import PackageDescription
55

66
let package = Package(
77
name: "SwiftfulLoggingMixpanel",
8+
platforms: [
9+
.iOS(.v17),
10+
.macOS(.v14)
11+
],
812
products: [
913
// Products define the executables and libraries a package produces, making them visible to other packages.
1014
.library(
1115
name: "SwiftfulLoggingMixpanel",
1216
targets: ["SwiftfulLoggingMixpanel"]),
1317
],
18+
dependencies: [
19+
// Here we add the dependency for the SendableDictionary package
20+
.package(url: "https://github.com/SwiftfulThinking/SwiftfulLogging.git", "1.0.0"..<"2.0.0"),
21+
.package(url: "https://github.com/mixpanel/mixpanel-swift.git", "4.1.0"..<"5.0.0")
22+
],
1423
targets: [
1524
// Targets are the basic building blocks of a package, defining a module or a test suite.
1625
// Targets can depend on other targets in this package and products from dependencies.
1726
.target(
18-
name: "SwiftfulLoggingMixpanel"),
27+
name: "SwiftfulLoggingMixpanel",
28+
dependencies: [
29+
// Adding SendableDictionary as a dependency for this target
30+
.product(name: "SwiftfulLogging", package: "SwiftfulLogging"),
31+
.product(name: "Mixpanel", package: "mixpanel-swift")
32+
]
33+
),
1934
.testTarget(
2035
name: "SwiftfulLoggingMixpanelTests",
2136
dependencies: ["SwiftfulLoggingMixpanel"]
2237
),
2338
]
2439
)
40+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Foundation
2+
import Mixpanel
3+
import SwiftfulLogging
4+
import SendableDictionary
5+
6+
struct MixpanelProvider: LogService {
7+
8+
private var instance: MixpanelInstance {
9+
Mixpanel.mainInstance()
10+
}
11+
12+
init(token: String) {
13+
#if !os(OSX) && !os(watchOS)
14+
Mixpanel.initialize(token: token, trackAutomaticEvents: true)
15+
#else
16+
Mixpanel.initialize(token: token)
17+
#endif
18+
instance.loggingEnabled = false
19+
}
20+
21+
func identifyUser(userId: String, name: String?, email: String?) {
22+
instance.identify(distinctId: userId)
23+
24+
if let name {
25+
instance.people.set(property: "$name", to: name)
26+
}
27+
if let email {
28+
instance.people.set(property: "$email", to: email)
29+
}
30+
}
31+
32+
func trackEvent(event: LoggableEvent) {
33+
let properties = event.parameters?.mapValues({ $0 as? MixpanelType })
34+
Mixpanel.mainInstance().track(event: event.eventName, properties: properties)
35+
}
36+
37+
func trackScreenView(event: any LoggableEvent) {
38+
trackEvent(event: event)
39+
}
40+
41+
func addUserProperties(dict: SendableDict) {
42+
let properties = dict.dict.mapValues({ $0 as? MixpanelType })
43+
instance.people.set(properties: properties)
44+
}
45+
46+
func deleteUserProfile() {
47+
instance.people.deleteUser()
48+
}
49+
}

Sources/SwiftfulLoggingMixpanel/SwiftfulLoggingMixpanel.swift

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)