fix(analytics): fix send later and snooze analytics

This commit is contained in:
Evan Morikawa 2016-02-25 14:01:00 -08:00
parent 1d130e15c8
commit a63bc9e4b0
4 changed files with 18 additions and 16 deletions

View file

@ -56,21 +56,21 @@ class SendLaterPopover extends Component {
onSelectMenuOption = (optionKey)=> {
const date = SendLaterOptions[optionKey]();
this.onSelectDate(date);
this.onSelectDate(date, optionKey);
};
onSelectCustomOption = (value)=> {
const date = DateUtils.futureDateFromString(value);
if (date) {
this.onSelectDate(date);
this.onSelectDate(date, "Custom");
} else {
NylasEnv.showErrorDialog(`Sorry, we can't parse ${value} as a valid date.`);
}
};
onSelectDate = (date)=> {
onSelectDate = (date, label)=> {
const formatted = DateUtils.format(date.utc());
SendLaterActions.sendLater(this.props.draftClientId, formatted);
SendLaterActions.sendLater(this.props.draftClientId, formatted, label);
this.setState({scheduledDate: 'saving', inputDate: null});
this.refs.popover.close();
};

View file

@ -42,12 +42,13 @@ class SendLaterStore extends NylasStore {
});
};
recordAction(sendLaterDate) {
recordAction(sendLaterDate, label) {
try {
if (sendLaterDate) {
const sec = Math.round(((new Date(sendLaterDate)).valueOf() - Date.now()) / 1000);
const min = Math.round(((new Date(sendLaterDate)).valueOf() - Date.now()) / 1000 / 60);
Actions.recordUserEvent("Send Later", {
snoozeTime: sec,
sendLaterTime: min,
optionLabel: label,
});
} else {
Actions.recordUserEvent("Send Later Cancel");
@ -57,8 +58,8 @@ class SendLaterStore extends NylasStore {
}
}
onSendLater = (draftClientId, sendLaterDate)=> {
this.recordAction(sendLaterDate)
onSendLater = (draftClientId, sendLaterDate, label)=> {
this.recordAction(sendLaterDate, label)
this.setMetadata(draftClientId, {sendLaterDate});
};

View file

@ -65,10 +65,10 @@ class SnoozePopoverBody extends Component {
this.props.swipeCallback(this.didSnooze);
}
onSnooze(dateGenerator) {
onSnooze(dateGenerator, label) {
const utcDate = dateGenerator().utc();
const formatted = DateUtils.format(utcDate);
SnoozeActions.snoozeThreads(this.props.threads, formatted);
SnoozeActions.snoozeThreads(this.props.threads, formatted, label);
this.didSnooze = true;
this.props.closePopover();
@ -87,7 +87,7 @@ class SnoozePopoverBody extends Component {
if (value.length > 0 && ["Enter", "Return"].includes(event.key)) {
const inputDate = DateUtils.futureDateFromString(value);
if (inputDate) {
this.onSnooze(()=> inputDate);
this.onSnooze(() => {return inputDate}, "Custom");
// Prevent onInputChange from firing
event.stopPropagation()
}
@ -103,7 +103,7 @@ class SnoozePopoverBody extends Component {
<div
key={label}
className="snooze-item"
onClick={this.onSnooze.bind(this, dateGenerator)}>
onClick={this.onSnooze.bind(this, dateGenerator, label)}>
<RetinaImg
url={iconPath}
mode={RetinaImg.Mode.ContentIsMask} />

View file

@ -14,12 +14,13 @@ class SnoozeStore {
this.unsubscribe = SnoozeActions.snoozeThreads.listen(this.onSnoozeThreads)
}
onSnoozeThreads = (threads, snoozeDate)=> {
onSnoozeThreads = (threads, snoozeDate, label) => {
try {
const sec = Math.round(((new Date(snoozeDate)).valueOf() - Date.now()) / 1000);
const min = Math.round(((new Date(snoozeDate)).valueOf() - Date.now()) / 1000 / 60);
Actions.recordUserEvent("Snooze Threads", {
numThreads: threads.length,
snoozeTime: sec,
snoozeTime: min,
buttonType: label,
});
} catch (e) {
// Do nothing