-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track gen-ai use in Intercom COMPASS-7116 (#5442)
* feat: track gen-ai use in Intercom COMPASS-7116 * test: add onSubmit tests * closer check and cleanup * add dependency * add a catch * limit track to compass + dependency
- Loading branch information
1 parent
3965d40
commit 946f648
Showing
7 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging'; | ||
const { debug } = createLoggerAndTelemetry('COMPASS-INTERCOM'); | ||
|
||
type WindowWithIntercomGlobals = Window & | ||
typeof globalThis & { | ||
Intercom?: (...args: any[]) => any; | ||
attachEvent?: (...args: any[]) => any; | ||
}; | ||
|
||
export enum IntercomTrackingEvent { | ||
submittedNlPrompt = 'submitted-nl-prompt', | ||
} | ||
|
||
export function intercomTrack( | ||
event: IntercomTrackingEvent, | ||
metadata?: unknown | ||
) { | ||
const win = window as WindowWithIntercomGlobals; | ||
if (typeof win === 'undefined') { | ||
return; | ||
} | ||
|
||
if ( | ||
!win.Intercom || | ||
typeof win.Intercom !== 'function' || | ||
// the last check is because the packages might be embedded in an environment where an external Intercom lives | ||
// this way we ensure we don't polute such external Intercom with events intended for Compass Intercom | ||
!process.env.HADRON_METRICS_INTERCOM_APP_ID | ||
) { | ||
return; | ||
} | ||
|
||
try { | ||
win.Intercom('track', event, metadata); | ||
} catch (error) { | ||
debug('intercom track error', error); | ||
} | ||
} |