Skip to main content

cdp_driver/protocol/
ads.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! A domain for ad-related metrics and data.
5//!
6//! Types, command parameters and event payloads for the `Ads`
7//! domain. The method-name constants for the same domain are in
8//! [`crate::methods`].
9//!
10//! This domain is experimental and may change without notice.
11
12use serde::{Deserialize, Serialize};
13
14/// Ad frame data.
15#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
16pub struct AdFrameData {
17    /// The DevTools frame token.
18    #[serde(rename = "frameId")]
19    pub frame_id: crate::protocol::page::FrameId,
20    /// The initial origin of the frame. To minimize the payload size, this is
21    /// only sent once per frame.
22    #[serde(
23        rename = "initialOrigin",
24        default,
25        skip_serializing_if = "Option::is_none"
26    )]
27    pub initial_origin: Option<String>,
28    /// The network bytes of the frame.
29    #[serde(rename = "networkBytes")]
30    pub network_bytes: f64,
31    /// The CPU time of the frame, in milliseconds.
32    #[serde(rename = "cpuTime")]
33    pub cpu_time: f64,
34}
35
36/// Ad metrics for a page.
37#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
38pub struct AdMetrics {
39    /// The viewport ad density by area, represented as a percentage (an integer
40    /// between 0 and 100).
41    #[serde(rename = "viewportAdDensityByArea")]
42    pub viewport_ad_density_by_area: i64,
43    /// The time-weighted average of the viewport ad density by area, measured
44    /// across the duration of the page.
45    #[serde(rename = "averageViewportAdDensityByArea")]
46    pub average_viewport_ad_density_by_area: f64,
47    /// The number of ads currently visible within the viewport.
48    #[serde(rename = "viewportAdCount")]
49    pub viewport_ad_count: i64,
50    /// The time-weighted average of the viewport ad count, measured across the
51    /// duration of the page.
52    #[serde(rename = "averageViewportAdCount")]
53    pub average_viewport_ad_count: f64,
54    /// The total ad CPU usage, in milliseconds.
55    #[serde(rename = "totalAdCpuTime")]
56    pub total_ad_cpu_time: f64,
57    /// The total ad network bytes.
58    #[serde(rename = "totalAdNetworkBytes")]
59    pub total_ad_network_bytes: f64,
60    /// The list of ad frames that have been updated since the last event.
61    #[serde(rename = "updateAdFrames")]
62    pub update_ad_frames: Vec<AdFrameData>,
63    /// The list of ad frame IDs that have been removed since the last event.
64    #[serde(rename = "removeAdFrames")]
65    pub remove_ad_frames: Vec<crate::protocol::page::FrameId>,
66}
67
68/// An ad script. Note: when the script is a transitive ad script, we only
69/// fill in the immediate ancestor script in the provenance's adScriptAncestry
70/// field (as its first entry), rather than filling in the full ancestry. This
71/// saves work for the backend, and the frontend can reconstruct the full
72/// ancestry if necessary.
73#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
74pub struct AdScript {
75    /// The script ID.
76    #[serde(rename = "scriptId")]
77    pub script_id: crate::protocol::runtime::ScriptId,
78    /// The ad provenance.
79    pub provenance: crate::protocol::network::AdProvenance,
80}
81
82/// Retrieves ad metrics for the current page.
83///
84/// Parameters of `Ads.getAdMetrics`.
85#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
86pub struct GetAdMetricsParams {}
87
88/// What `Ads.getAdMetrics` answers with.
89#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
90pub struct GetAdMetricsReturns {
91    pub metrics: AdMetrics,
92}
93
94impl crate::typed::Command for GetAdMetricsParams {
95    const METHOD: &'static str = "Ads.getAdMetrics";
96    type Returns = GetAdMetricsReturns;
97}
98
99/// Retrieves ad scripts for the current page. To minimize payload size, this
100/// only returns the newly tracked ad scripts since the last call to
101/// getAdScripts (i.e., the delta).
102///
103/// Parameters of `Ads.getAdScripts`.
104#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
105pub struct GetAdScriptsParams {}
106
107/// What `Ads.getAdScripts` answers with.
108#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
109pub struct GetAdScriptsReturns {
110    #[serde(rename = "newScripts")]
111    pub new_scripts: Vec<AdScript>,
112}
113
114impl crate::typed::Command for GetAdScriptsParams {
115    const METHOD: &'static str = "Ads.getAdScripts";
116    type Returns = GetAdScriptsReturns;
117}