Skip to content

Latest commit

 

History

History
240 lines (211 loc) · 5.8 KB

File metadata and controls

240 lines (211 loc) · 5.8 KB

Event routes:

keep in mind:

  type eventName = "login" | "signup" | "admin" | "/";
  type os = "windows" | "mac" | "linux" | "ios" | "android" | "other";
  type browser = "chrome" | "safari" | "edge" | "firefox" | "ie" | "other";
  type GeoLocation = {
    location: Location;
    accuracy: number;
  };
  type Location = {
    lat: number;
    lng: number;
  };

interface event {
   _id: string;
  session_id: string;
  name: eventName;
  url: string;
  distinct_user_id: string;
  date: number; // Date.prototype.getTime()
  os: os;
  browser: browser;
  geolocation: GeoLocation;
  }

let exampleEvent = {
  _id: 'VATb6bdcOEW', 
  session_id: 'd788bae3-6909-49a2-a54a-6d50d35b3c70',  
  name: 'signup',  
  distinct_user_id: 'O-5mFsaxp9',  
  date: 1603316369846,  
  os: 'ios',  
  browser: 'chrome',  
  geolocation: {  
    location: {
      lat: 81,
      lng: 86
    },  
    accuracy: 1708
  },  
  url: 'http://localhost3000/signup'
}

POST /events

recives Event object in the request body(according to Event interface), and add it to DB.


/events/all

returns all events in an array:

declare function allEvents():event[]

/events/all-filtered

interface Filter {
  sorting: string; // '+date'/'-date'
  type: string; 
  browser: string;
  search: string;
  offset: number;
}
const filters: Filter = req.query;
declare function allEvents():event[]

recives query params from client (according to Filter interface).

  • sorting- must option : +date sort the events from latest to earliest, -date the opposite ( you can add more options if you want )
  • type- recives one of the eventName options according to the Event interface, and returns only matching Events.
  • browser- recives one of the browser options according to the Event interface, and returns only matching Events.
  • search- recives a value and test if it exists in one of the Event entities.
  • offset- recives an integer representing the number of events to send back to the client.

IMPORTANT The entry point response format is

{
  events: [], // array containing the filtered events
  more: true // or false
}

more - informs the client if there are events that weren't sent (becuase of the offset).


/by-days/:offset

reutns a count of unique sessions for the relevant day (events with different session_id), grouped by days, for one week.

offset- number of days to go back from today. If offset is 0 the return result should be week ago strting from today.

example: current date- 30/10/2020, http request- http://localhost:3000/events/by-days/0

[
  {
    date: "24/10/2020",
    count: 12
  }, 
  {
    date: "25/10/2020",
    count: 43
  }, 
  {
    date: "26/10/2020",
    count: 7
  }, 
  ...
  ...
  ...
  {
    date: "30/10/2020",
    count: 78
  }, 
]

current date- 30/10/2020, http request- http://localhost:3000/events/by-days/2

[
  {
    date: "22/10/2020",
    count: 7
  }, 
  {
    date: "23/10/2020",
    count: 78
  }, 
  {
    date: "24/10/2020",
    count: 12
  }, 
  ...
  ...
  ...
  {
    date: "28/10/2020",
    count: 26
  }, 
]

/by-hours/:offset

reutns a count of unique sessions for the relevant hour (events with different session_id), grouped by hour, for one day.

offset- number of days to go back from today. If offset is 0 the return result should todays sessions.

example: current date- 30/10/2020, http request- http://localhost:3000/events/by-hours/1

[ // sessions count for 29/10/2020
  {
    hour: "00:00",
    count: 12
  }, 
  {
    hour: "01:00",
    count: 43
  }, 
  {
    hour: "02:00",
    count: 7
  }, 
  {
    hour: "03:00",
    count: 78
  }, 
  ...
  ...
  ...
  {
    hour: "23:00",
    count: 54
  }
]

/retention

request url should look like: /retention?dayZero=11231231 for instance.
get a "dayZero" query Parameter which denotes the day, as milliseconds, to start calculating from, return the an array of objects with User retention Information for every week since dayZero. For every week, what percent of the users that signed up on that week have logged in to the site on every consecutive week.

interface weeklyRetentionObject {
  registrationWeek:number;  //launch is week 0 and so on
  newUsers:number;  // how many new user have joined this week
  weeklyRetention:number[]; // for every week since, what percentage of the users came back. weeklyRetention[0] is always 100% because it's the week of registration  
  start:string;  //date string for the first day of the week
  end:string  //date string for the first day of the week
}
let week0Retention : weeklyRetentionObject = {
  registrationWeek: 1, 
  newUsers: 34, 
  weeklyRetention:[100,24,45,66,1,80],  // here we see there were 7 in total since week 1 has data for 6 weeks 
  start:'01/11/2020',
  end: '07/11/2020'
} 

declare function getRetentionCohort(dayZero:number) : weeklyRetentionObject[]