plain-lizard-13513
09/04/2021, 8:07 AMfuture-teacher-7046
plain-lizard-13513
09/08/2021, 2:23 PMfuture-teacher-7046
plain-lizard-13513
09/21/2021, 12:12 PMfunction main() {
// Experiment results - User decide boost UI2
const metrics = [
{
"id": "met_3bwgdd13ks6bu7nn",
"name": "created_plan"
},
{
"id": "met_19g614ks32p0cy",
"name": "appointment_booked"
}
];
return Events({from_date: "2021-09-21", to_date: "2021-09-21"})
.filter(function(e) {
if(e.name === "Experiment Viewed" && e.properties["experiment_id"] === "user-decide-boost-ui2") return true;
// Metric - created_plan
if(e.name === "created_plan") return true;
// Metric - appointment_booked
if(e.name === "appointment_booked") return true;
return false;
})
// Metric value per user
.groupByUser(function(state, events) {
state = state || {
inExperiment: false,
start: null,
variation: null,
m0: null,
m1: null,
};
for(var i=0; i<events.length; i++) {
const e = events[i];
// User is put into the experiment
if(!state.inExperiment && e.name === "Experiment Viewed" && e.properties["experiment_id"] === "user-decide-boost-ui2") {
state.inExperiment = true;
state.variation = e.properties["variation_id"];
state.start = e.time;
continue;
}
// Not in the experiment yet
if(!state.inExperiment) {
continue;
}
// Metric - created_plan
if(e.name === "created_plan" && e.time - state.start < 259200000) {
state.m0 = Math.min(1,(state.m0 || 0) + 1);
}
// Metric - appointment_booked
if(e.name === "appointment_booked" && e.time - state.start < 259200000) {
state.m1 = Math.min(1,(state.m1 || 0) + 1);
}
}
return state;
})
// Remove users that are not in the experiment
.filter(function(ev) {
if(!ev.value.inExperiment) return false;
if(ev.value.variation === null || ev.value.variation === undefined) return false;
return true;
})
// One group per experiment variation with summary data
.groupBy(["value.variation"], [
// Total users in the group
mixpanel.reducer.count(),
// Metric - created_plan
mixpanel.reducer.numeric_summary('value.m0'),
// Metric - appointment_booked
mixpanel.reducer.numeric_summary('value.m1'),
])
// Convert to an object that's easier to work with
.map(row => {
const ret = {
variation: row.key[0],
dimension: '',
users: row.value[0],
metrics: [],
};
for(let i=1; i<row.value.length; i++) {
ret.metrics.push({
id: metrics[i-1].id,
name: metrics[i-1].name,
count: row.value[i].count,
mean: row.value[i].avg,
stddev: row.value[i].stddev,
});
}
return ret;
});
}
future-teacher-7046
filter
function thoughplain-lizard-13513
09/21/2021, 1:01 PM