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

[ios] support app identifier condition for experiment, and send metadata to collect server #49

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading