Skip to content
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
25 changes: 25 additions & 0 deletions PostHogExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,31 @@ struct ContentView: View {
}
}

// Events go to /i/v1/analytics/events; captureAi events go to /i/v1/ai/events.
Section("Capture v1") {
Button("Capture with options") {
PostHogSDK.shared.capture("example_event_with_options", properties: [
"source": "example_app",
], options: [
"process_person_profile": false,
])
}

Button("Capture $ai_generation") {
let uuid = PostHogSDK.shared.captureAi("$ai_generation", properties: [
"$ai_trace_id": UUID().uuidString,
"$ai_provider": "openai",
"$ai_model": "gpt-4o-mini",
"$ai_input": [["role": "user", "content": "Tell me a fun fact about hedgehogs"]],
"$ai_output_choices": [["role": "assistant", "content": "Hedgehogs have about 5,000 spines."]],
"$ai_input_tokens": 12,
"$ai_output_tokens": 9,
"$ai_latency": 0.42,
])
print("captureAi queued $ai_generation: \(uuid ?? "not queued")")
}
}

// Manual testing of exception steps.
Section("Exception steps") {
Button("Add 3 exception steps") {
Expand Down
18 changes: 18 additions & 0 deletions PostHogObjCExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
groups:groupProps
timestamp:[NSDate date]];

[[PostHogSDK shared] captureWithEvent:@"theEvent"
distinctId:nil
properties:props
userProperties:nil
userPropertiesSetOnce:nil
groups:nil
timestamp:nil
options:@{@"process_person_profile": @NO}];

NSString *aiEventUuid = [[PostHogSDK shared] captureAiWithEvent:@"$ai_generation"
distinctId:nil
properties:@{@"$ai_model": @"gpt-4o-mini", @"$ai_provider": @"openai"}
userProperties:nil
userPropertiesSetOnce:nil
groups:nil
timestamp:nil
options:nil];
NSLog(@"captureAi uuid: %@", aiEventUuid);

[[PostHogSDK shared] groupWithType:@"theType" key:@"theKey"];
[[PostHogSDK shared] groupWithType:@"theType" key:@"theKey" groupProperties:groupProps];
Expand Down
Loading