Core.AsyncInitialize().using Oculus.Platform;
using Oculus.Platform.Models;
Message<SegmentEvent> msg = await InAppAnalytics.OpenSegment("test_segment");
if (msg.IsError)
{
Debug.LogError($"OpenSegment failed: {msg.data}");
return;
}
SegmentEvent model = msg.Data;
Debug.Log(model.ToJson());
Message<SegmentEvent> msg = await InAppAnalytics.CloseSegment("test_segment");
if (msg.IsError)
{
Debug.LogError($"CloseSegment failed: {msg.data}");
return;
}
SegmentEvent model = msg.Data;
Debug.Log(model.ToJson());
Message<SegmentEvent[]> msg = await InAppAnalytics.CloseAllOpenSegments();
if (msg.IsError)
{
Debug.LogError($"CloseAllOpenSegments failed: {msg.data}");
return;
}
foreach (var segment in msg.Data)
{
Debug.Log(segment.ToJson());
}
Message<SegmentEvent[]> msg = await InAppAnalytics.GetAllSegments();
if (msg.IsError)
{
Debug.LogError($"GetAllSegments failed: {msg.data}");
return;
}
foreach (var segment in msg.Data)
{
Debug.Log(segment.ToJson());
}
SendEvent with a metric name and a numeric value:string metricName = "test_event";
float value = 1.0f;
Message msg = await InAppAnalytics.SendEvent(metricName, value);
if (msg.IsError)
{
Debug.LogError($"SendEvent failed: {msg.data}");
return;
}
Debug.Log(msg.data);
QueueMetricEvent with a MetricEventInput:using Oculus.Platform;
using Oculus.Platform.Models;
MetricEventInput metricEvent = new MetricEventInput()
{
MetricName = "queued_metric",
Value = 1.0f,
MetricType = MetricType.Action,
Timestamp = 1773088361
};
Message msg = await InAppAnalytics.QueueMetricEvent(metricEvent);
if (msg.IsError)
{
Debug.LogError($"QueueMetricEvent failed: {msg.data}");
return;
}
Debug.Log(msg.data);
SegmentEventInput:SegmentEventInput segEvent = new SegmentEventInput()
{
SegName = "queued_segment"
};
Message msg = await InAppAnalytics.QueueSegmentEvent(segEvent);
if (msg.IsError)
{
Debug.LogError($"QueueSegmentEvent failed: {msg.data}");
return;
}
Debug.Log(msg.data);
string counterName = "test_counter";
bool? manualFlush = false;
Message<MetricEvent> msg = await InAppAnalytics.CreateEventCounter(counterName, manualFlush);
if (msg.IsError)
{
Debug.LogError($"CreateEventCounter failed: {msg.data}");
return;
}
MetricEvent model = msg.Data;
Debug.Log(model.ToJson());
string counterName = "test_counter";
float amount = 1.0f;
Message<MetricEvent> msg = await InAppAnalytics.IncrementEventCounter(counterName, amount);
if (msg.IsError)
{
Debug.LogError($"IncrementEventCounter failed: {msg.data}");
return;
}
MetricEvent model = msg.Data;
Debug.Log(model.ToJson());
Message<MetricEvent> msg = await InAppAnalytics.GetEventCounter("test_counter");
if (msg.IsError)
{
Debug.LogError($"GetEventCounter failed: {msg.data}");
return;
}
MetricEvent model = msg.Data;
Debug.Log(model.ToJson());
Message<MetricEvent> msg = await InAppAnalytics.SendEventCounter("test_counter");
if (msg.IsError)
{
Debug.LogError($"SendEventCounter failed: {msg.data}");
return;
}
MetricEvent model = msg.Data;
Debug.Log(model.ToJson());
manualFlush: true when creating a counter to disable auto-flush. You are then responsible for calling SendEventCounter explicitly:await InAppAnalytics.CreateEventCounter("coins_collected", manualFlush: true);
Message<EventCounterNames> msg = await InAppAnalytics.GetAllEventCounterNames();
if (msg.IsError)
{
Debug.LogError($"GetAllEventCounterNames failed: {msg.data}");
return;
}
EventCounterNames model = msg.Data;
Debug.Log(model.ToJson());
OnComplete:InAppAnalytics.OpenSegment("test_segment").OnComplete((Message<SegmentEvent> msg) =>
{
if (msg.IsError)
{
Debug.LogError($"OpenSegment failed: {msg.data}");
return;
}
SegmentEvent model = msg.Data;
Debug.Log(model.ToJson());
});
| Method | Description | Returns |
|---|---|---|
OpenSegment(segName) | Opens a named segment and records a START event. | Request<SegmentEvent> |
CloseSegment(segName) | Closes a named segment and records an END event with duration. | Request<SegmentEvent> |
CloseAllOpenSegments() | Closes all active segments. | Request<SegmentEvent[]> |
GetAllSegments() | Returns all currently active segments without closing them. | Request<SegmentEvent[]> |
SendEvent(metricName, value) | Sends a single metric event immediately. | Request |
QueueMetricEvent(event) | Queues a metric event for batch processing. | Request |
QueueSegmentEvent(event) | Queues a segment event for batch processing. | Request |
CreateEventCounter(counterName, manualFlush?) | Creates a counter with an initial value of 1. | Request<MetricEvent> |
IncrementEventCounter(counterName, amount) | Increments an existing counter by the given amount. | Request<MetricEvent> |
SendEventCounter(counterName) | Sends the counter value and removes the counter. | Request<MetricEvent> |
GetEventCounter(counterName) | Gets the current counter value without sending. | Request<MetricEvent> |
GetAllEventCounterNames() | Returns the names of all tracked counters. | Request<EventCounterNames> |
| Property | Type | Description |
|---|---|---|
MetricName | string | Name of the metric. |
Value | float | Numeric value of the metric. |
SegId | string | Segment ID the metric is attributed to. |
Timestamp | long | Unix timestamp in seconds when the event was recorded. |
SeqNum | long | Sequence number for ordering events. |
MetricType | MetricType | Category of the metric. |
PositionOptional | Position | Optional 3D position (x, y, z) associated with the event. |
| Property | Type | Description |
|---|---|---|
SegName | string | Name of the segment. |
SegId | string | Unique identifier for the segment instance. |
EventType | SegmentEventType | Type of segment event. |
SegType | SegmentType | Category of the segment. |
Timestamp | long | Unix timestamp in seconds when the event occurred. |
DurationS | float | Duration of the segment in seconds (populated on close). |
SeqNum | long | Sequence number for ordering events. |
MatchId | string | Optional match identifier for multiplayer sessions. |
PositionOptional | Position | Optional 3D position associated with the event. |
SettingsOptional | SegmentSettings | Optional segment settings (cosmetics, difficulty, game mode). |
QueueMetricEvent to provide detailed metric event data.| Field | Type | Description |
|---|---|---|
MetricName | string | Name of the metric (required). |
Value | float | Numeric value (required). |
SegId | string | Segment ID to attribute the event to. |
Timestamp | long | Custom Unix timestamp in seconds. |
SeqNum | long | Sequence number for ordering. |
MetricType | MetricType | Category of the metric. |
Position | PositionInput | 3D position (x, y, z). |
QueueSegmentEvent to provide detailed segment event data.| Field | Type | Description |
|---|---|---|
SegName | string | Name of the segment (required). |
SegId | string | Segment ID. |
EventType | SegmentEventType | Type of segment event. |
SegType | SegmentType | Category of the segment. |
Timestamp | long | Custom Unix timestamp in seconds. |
DurationS | float | Duration in seconds. |
SeqNum | long | Sequence number for ordering. |
MatchId | string | Match identifier for multiplayer sessions. |
Position | PositionInput | 3D position (x, y, z). |
Settings | SegmentSettingsInput | Segment settings (cosmetics, difficulty, game mode). |
GetAllEventCounterNames.| Property | Type | Description |
|---|---|---|
Names | string[] | Array of tracked counter names. |