Discrepancies in Event Counts from APIs and Export in Mixpanel
Hello, I’m trying to count the number of events I have per day. I’m doing it this way:
- 1.
Call: /api/query/events/names
- 2.
Feed the list of event names to: /api/query/events
The number I get matches what I see on the dashboard. But when I use the export API, on some days, the value is lower than what I get from /api/query/events. Why is that? This is my implementation for the export API. I’m in the range of ~1.8 million events per day, and my project timezone is in UTC.
pub async fn get_event_count_via_data_export(&self, from_date: &str, to_date: &str) -> Result<u64> {
let url = format!(https://data.mixpanel.com/api/2.0/export);
let resp = self
.http_client
.get(url)
.basic_auth(&self.project_secret, Some(""))
.query(&[
("from_date", from_date),
("to_date", to_date),
(
"where",
r#"properties["environment"] == "prod_walker" and properties["event_type"] == "ANALYTICS""#,
),
])
.send()
.await
.map_err(AlertError::Request)?;
if !resp.status().is_success() {
let error_body = resp.text().await.unwrap_or_else(|_| "Unknown error".to_string());
return Err(AlertError::Mixpanel(format!(
"API returned non-success status: {}",
error_body
)));
}
let body = resp.text().await.map_err(AlertError::Request)?;
let count = body.lines().count() as u64;
Ok(count)
}