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: EventTypemetric: Metricsegment_by: Option<AllowedKey>time: Timecampaign_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

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more