Reputation: 93
Besides "from and to date", I'd like to further segment event info from the Mixpanel export() API method by their times ( events contain a 'time' property, expressed as a unix timestamp ); but, eg, when I specify a "where" param, I get an empty response ( see below ).
"where" param = 'properties["time"] >= 1401642000'
I definitely have events that match this. Should this be working ?
no "where" param:
args = {'from_date': '2014-06-01', 'api_key': 'REDACTED', 'sig': 'REDACTED', 'to_date': '2014-06-04', 'expire': 1402424767}
response = [ I receive expected events ]
'where' param = 'properties["time"] >= 1401642000'
args = {'from_date': '2014-06-01', 'expire': 1402424767, 'sig': 'REDACTED', 'to_date': '2014-06-04', 'api_key': 'REDACTED', 'where': 'properties["time"] >= 1401642000'}
response = [ HTTP request succeeds, but response is empty ]
Same as above, except putting time value in quotes:
'where' param = 'properties["time"] >= "1401642000"'
args = {'from_date': '2014-06-01', 'expire': 1402424767, 'sig': 'REDACTED', 'to_date': '2014-06-04', 'api_key': 'REDACTED', 'where': 'properties["time"] >= "1401642000"'}
response = [ HTTP request succeeds, but response is empty ]
Try casting properties["time"] to a number:
'where' param = 'number(properties["time"]) >= 1401642000'
args = {'from_date': '2014-06-01', 'expire': 1402424767, 'sig': 'REDACTED', 'to_date': '2014-06-04', 'api_key': 'REDACTED', 'where': 'number(properties["time"]) >= 1401642000'}
response = [ HTTP request succeeds, but response is empty ]
Upvotes: 5
Views: 2835
Reputation: 88
I was able to solve this problem using Mixpanel's JQL API endpoint. As mentioned in other answers, the other Mixpanel API endpoints seem to ignore a 'time' parameter in the where clause. (Which is frustrating and confusing!)
Below is my solution in Python, in which I used the mixpanel-jql library to make things easy. It fetches 'Chat' events for after noon on Halloween (31-Oct-2018 GMT). It's worth noting that the from_date, to_date and e.time comparison need to all overlap to actually get events.
now = datetime(2018, 10, 31)
from_timestamp_epoch_ms = 1540987200000 # Noon, Halloween 2018, GMT
query = JQL(
MIXPANEL_SECRET,
events=Events({
# 'event_selectors' can be left out to grab all events
'event_selectors': [{'event': 'Chat'}],
'from_date': datetime(now.year, now.month, now.day),
'to_date': datetime(now.year, now.month, now.day)
})
).filter('e.time > {}'.format(from_timestamp_epoch_ms))
for row_dict in query.send():
# Work your magic
Upvotes: 0
Reputation: 1779
Answering the same problem with a different method: first export your data into MYSQL or any other database. I used to have my own script to do that but as the data volume became bigger and bigger I started to see the limitations of my custom script (duplicate events, long / heavy http requests, ...).
I am now using Mixpaneldb, which works very well for my needs.
Treasuredata can also do it apparently but they are not self served.
Upvotes: -1
Reputation: 189
I ran into the same problem on this API and tried various solutions before contacting their customer support. Their response was as follows:
"The bad news is that there's unfortunately no way to selectively export events from a particular time through the export API. This is largely due to the fact that time is not one of the exposed properties on your events to the API. The only properties that are exposed within the export API are the properties that were sent in with your events and actually exposed within the UI."
However, he went on to point out their newer JQL system https://mixpanel.com/help/reference/jql which can apparently filter on things like time.
Hope that helps.
Upvotes: 1
Reputation: 1
You can use the typecast function datetime() to cast the target timestamp to a datetime type, and then compare as you are above, e.g. "where" param = 'properties["time"] >= datetime(1401642000)'
.
You can also do time interval arithmetic inside the parentheses to build periods off a given starting or endpoint, e.g. "where" param = 'properties["time"] >= datetime(1401642000 - 60*60*24)'
for events where the "time" property occurred more than an hour before the target datetime.
Upvotes: 0