search action tracking (#507)

Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-04-26 13:27:33 +08:00 committed by GitHub
parent 05d0d8b8ef
commit 9fc5f62b70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -27,7 +27,9 @@ mixpanel.init(pub.PUBLIC_MIXPANEL_TOKEN, { debug: true });
enum AnalyticsAction {
install = "INSTALL_ACTION",
install_failed = "INSTALL_ACTION_FAILED"
install_failed = "INSTALL_ACTION_FAILED",
search = "SEARCH_ACTION",
search_failed = "SEARCH_ACTION_FAILED"
}
const trackAction = (action: AnalyticsAction, data?: { [key: string]: any }) => {
@ -63,3 +65,16 @@ export const trackInstallFailed = (packageFullname: string, error: string) => {
error
});
};
export const trackSearch = (search_term: string, result_count: number) => {
if (result_count > 0) {
trackAction(AnalyticsAction.search, {
search_term,
result_count
});
} else {
trackAction(AnalyticsAction.search_failed, {
search_term
});
}
};

View file

@ -10,6 +10,7 @@ import initNavStore from "./stores/nav";
import initPackagesStore from "./stores/pkgs";
import initNotificationStore from "./stores/notifications";
import initAppUpdateStore from "./stores/update";
import { trackSearch } from "./analytics";
export const featuredPackages = writable<Package[]>([]);
@ -116,6 +117,7 @@ function initSearchStore() {
packagesStore.search(term, 5)
// postsStore.search(term, 10)
]);
trackSearch(term, resultPkgs.length);
packagesSearch.set(resultPkgs);
// postsSearch.set(resultPosts);
} else {