helpful-hydrogen-62495
02/23/2022, 7:22 PMfuture-teacher-7046
future-teacher-7046
future-teacher-7046
helpful-hydrogen-62495
02/23/2022, 7:32 PMhelpful-hydrogen-62495
02/23/2022, 7:34 PMfunction main() {
// Experiment results -
const metrics = [
{
"id": "met_19g61mkzeo90t4",
"name": "Signed Up"
},
{
"id": "met_19g61nkzydqvaz",
"name": "Landed on Home"
},
{
"id": "met_19g61pkzex04ba",
"name": "User Activated"
},
{
"id": "met_19g61ukzeo5jpf",
"name": "In-app purchase event (trial or subscription)"
}
];
return Events({from_date: "2022-02-23", to_date: "2022-02-23"})
.filter(function(e) {
if(e.name === "$experiment_started" && e.properties["Experiment name"] === "condensed-onboarding" && e.time >= 1645635600000) return true;
// Metric - Signed Up
if(e.name === "Signed Up") return true;
// Metric - Landed on Home
if(e.name === "Page Load" && e.properties["page"] === "Home") return true;
// Metric - User Activated
if(e.name === "User Activated") return true;
// Metric - In-app purchase event (trial or subscription)
if(e.name === "Subscribed Successfully") return true;
return false;
})
// Metric value per user
.groupByUser(function(state, events) {
state = state || {
inExperiment: false,
start: null,
variation: null,
m0: null,
m1: null,
m2: null,
m3: 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_started" && e.properties["Experiment name"] === "condensed-onboarding" && e.time >= 1645635600000) {
state.inExperiment = true;
state.variation = e.properties["Variant name"];
state.start = e.time;
continue;
}
// Not in the experiment yet
if(!state.inExperiment) {
continue;
}
// Metric - Signed Up
if(e.name === "Signed Up" && e.time - state.start < 259200000) {
state.m0 = Math.min(1,(state.m0 || 0) + 1);
}
// Metric - Landed on Home
if(e.name === "Page Load" && e.time - state.start < 3600000 && e.properties["page"] === "Home") {
state.m1 = Math.min(1,(state.m1 || 0) + 1);
}
// Metric - User Activated
if(e.name === "User Activated" && e.time - state.start < 259200000) {
state.m2 = Math.min(1,(state.m2 || 0) + 1);
}
// Metric - In-app purchase event (trial or subscription)
if(e.name === "Subscribed Successfully" && e.time - state.start < 259200000) {
state.m3 = Math.min(1,(state.m3 || 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 - Signed Up
mixpanel.reducer.numeric_summary('value.m0'),
// Metric - Landed on Home
mixpanel.reducer.numeric_summary('value.m1'),
// Metric - User Activated
mixpanel.reducer.numeric_summary('value.m2'),
// Metric - In-app purchase event (trial or subscription)
mixpanel.reducer.numeric_summary('value.m3'),
])
// 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;
});
}
helpful-hydrogen-62495
02/23/2022, 7:34 PMhelpful-hydrogen-62495
02/23/2022, 7:35 PMhelpful-hydrogen-62495
02/23/2022, 7:35 PMhelpful-hydrogen-62495
02/23/2022, 7:36 PMhelpful-hydrogen-62495
02/23/2022, 7:36 PMfuture-teacher-7046
future-teacher-7046
helpful-hydrogen-62495
02/23/2022, 7:40 PMhelpful-hydrogen-62495
02/23/2022, 7:40 PMhelpful-hydrogen-62495
02/23/2022, 7:41 PMtrackWithProperties
is an alias for track
, the library author just added separate methods per Obj C convention for each variant of argumentsfuture-teacher-7046
future-teacher-7046
helpful-hydrogen-62495
02/23/2022, 7:47 PMOpen source platform for stress free deployments, measured impact, and smarter decisions.
Powered by