Skip to content

Commit

Permalink
Merge pull request #49 from plaidev/flutter
Browse files Browse the repository at this point in the history
[ios] support app identifier condition for experiment, and send metadata to collect server
  • Loading branch information
RyosukeCla authored Sep 12, 2024
2 parents 1e0ce58 + cf17761 commit 6db79dd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion ios/Nativebrik/Nativebrik/data/track.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UIKit

private let CRASH_RECORD_KEY: String = "NATIVEBRIK_CRASH_RECORD"

Expand All @@ -26,6 +27,7 @@ struct TrackRequest: Encodable {
var userId: String
var timestamp: DateTime
var events: [TrackEvent]
var meta: TrackEventMeta
}

struct TrackEvent: Encodable {
Expand All @@ -40,6 +42,15 @@ struct TrackEvent: Encodable {
var timestamp: DateTime
}

struct TrackEventMeta: Encodable {
var appId: String?
var appVersion: String?
var cfBundleVersion: String?
var osName: String?
var osVersion: String?
var sdkVersion: String?
}

struct TrackUserEvent {
var name: String
}
Expand Down Expand Up @@ -124,11 +135,24 @@ class TrackRespositoryImpl: TrackRepository2 {
}
let events = self.buffer
self.buffer = []

let appId = Bundle.main.bundleIdentifier ?? ""
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
let cfBundleVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""
let trackMeta = await TrackEventMeta(
appId: appId,
appVersion: appVersion,
cfBundleVersion: cfBundleVersion,
osName: UIDevice.current.systemName,
osVersion: UIDevice.current.systemVersion,
sdkVersion: nativebrikSdkVersion
)
let trackRequest = TrackRequest(
projectId: self.config.projectId,
userId: self.user.id,
timestamp: formatToISO8601(getCurrentDate()),
events: events
events: events,
meta: trackMeta
)

do {
Expand Down
3 changes: 3 additions & 0 deletions ios/Nativebrik/Nativebrik/data/user.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public class NativebrikUser {
self.properties[BuiltinUserProperty.sdkVersion.rawValue] = nativebrikSdkVersion
self.properties[BuiltinUserProperty.osName.rawValue] = UIDevice.current.systemName
self.properties[BuiltinUserProperty.osVersion.rawValue] = UIDevice.current.systemVersion

let appId = Bundle.main.bundleIdentifier ?? ""
self.properties[BuiltinUserProperty.appId.rawValue] = appId

let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
self.properties[BuiltinUserProperty.appVersion.rawValue] = appVersion
Expand Down
1 change: 1 addition & 0 deletions ios/Nativebrik/Nativebrik/generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum BuiltinUserProperty: String, Decodable, Encodable {
case sdkVersion = "sdkVersion"
case osVersion = "osVersion"
case osName = "osName"
case appId = "appId"
case appVersion = "appVersion"
case cfBundleVersion = "cfBundleVersion"
case localYear = "localYear"
Expand Down

0 comments on commit 6db79dd

Please sign in to comment.