Struct primitives::analytics::AnalyticsQuery
source · pub struct AnalyticsQuery {Show 15 fields
pub limit: u32,
pub event_type: EventType,
pub metric: Metric,
pub segment_by: Option<AllowedKey>,
pub time: Time,
pub campaign_id: Option<CampaignId>,
pub ad_unit: Option<IPFS>,
pub ad_slot: Option<IPFS>,
pub ad_slot_type: Option<String>,
pub advertiser: Option<Address>,
pub publisher: Option<Address>,
pub hostname: Option<String>,
pub country: Option<String>,
pub os_name: Option<OperatingSystem>,
pub chains: Vec<ChainId>,
}
Expand description
Examples:
use primitives::{
analytics::{
query::{AllowedKey, Time},
AnalyticsQuery, Metric, OperatingSystem, Timeframe,
},
sentry::{DateHour, EventType},
Address, CampaignId, ChainId, IPFS,
};
use std::str::FromStr;
fn main() {
// Empty query - default values only
{
let empty_query = "";
let query: AnalyticsQuery = serde_qs::from_str(empty_query).unwrap();
assert_eq!(100, query.limit);
assert_eq!(EventType::Impression, query.event_type);
assert!(matches!(query.metric, Metric::Count));
assert!(matches!(query.time.timeframe, Timeframe::Day));
}
// Query with different metric/chain/eventType
{
let query_str = "limit=200&eventType=CLICK&metric=paid&timeframe=month";
let query: AnalyticsQuery = serde_qs::from_str(query_str).unwrap();
assert_eq!(200, query.limit);
assert_eq!(EventType::Click, query.event_type);
assert!(matches!(query.metric, Metric::Paid));
assert!(matches!(query.time.timeframe, Timeframe::Month));
}
// Query with allowed keys for guest - country, slotType
{
let query_str = "country=Bulgaria&adSlotType=legacy_300x100";
let query: AnalyticsQuery = serde_qs::from_str(query_str).unwrap();
assert_eq!(Some("Bulgaria".to_string()), query.country);
assert_eq!(Some("legacy_300x100".to_string()), query.ad_slot_type);
}
// Query with all possible fields (publisher/advertiser/admin)
{
let query_str = "limit=200&eventType=CLICK&metric=paid&segmentBy=country\
&timeframe=week&start=2022-08-04+09:00:00.000000000+UTC\
&campaignId=0x936da01f9abd4d9d80c702af85c822a8\
&adUnit=QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR\
&adSlot=Qmasg8FrbuSQpjFu3kRnZF9beg8rEBFrqgi1uXDRwCbX5f\
&adSlotType=legacy_300x100\
&advertiser=0xDd589B43793934EF6Ad266067A0d1D4896b0dff0\
&publisher=0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9\
&hostname=localhost&country=Bulgaria&osName=Windows\
&chains[0]=1&chains[1]=1337";
let query: AnalyticsQuery = serde_qs::from_str(query_str).unwrap();
assert_eq!(query.limit, 200);
assert_eq!(query.event_type, EventType::Click);
assert!(matches!(query.metric, Metric::Paid));
assert_eq!(query.segment_by, Some(AllowedKey::Country));
assert_eq!(
query.time,
Time {
timeframe: Timeframe::Week,
start: DateHour::from_ymdh(2022, 8, 4, 9),
end: None,
}
);
assert_eq!(
query.campaign_id,
Some(
CampaignId::from_str("0x936da01f9abd4d9d80c702af85c822a8")
.expect("should be valid")
)
);
assert_eq!(
query.ad_unit,
Some(
IPFS::from_str("QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR")
.expect("should be valid")
)
);
assert_eq!(
query.ad_slot,
Some(
IPFS::from_str("Qmasg8FrbuSQpjFu3kRnZF9beg8rEBFrqgi1uXDRwCbX5f")
.expect("should be valid")
)
);
assert_eq!(query.ad_slot_type, Some("legacy_300x100".to_string()));
assert_eq!(
query.advertiser,
Some(
Address::from_str("0xDd589B43793934EF6Ad266067A0d1D4896b0dff0")
.expect("should be valid")
)
);
assert_eq!(
query.publisher,
Some(
Address::from_str("0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9")
.expect("should be valid")
)
);
assert_eq!(query.hostname, Some("localhost".to_string()));
assert_eq!(query.country, Some("Bulgaria".to_string()));
assert_eq!(
query.os_name,
Some(OperatingSystem::Whitelisted("Windows".to_string()))
);
assert_eq!(query.chains, vec!(ChainId::new(1), ChainId::new(1337)));
}
}
Fields
limit: u32
Default: 100
event_type: EventType
Default: EventType::Impression
metric: Metric
segment_by: Option<AllowedKey>
time: Time
campaign_id: Option<CampaignId>
ad_unit: Option<IPFS>
ad_slot: Option<IPFS>
ad_slot_type: Option<String>
advertiser: Option<Address>
publisher: Option<Address>
hostname: Option<String>
country: Option<String>
os_name: Option<OperatingSystem>
chains: Vec<ChainId>
Implementations
sourceimpl AnalyticsQuery
impl AnalyticsQuery
Trait Implementations
sourceimpl Clone for AnalyticsQuery
impl Clone for AnalyticsQuery
sourcefn clone(&self) -> AnalyticsQuery
fn clone(&self) -> AnalyticsQuery
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for AnalyticsQuery
impl Debug for AnalyticsQuery
sourceimpl Default for AnalyticsQuery
impl Default for AnalyticsQuery
sourceimpl<'de> Deserialize<'de> for AnalyticsQuery
impl<'de> Deserialize<'de> for AnalyticsQuery
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Serialize for AnalyticsQuery
impl Serialize for AnalyticsQuery
Auto Trait Implementations
impl RefUnwindSafe for AnalyticsQuery
impl Send for AnalyticsQuery
impl Sync for AnalyticsQuery
impl Unpin for AnalyticsQuery
impl UnwindSafe for AnalyticsQuery
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more