[PR #3727] [MERGED] chore(common): analytics on spotlight #4510

Closed
opened 2026-03-17 02:02:18 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/3727
Author: @jamesgeorge007
Created: 1/7/2024
Status: Merged
Merged: 2/2/2024
Merged by: @AndrewBastin

Base: release/2023.12.4Head: spotlight-analytics


📝 Commits (10+)

  • a8ce0c1 chore: analytics on spotlight
  • 7eb0445 refactor: move analytics log event logic to spotlight service
  • 1e35a45 chore: compute the session duration and send it along
  • 2d4a8ce test: increase coverage
  • 759fa9b test: fix incorrect test case
  • c44f6bc refactor: use Date.now instead of timers for sessionDuration
  • 0339d10 refactor: move inputLength tracking outside of the for loop
  • cfc315a chore: fix mismatch between HoppAction and HoppActionArgsMap
  • 9d1c2db chore: fix type errors
  • 63a2537 chore: cleanup

📊 Changes

10 files changed (+267 additions, -76 deletions)

View changed files

📝 packages/hoppscotch-common/src/components/app/Header.vue (+1 -1)
📝 packages/hoppscotch-common/src/components/app/spotlight/index.vue (+30 -16)
📝 packages/hoppscotch-common/src/components/history/index.vue (+2 -1)
📝 packages/hoppscotch-common/src/components/http/Request.vue (+6 -19)
📝 packages/hoppscotch-common/src/helpers/actions.ts (+45 -21)
📝 packages/hoppscotch-common/src/helpers/keybindings.ts (+3 -3)
📝 packages/hoppscotch-common/src/layouts/default.vue (+18 -4)
📝 packages/hoppscotch-common/src/platform/analytics.ts (+12 -0)
📝 packages/hoppscotch-common/src/services/spotlight/__tests__/index.spec.ts (+97 -9)
📝 packages/hoppscotch-common/src/services/spotlight/index.ts (+53 -2)

📄 Description

Description

This PR introduces the changes for sending events about spotlight sessions to Posthog. This comprises of the following:

  • The method used to launch the spotlight (via keyboard shortcut / clicking on the spotlight bar).
  • The action (Hitting enter indicates success while pressing escape indicates close).
  • Rank of the item chosen from the results.
  • Length of the search query.
  • Session duration.
  • searcher ID (type of the selected result request, collection, etc).

Sample format

{
  "method": "click-spotlight-bar",
  "inputLength": 0,
  "action": "close",
  "rank": null,
  "searcherID": null,
  "sessionDuration": "0.90s"
}
{
  "method": "keyboard-shortcut",
  "inputLength": 7,
  "action": "success",
  "rank": 3.41,
  "searcherID": "collection",
  "sessionDuration": "1.92s"
}

Closes HFE-383.

Changes

  • A new AnalyticsEvent type is introduced with the name HOPP_SPOTLIGHT_SESSION.
  • The invokeAction method is updated to optionally take in a trigger argument that conveys the action trigger (keypress/mouseclick). This was required to communicate the spotlight launch method while opening cmd + k since the keybinding definitions didn't support supplying arguments along with invokeAction.
  • The keybinding definitions were previously a map of the shortcut keys to HoppActionsWithNoArgs. This is now changed to map to HoppActionWithOptionalArgs that compiles the actions with no arguments in addition to the actions that optionally accept arguments. For instance, request.save-as.
  • A new private property is added under SpotlightService to persist the session information and associated methods setAnalyticsData and getAnalyticsData to update and retrieve the information. The test suite is updated accordingly.
  • Fixes an incorrect test case in the spotlight service test suite.

Checks

  • My pull request adheres to the code style of this project
  • All the tests have passed

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/3727 **Author:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Created:** 1/7/2024 **Status:** ✅ Merged **Merged:** 2/2/2024 **Merged by:** [@AndrewBastin](https://github.com/AndrewBastin) **Base:** `release/2023.12.4` ← **Head:** `spotlight-analytics` --- ### 📝 Commits (10+) - [`a8ce0c1`](https://github.com/hoppscotch/hoppscotch/commit/a8ce0c103dd65a7dfaa96b47e2ce84d7027f8319) chore: analytics on spotlight - [`7eb0445`](https://github.com/hoppscotch/hoppscotch/commit/7eb0445c0f90ea8a6b46b1a539a80be126e609d6) refactor: move analytics log event logic to spotlight service - [`1e35a45`](https://github.com/hoppscotch/hoppscotch/commit/1e35a45996118af78c683f470679215705a84bcd) chore: compute the session duration and send it along - [`2d4a8ce`](https://github.com/hoppscotch/hoppscotch/commit/2d4a8ce329d4456ff7de40c35bb3471cd5f3f6d2) test: increase coverage - [`759fa9b`](https://github.com/hoppscotch/hoppscotch/commit/759fa9b2b2d2f93a1f014fc3c1df1b3448cfc5b9) test: fix incorrect test case - [`c44f6bc`](https://github.com/hoppscotch/hoppscotch/commit/c44f6bc29a5e8e7843c88564deff15a18433246b) refactor: use Date.now instead of timers for sessionDuration - [`0339d10`](https://github.com/hoppscotch/hoppscotch/commit/0339d10acfc2830f4dc8660782df040c08daa376) refactor: move inputLength tracking outside of the for loop - [`cfc315a`](https://github.com/hoppscotch/hoppscotch/commit/cfc315a94db5324e7de385c6e1b37ba8d9cb1be9) chore: fix mismatch between HoppAction and HoppActionArgsMap - [`9d1c2db`](https://github.com/hoppscotch/hoppscotch/commit/9d1c2dbc6ae18a90f846715bc5df35235cded3b5) chore: fix type errors - [`63a2537`](https://github.com/hoppscotch/hoppscotch/commit/63a25377c4cda5728e37c72c5e7691a9c01a3978) chore: cleanup ### 📊 Changes **10 files changed** (+267 additions, -76 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/components/app/Header.vue` (+1 -1) 📝 `packages/hoppscotch-common/src/components/app/spotlight/index.vue` (+30 -16) 📝 `packages/hoppscotch-common/src/components/history/index.vue` (+2 -1) 📝 `packages/hoppscotch-common/src/components/http/Request.vue` (+6 -19) 📝 `packages/hoppscotch-common/src/helpers/actions.ts` (+45 -21) 📝 `packages/hoppscotch-common/src/helpers/keybindings.ts` (+3 -3) 📝 `packages/hoppscotch-common/src/layouts/default.vue` (+18 -4) 📝 `packages/hoppscotch-common/src/platform/analytics.ts` (+12 -0) 📝 `packages/hoppscotch-common/src/services/spotlight/__tests__/index.spec.ts` (+97 -9) 📝 `packages/hoppscotch-common/src/services/spotlight/index.ts` (+53 -2) </details> ### 📄 Description ### Description This PR introduces the changes for sending events about spotlight sessions to Posthog. This comprises of the following: - The method used to launch the spotlight (via keyboard shortcut / clicking on the spotlight bar). - The action (Hitting enter indicates `success` while pressing escape indicates `close`). - Rank of the item chosen from the results. - Length of the search query. - Session duration. - searcher ID (type of the selected result `request`, `collection`, etc). > Sample format ```json { "method": "click-spotlight-bar", "inputLength": 0, "action": "close", "rank": null, "searcherID": null, "sessionDuration": "0.90s" } ``` ```json { "method": "keyboard-shortcut", "inputLength": 7, "action": "success", "rank": 3.41, "searcherID": "collection", "sessionDuration": "1.92s" } ``` Closes HFE-383. ### Changes - A new `AnalyticsEvent` type is introduced with the name `HOPP_SPOTLIGHT_SESSION`. - The `invokeAction` method is updated to optionally take in a `trigger ` argument that conveys the action trigger (keypress/mouseclick). This was required to communicate the spotlight launch method while opening `cmd + k` since the keybinding definitions didn't support supplying arguments along with `invokeAction`. - The keybinding definitions were previously a map of the shortcut keys to `HoppActionsWithNoArgs`. This is now changed to map to `HoppActionWithOptionalArgs` that compiles the actions with no arguments in addition to the actions that optionally accept arguments. For instance, `request.save-as`. - A new private property is added under `SpotlightService` to persist the session information and associated methods `setAnalyticsData` and `getAnalyticsData` to update and retrieve the information. The test suite is updated accordingly. - Fixes an incorrect test case in the spotlight service test suite. ### Checks - [x] My pull request adheres to the code style of this project - [x] All the tests have passed --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:02:18 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#4510
No description provided.