feat: track events in note creator

This commit is contained in:
Kieran 2023-12-10 17:40:54 +00:00
parent d2cec4909c
commit a1e9df8254
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
1 changed files with 26 additions and 15 deletions

View File

@ -6,7 +6,7 @@ import { TagsInput } from "react-tag-input-component";
import Icon from "@/Icons/Icon";
import useEventPublisher from "@/Hooks/useEventPublisher";
import { appendDedupe, openFile } from "@/SnortUtils";
import { appendDedupe, openFile, trackEvent } from "@/SnortUtils";
import Textarea from "@/Element/Textarea";
import Modal from "@/Element/Modal";
import ProfileImage from "@/Element/User/ProfileImage";
@ -158,6 +158,16 @@ export function NoteCreator() {
async function sendNote() {
const ev = await buildNote();
if (ev) {
trackEvent("PostNote")
if (ev.tags.find(a => a[0] === "content-warning")) {
trackEvent("PostNote:WithContentWarning");
}
if (ev.tags.find(a => a[0] === "poll_option")) {
trackEvent("PostNote:WithPoll");
}
if (ev.tags.find(a => a[0] === "zap")) {
trackEvent("PostNote:WithZapSplit");
}
const events = (note.otherEvents ?? []).concat(ev);
events.map(a =>
sendEventToRelays(system, a, note.selectedCustomRelays, r => {
@ -193,7 +203,7 @@ export function NoteCreator() {
}
}
async function uploadFile(file: File | Blob) {
async function uploadFile(file: File) {
try {
if (file) {
const rx = await uploader.upload(file, file.name);
@ -259,6 +269,7 @@ export function NoteCreator() {
note.update(v => (v.preview = undefined));
} else if (publisher) {
const tmpNote = await buildNote();
trackEvent("PostNote:Preview");
note.update(v => (v.preview = tmpNote));
}
}
@ -341,18 +352,18 @@ export function NoteCreator() {
onChange={e => {
note.update(
v =>
(v.selectedCustomRelays =
// set false if all relays selected
e.target.checked &&
(v.selectedCustomRelays =
// set false if all relays selected
e.target.checked &&
note.selectedCustomRelays &&
note.selectedCustomRelays.length == a.length - 1
? undefined
: // otherwise return selectedCustomRelays with target relay added / removed
a.filter(el =>
el === r
? e.target.checked
: !note.selectedCustomRelays || note.selectedCustomRelays.includes(el),
)),
? undefined
: // otherwise return selectedCustomRelays with target relay added / removed
a.filter(el =>
el === r
? e.target.checked
: !note.selectedCustomRelays || note.selectedCustomRelays.includes(el),
)),
);
}}
/>
@ -421,9 +432,9 @@ export function NoteCreator() {
onChange={e =>
note.update(
v =>
(v.zapSplits = arr.map((vv, ii) =>
ii === i ? { ...vv, weight: Number(e.target.value) } : vv,
)),
(v.zapSplits = arr.map((vv, ii) =>
ii === i ? { ...vv, weight: Number(e.target.value) } : vv,
)),
)
}
/>