syntax = "proto3";

package devvit.ui.effects.web_view.v1alpha;

option go_package = "github.snooguts.net/reddit/reddit-devplatform-monorepo/go-common/generated/protos/types/devvit/ui/effects/web_view/v1alpha";
option java_package = "com.reddit.devvit.ui.effects.web_view.v1alpha";

// Any statistical data event from the web view for analytics.
message WebViewTelemetryEffect {
  // Event type. Eg, `click` or `web-view-loaded`.
  optional string event = 1;
  // Event JSON data.
  oneof data {
    WebViewTelemetryClickEffect click = 2;
    WebViewTelemetryLoadedEffect loaded = 3;
    WebViewTelemetryMetricsEffect metrics = 4;
  }
}

// Maps to DOM `click` event. See https://docs.google.com/document/d/1J9MKJrHW16YSsBTii0LSXViAQvwq6MTQJAmjf2EyPaw/edit?tab=t.0
message WebViewTelemetryClickEffect {
  // `click`.
  string event = 1 [deprecated = true];
  // Click definition: 'strict' or 'default'.
  string definition = 2;
  // Element track ID for the click event.
  optional string elem_track_id = 3;
}

// Maps to DOM `load` event.
message WebViewTelemetryLoadedEffect {
  // `web-view-loaded`.
  string event = 1 [deprecated = true];
  // Load start time in fractional UTC milliseconds.
  double time_start = 2;
  // Load end time in fractional UTC milliseconds.
  double time_end = 3;
  // Load duration in fractional milliseconds.
  double duration = 4;
}

// A performance metric that should be mapped to a `DevplatformBaseTrace` event on the client.
message WebViewTelemetryMetric {
  // Name of the transaction used in the event.
  string span_name = 1;
  // Start time in fractional UTC milliseconds.
  double time_start = 2;
  // End time in fractional UTC milliseconds.
  double time_end = 3;
}

// A collection of performance metrics for the client to send as v2 events.
message WebViewTelemetryMetricsEffect {
  // A collection of performance metrics.
  repeated WebViewTelemetryMetric metrics = 1;
}
