-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicUsage.swift
More file actions
72 lines (60 loc) · 1.88 KB
/
BasicUsage.swift
File metadata and controls
72 lines (60 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// BasicUsage.swift
// Copy-paste example showing how to integrate Beacon into a macOS or iOS app.
// This file is not compiled as part of the package — it's a reference.
import SwiftUI
import Beacon
// MARK: - macOS App Example
@main
struct MyApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
// 1. Enable debug logging (remove in production)
Beacon.enableLogging()
// 2. Configure with your Supabase credentials
Beacon.configure(
supabaseURL: "https://your-project.supabase.co",
supabaseKey: "your-anon-key"
)
// 3. Track app launch
Beacon.track("app_launched")
}
func applicationWillTerminate(_ notification: Notification) {
// Flush remaining events before exit
Beacon.shutdown()
}
}
struct ContentView: View {
var body: some View {
VStack(spacing: 20) {
Text("Beacon Example")
.font(.title)
Button("Track Button Tap") {
Beacon.track("button_tapped", properties: [
"screen": "main",
"button": "example"
])
}
Button("Identify User") {
Beacon.identify(userId: "user-123", traits: [
"plan": "pro",
"signup_source": "organic"
])
}
Button("Track Purchase") {
Beacon.track("purchase_completed", properties: [
"item_id": "sku-789",
"price": 9.99,
"currency": "USD"
])
}
}
.padding(40)
}
}