Question

JQuery: extract date from datetime

  • 30 July 2019
  • 1 reply
  • 296 views

Userlevel 3
Badge

Hi,
I need to extract $last_seen to date dd/mm/yyyy. I export raw data. Please help improve my JQL.
my JQL:

function main() {

return join(

Events({

from_date: "2019-01-01",

to_date: "2019-07-30",

}),

People(),

{type:'inner'}

)

//just return a single object per user in case any user has fired the event more than once

.groupByUser(mixpanel.reducer.any())

.map(function(tuple){

return {

"distinct_id": tuple.value.event.distinct_id,

"City": tuple.value.event.properties.$city,

"Email": tuple.value.user.properties.$email,

"Phone": tuple.value.user.properties.$phone,

"URL": tuple.value.event.properties.$current_url,

"Time": tuple.value.user.properties.$last_seen,

};

});

}



1 reply

Userlevel 1
Badge

Hi @cuongnd, If you're interested in only showing the person and their last_seen property, you can use the map (https://mixpanel.com/help/reference/jql/api-reference#api/transformations/map) function.


This would look like the following:

function main() {
  
  return People() // take all People profiles in your project 
  
  .filter(function(user){ // filter takes in a function
    return user.time && user.properties.$last_seen; // show only those that have a last seen property 
  })
  .map(function(user) { // take those with only a last seen property 
            return{
              distinct_id : user.properties.$distinct_id,  // display the distinct_id 
              City : user.properties.$city,  // display the city 
              email : user.properties.$email,  // display the email
              Last_seen : new Date(user.time).toISOString().slice(0,-14) // display last seen
              
            };
            });
}


Hope this helps!


Reply


Mixpanel