Skip to content

Commit

Permalink
Explicitly define what types are allowed for custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Jun 10, 2023
1 parent 608dd0d commit ed2db3b
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Aptabase.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Aptabase'
s.version = '0.0.7'
s.version = '0.1.0'
s.summary = 'Swift SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps'
s.homepage = 'https://aptabase.com'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.0

* General refactor
* Explicitly define what types are allowed for custom properties

## 0.0.7

* Added support for CocoaPods
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E2019AE329DAEF2600204720"
BuildableName = "HelloWorld.app"
BlueprintName = "HelloWorld"
ReferencedContainer = "container:HelloWorld.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E2019AE329DAEF2600204720"
BuildableName = "HelloWorld.app"
BlueprintName = "HelloWorld"
ReferencedContainer = "container:HelloWorld.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E2019AE329DAEF2600204720"
BuildableName = "HelloWorld.app"
BlueprintName = "HelloWorld"
ReferencedContainer = "container:HelloWorld.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let package = Package(
...
dependencies: [
...
.package(name: "Aptabase", url: "https://github.com/aptabase/aptabase-swift.git", from: "0.0.7"),
.package(name: "Aptabase", url: "https://github.com/aptabase/aptabase-swift.git", from: "0.1.0"),
],
targets: [
.target(
Expand All @@ -39,7 +39,7 @@ Use this [guide](https://developer.apple.com/documentation/xcode/adding-package-
Aptabase is alsoavailable through CocoaPods. To install it, simply add the following line to your Podfile:

```ruby
pod 'Aptabase', :git => 'https://github.com/aptabase/aptabase-swift.git', :tag => '0.0.7'
pod 'Aptabase', :git => 'https://github.com/aptabase/aptabase-swift.git', :tag => '0.1.0'
```


Expand Down
11 changes: 8 additions & 3 deletions Sources/Aptabase/Aptabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public struct InitOptions {

// The Aptabase client used to track events
public class Aptabase {
private static var sdkVersion = "aptabase-swift@0.0.7";
private static var sdkVersion = "aptabase-swift@0.1.0";

// Session expires after 1 hour of inactivity
private var sessionTimeout: TimeInterval = 1 * 60 * 60
Expand Down Expand Up @@ -64,7 +64,7 @@ public class Aptabase {
}

// Track an event and its properties
public func trackEvent(_ eventName: String, with props: [String: Any] = [:]) {
public func trackEvent(_ eventName: String, with props: [String: Value] = [:]) {
DispatchQueue(label: "com.aptabase.aptabase").async { [self] in
guard let appKey, let env, let apiURL else {
return
Expand Down Expand Up @@ -92,7 +92,12 @@ public class Aptabase {
] as [String : Any],
"props": props
]


if !JSONSerialization.isValidJSONObject(props) {
debugPrint("Aptabase: unable to serialize custom props. Event will be discarded.")
return
}

guard let body = try? JSONSerialization.data(withJSONObject: body) else { return }

var request = URLRequest(url: apiURL)
Expand Down
6 changes: 6 additions & 0 deletions Sources/Aptabase/Value.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public protocol Value {}
extension Int: Value {}
extension Double: Value {}
extension String: Value {}
extension Float: Value {}
extension Bool: Value {}

0 comments on commit ed2db3b

Please sign in to comment.