-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DT-979: Add Appcues Support #2722
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
619966f
feat: add appcues support
rushtong 058918e
feat: add types to docker build
rushtong c020243
feat: basic tests for metrics class
rushtong 052e03b
formatting
rushtong 554e21f
doc update
rushtong 6a5750e
pr feedback
rushtong 5552e3d
formatting
rushtong 5ee185f
Merge branch 'refs/heads/develop' into gr-DT-979-appcues
rushtong cda0778
feat: use the same id we send to bard
rushtong 8f3f267
feat: use the oidc profile sub value which is what Terra does
rushtong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,15 +1,24 @@ | ||
import axios from 'axios'; | ||
import axios, {AxiosRequestConfig} from 'axios'; | ||
import {getDefaultProperties} from '@databiosphere/bard-client'; | ||
|
||
import {Storage} from '../storage'; | ||
import {getBardApiUrl} from '../ajax'; | ||
import {Token} from '../config'; | ||
import {MetricsEventName} from 'src/libs/events'; | ||
|
||
// Set default timeout for all metrics calls to 30 seconds | ||
const defaultSignal: AbortSignal = AbortSignal.timeout(30000); | ||
|
||
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this was necessary for typescriptification to make all the axios calls compile. I'm open to alternative suggestions here but this seems like a safe timeout for bard & appcues calls. |
||
export const Metrics = { | ||
captureEvent: (event, details, signal) => captureEventFn(event, details, signal).catch(() => { | ||
captureEvent: ( | ||
event: MetricsEventName, | ||
details: Record<string, any> = {}, | ||
signal: AbortSignal = defaultSignal, | ||
refreshAppcues: boolean = true | ||
) => captureEventFn(event, details, signal, refreshAppcues).catch(() => { | ||
}), | ||
syncProfile: (signal) => syncProfile(signal), | ||
identify: (anonId, signal) => identify(anonId, signal), | ||
syncProfile: (signal: AbortSignal = defaultSignal) => syncProfile(signal), | ||
identify: (anonId: String, signal: AbortSignal = defaultSignal) => identify(anonId, signal), | ||
}; | ||
|
||
/** | ||
|
@@ -18,12 +27,19 @@ export const Metrics = { | |
* @param {string} event - The event name. | ||
* @param {Object} [details={}] - The event details. | ||
* @param {AbortSignal} [signal] - The abort signal. | ||
* @param refreshAppcues - The refresh Appcues flag. | ||
* @returns {Promise} - A Promise that resolves when the event is captured. | ||
*/ | ||
const captureEventFn = async (event, details = {}, signal) => { | ||
const captureEventFn = async (event: MetricsEventName, details: object = {}, signal: AbortSignal, refreshAppcues: boolean): Promise<any> => { | ||
const isSignedIn = Storage.userIsLogged(); | ||
rushtong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const isRegistered = isSignedIn && Storage.getCurrentUser(); | ||
|
||
// Send event to Appcues and refresh Appcues state | ||
window.Appcues?.track(event); | ||
if (refreshAppcues) { | ||
window.Appcues?.page(); | ||
} | ||
|
||
if (!isRegistered && !Storage.getAnonymousId()) { | ||
Storage.setAnonymousId(); | ||
} | ||
|
@@ -40,7 +56,7 @@ const captureEventFn = async (event, details = {}, signal) => { | |
}, | ||
}; | ||
|
||
const config = { | ||
const config: AxiosRequestConfig = { | ||
method: 'POST', | ||
url: `${await getBardApiUrl()}/api/event`, | ||
data: body, | ||
|
@@ -57,8 +73,8 @@ const captureEventFn = async (event, details = {}, signal) => { | |
* @param {AbortSignal} [signal] - The abort signal. | ||
* @returns {Promise} - A Promise that resolves when the profile is synced. | ||
*/ | ||
const syncProfile = async (signal) => { | ||
const config = { | ||
const syncProfile = async (signal: AbortSignal): Promise<any> => { | ||
const config: AxiosRequestConfig = { | ||
method: 'POST', | ||
url: `${await getBardApiUrl()}/api/syncProfile`, | ||
headers: {Authorization: `Bearer ${Token.getToken()}`}, | ||
|
@@ -76,10 +92,24 @@ const syncProfile = async (signal) => { | |
* @param {AbortSignal} [signal] - The abort signal. | ||
* @returns {Promise} - A Promise that resolves when the user is identified. | ||
*/ | ||
const identify = async (anonId, signal) => { | ||
const identify = async (anonId: String, signal: AbortSignal): Promise<any> => { | ||
const body = {anonId}; | ||
|
||
const config = { | ||
if (window.Appcues) { | ||
const user = Storage.getCurrentUser(); | ||
const createDate = user.createDate ? user.createDate : new Date().getTime(); | ||
const appcuesProps = { | ||
dateJoined: createDate, | ||
app: 'DUOS' | ||
}; | ||
if (user.userStatusInfo?.userSubjectId) { | ||
window.Appcues.identify(user.userStatusInfo.userSubjectId, appcuesProps); | ||
} else { | ||
window.Appcues.identify(`${user.userId}`, appcuesProps); | ||
} | ||
} | ||
|
||
const config: AxiosRequestConfig = { | ||
method: 'POST', | ||
url: `${await getBardApiUrl()}/api/identify`, | ||
data: body, | ||
|
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* NOTE: See the Mixpanel guide in the terra-ui GitHub Wiki for more details: | ||
* https://github.com/DataBiosphere/terra-ui/wiki/Mixpanel | ||
*/ | ||
const eventList = { | ||
userRegister: 'user:register', | ||
userSignIn: 'user:signin', | ||
|
||
pageView: 'page:view', | ||
dataLibrary: 'page:view:data-library', | ||
dar: 'page:view:dar' | ||
}; | ||
|
||
export default eventList; | ||
|
||
// Helper type to create BaseMetricsEventName. | ||
type MetricsEventsMap<EventName> = { [key: string]: EventName | MetricsEventsMap<EventName> }; | ||
// Union type of all event names configured in eventsList. | ||
type BaseMetricsEventName = typeof eventList extends MetricsEventsMap<infer EventName> ? EventName : never; | ||
// Each route has its own page view event, where the event name includes the name of the route. | ||
type PageViewMetricsEventName = `${typeof eventList.pageView}:${string}`; | ||
|
||
/** | ||
* Union type of all metrics event names. | ||
*/ | ||
export type MetricsEventName = BaseMetricsEventName | PageViewMetricsEventName; |
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 |
---|---|---|
|
@@ -21,7 +21,8 @@ | |
} | ||
}, | ||
"include": [ | ||
"src" | ||
"src", | ||
"types/index.d.ts" | ||
], | ||
"plugins": ["@typescript-eslint", "import"] | ||
} |
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,4 @@ | ||
|
||
declare module "@databiosphere/bard-client" { | ||
export function getDefaultProperties(): any | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drive by fix - we removed "google sign in" in #2667