Solved

Return Users Daily Event Count by Event Name

  • 10 July 2020
  • 2 replies
  • 312 views

I am hitting a brick wall here with trying to return one record with event count per user, per day, per event name.

I can successfully return one record with event count per user per day, but I cannot get it to add in the grouping level for the event name property, it just returns a null value.

Here is my code:

function main() {
return Events({
from_date: '2020-07-01',
to_date: '2020-07-10'
})
.groupByUser([getDay, "properties.Name"], mixpanel.reducer.count());
}

function getDay(event){
return new Date(event.time).toISOString().substr(0, 10);
}

This is what is returned (user ID has been anonymized):

  {
"key": [
"ANONYMOUS-USER-ID-123",
"2020-07-10",
null
],
"value": 23
},

Any help will be greatly appreciated, thanks!

icon

Best answer by Cara 10 July 2020, 19:50

Hey Anthony! I think what’s causing the null value in the response is that “Name” isn’t an event property in your Lexicon (which you can find under the Data Management tab). In Mixpanel, the event name property is tracked as “$event_name”.  

I took your script and tweaked “properties.Name” with “properties.$event_name”: 

function main() {
return Events({
from_date: '2020-07-01',
to_date: '2020-07-10'
})
.groupByUser([getDay, "properties.$event_name"], mixpanel.reducer.count());
}

function getDay(event){
return new Date(event.time).toISOString().substr(0, 10);
}

This is what I get returned :) 

  {
"key": [
"ANONYMIZED_DISTINCT_ID",
"2020-07-03",
"Signup Page View"
],
"value": 1
}

 

View original

2 replies

Userlevel 1
Badge

Hey Anthony! I think what’s causing the null value in the response is that “Name” isn’t an event property in your Lexicon (which you can find under the Data Management tab). In Mixpanel, the event name property is tracked as “$event_name”.  

I took your script and tweaked “properties.Name” with “properties.$event_name”: 

function main() {
return Events({
from_date: '2020-07-01',
to_date: '2020-07-10'
})
.groupByUser([getDay, "properties.$event_name"], mixpanel.reducer.count());
}

function getDay(event){
return new Date(event.time).toISOString().substr(0, 10);
}

This is what I get returned :) 

  {
"key": [
"ANONYMIZED_DISTINCT_ID",
"2020-07-03",
"Signup Page View"
],
"value": 1
}

 

@Cara Thank you, that works! I actually realized that “properties.name” would not work after posting this but had not yet figured out the reference should be to “properties.$event_name”

Reply


Mixpanel