Question

JQL show events from a user custom field


Badge

I would like to get the list of events based on a user custom field named "Company ID". How do I write this JQL query?


I tried this but didn't work:

function main() {

return Events({

from_date: '2019-05-08',

to_date: '2019-05-30',

})

People(),

{

type:"inner",

selectors:[{selector:

'properties["company_id"] == "0cd2eaf.....df1326ca"'}]

}

}




5 replies

Userlevel 3
Badge

hey @daner06, I think this community post on JQL will be helpful for you https://community.mixpanel.com/questions/2092/how-to-write-this-jql-query-to-return-all-the-even.html



Badge

Thanks for the link.


However, I tried that query:


function main() {

return Events({

from_date: '2019-05-01',

to_date: '2019-05-31',

event_selectors: [

{selector: '"0cd2eaf.....df1326ca" in properties["company_id"]'},

]

})

}


But that returns only the company id from events (there are only a few only, not all rows have this field in the list of events).



What I need is the company id from the user table:


So, the list of event from company id in users.


Thank you for your help.



Badge

@Willyv, I tried with join as well. But I don't have the details of the events:


function main() {

return join(

Events({

from_date: '2019-05-01',

to_date: '2019-06-03',

}),

People(),

{

type:"right",

selectors:[{selector:

'properties["company_id"] == "0cd2eaf.....df1326ca"'}]

}

);

}


In the result, I supposed it it is in the event.dataset...


Can you help?


Badge

Hey @daner06, Sorry for the delay in response, hopefully this is still useful. I think you are looking for the `user` keyword within the selector language. For instance to count all events done by users with user property "user_prop" set to "foo_bar".

function main() {
  return join(Events({
    from_date: '2019-06-17',
    to_date:   '2019-06-18',
  }),
   People({
     user_selectors: [{selector: 'user["user_prop"] == "foo_bar"'}]
   }),
   {type: 'inner'}
  )
  .groupBy(["event.name"], mixpanel.reducer.count());
}


This assumes queries like:

 var main = () => People().reduce(mixpanel.reducer.any())

returns objects like:

 {"properties": {"user_prop": "foo_bar"}, "distinct_id": "bar", ...}

HTH,
-Marcus


Badge

how can i get all event for each user, means user and his all events in one object


Reply