Skip to content

Commit

Permalink
docs: [vision-os-sample-app][10/n] Profile Attributes (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed-CIO authored Mar 26, 2024
1 parent be3e41f commit 1396144
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Apps/VisionOS/VisionOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
6023AD372B9137F0001540EF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6023AD362B9137F0001540EF /* AppDelegate.swift */; };
6066B2632BAFC86F005A4135 /* TrackEventsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6066B2622BAFC86F005A4135 /* TrackEventsView.swift */; };
6066B2652BAFCBEB005A4135 /* ProfileAttributesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6066B2642BAFCBEB005A4135 /* ProfileAttributesView.swift */; };
60B151FB2BAB4AA9003C4726 /* DataPipelines in Frameworks */ = {isa = PBXBuildFile; productRef = 60B151FA2BAB4AA9003C4726 /* DataPipelines */; };
60C32BEC2BABAD4D006F5DC3 /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60C32BEB2BABAD4D006F5DC3 /* ViewModel.swift */; };
60C32BF62BABAFBE006F5DC3 /* LineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6023AD4B2B9153EB001540EF /* LineView.swift */; };
Expand Down Expand Up @@ -41,6 +42,7 @@
6023AD4A2B9153EB001540EF /* FloatingTitleTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FloatingTitleTextField.swift; sourceTree = "<group>"; };
6023AD4B2B9153EB001540EF /* LineView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineView.swift; sourceTree = "<group>"; };
6066B2622BAFC86F005A4135 /* TrackEventsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackEventsView.swift; sourceTree = "<group>"; };
6066B2642BAFCBEB005A4135 /* ProfileAttributesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileAttributesView.swift; sourceTree = "<group>"; };
606F2C202B9B79F3004E7318 /* PropertiesInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertiesInputView.swift; sourceTree = "<group>"; };
60B792DB2BAFC0F700E8F886 /* TrackEventsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackEventsView.swift; sourceTree = "<group>"; };
60C32BEB2BABAD4D006F5DC3 /* ViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -102,6 +104,7 @@
60E792512BACDE72003736F4 /* SDKInitializationView.swift */,
60DE3F7A2BAD38C600C6816C /* IdentifyView.swift */,
6066B2622BAFC86F005A4135 /* TrackEventsView.swift */,
6066B2642BAFCBEB005A4135 /* ProfileAttributesView.swift */,
);
path = APIViews;
sourceTree = "<group>";
Expand Down Expand Up @@ -277,6 +280,7 @@
60C32BFB2BABAFBE006F5DC3 /* MainLayoutView.swift in Sources */,
60F967542B91288400A4E95E /* Payloads.swift in Sources */,
60DE3F7D2BAD392000C6816C /* CodeSnippetHelper.swift in Sources */,
6066B2652BAFCBEB005A4135 /* ProfileAttributesView.swift in Sources */,
60F967372B9125D000A4E95E /* MainScreen.swift in Sources */,
60F9675B2B912C1000A4E95E /* TextOutputFormat.swift in Sources */,
60F9675D2B912C1000A4E95E /* MarkdownTheme.swift in Sources */,
Expand Down
53 changes: 53 additions & 0 deletions Apps/VisionOS/VisionOS/APIViews/ProfileAttributesView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import MarkdownUI
import SwiftUI

private func profileAttributeCodeSnippet(_ attributes: [Attribute]) -> String {
if attributes.isEmpty {
return "// enter profile attributes"
} else {
let attributesStr = propertiesToTutorialString(attributes)
return
"""
CustomerIO.shared.profileAttributes = \(attributesStr)
"""
}
}

struct ProfileAttributesView: View {
@ObservedObject var state = AppState.shared

@State private var attributes: [Attribute] = []

let onSuccess: (_ profileAttributes: [Attribute]) -> Void

var body: some View {
VStack(alignment: .leading) {
Markdown {
"""
You can set/update user attributes at any point in your app by setting values in the
`CustomerIO.shared.profileAttributes` dictionary.
If you are interested to learn about how profile attributes is being used,
[click here](https://customer.io/docs/journeys/attributes/#attribute-segment).
```swift
\(profileAttributeCodeSnippet(attributes))
```
"""
}


PropertiesInputView(terminology: .attributes, properties: $attributes)

Button("Set/Update profile attribute") {
onSuccess(attributes)
}
}
}
}

#Preview {
MainLayoutView(selectedExample: .constant(.profileAttributes)) {
ProfileAttributesView { _ in
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import MarkdownUI
import SwiftUI

enum PropertiesTerminology: String {
case properties, traits
case properties, traits, attributes

var capitalize: String {
"\(self)".capitalized
Expand Down
7 changes: 6 additions & 1 deletion Apps/VisionOS/VisionOS/MainScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ struct MainScreen: View {
CustomerIO.shared.flush()
}
case .profileAttributes:
Text("Profile Attribute")
ProfileAttributesView { attributes in
CustomerIO.shared.profileAttributes = attributes.toDictionary()
viewModel.successMessage = "Profile attributes set successfully"
// For debug purpose only
CustomerIO.shared.flush()
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Apps/VisionOS/VisionOS/Storage/Payloads.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ extension [Property] {
}
}

typealias Attribute = Property

struct Event: Codable {
var name: String
var properties: [Property] = []
Expand Down

0 comments on commit 1396144

Please sign in to comment.