-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mauro Takeda
committed
Jul 22, 2023
1 parent
f1b4c40
commit 6a64cf5
Showing
4 changed files
with
128 additions
and
31 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import axios from 'axios' | ||
|
||
const ANALYTICS_URL = 'https://rc.vtex.com/api/analytics/schemaless-events' | ||
|
||
type CreateQuoteMetric = { | ||
kind: 'create-quote-ui-event' | ||
description: 'Create Quotation Action - UI' | ||
} | ||
|
||
type UseQuoteMetric = { | ||
kind: 'use-quote-ui-event' | ||
description: 'Use Quotation Action - UI' | ||
} | ||
|
||
export type Metric = { | ||
name: 'b2b-suite-buyerorg-data' | ||
account: string | ||
} & (CreateQuoteMetric | UseQuoteMetric) | ||
|
||
export type SessionProfile = { | ||
id: { value: string } | ||
email: { value: string } | ||
} | ||
|
||
export type SessionResponse = { | ||
namespaces: { | ||
profile: SessionProfile | ||
} | ||
} | ||
|
||
export const sendMetric = async (metric: Metric) => { | ||
try { | ||
await axios.post(ANALYTICS_URL, metric) | ||
} catch (error) { | ||
console.warn('Unable to log metrics', error) | ||
} | ||
} |
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,65 @@ | ||
import type { Metric, SessionResponse } from './metrics' | ||
import { sendMetric } from './metrics' | ||
|
||
type UseQuoteFieldsMetric = { | ||
quote_id: string | ||
quote_reference_name: string | ||
order_form_id: string | ||
quote_creation_date: string | ||
quote_use_date: string | ||
creator_email: string | ||
user_email: string | ||
cost_center_name: string | ||
buy_org_id: string | ||
buy_org_name: string | ||
quote_last_update: string | ||
} | ||
|
||
type UseQuoteMetric = Metric & { fields: UseQuoteFieldsMetric } | ||
|
||
export type UseQuoteMetricsParams = { | ||
quoteState: Quote | ||
orderFormId: string | ||
account: string | ||
sessionResponse: SessionResponse | ||
} | ||
|
||
const buildUseQuoteMetric = async ( | ||
metricsParam: UseQuoteMetricsParams | ||
): Promise<UseQuoteMetric> => { | ||
const { quoteState, orderFormId, account, sessionResponse } = metricsParam | ||
|
||
const metric: UseQuoteMetric = { | ||
name: 'b2b-suite-buyerorg-data', | ||
kind: 'use-quote-ui-event', | ||
description: 'Use Quotation Action - UI', | ||
account, | ||
fields: { | ||
buy_org_id: quoteState.organization, | ||
buy_org_name: quoteState.organizationName, | ||
cost_center_name: quoteState.costCenterName, | ||
quote_id: quoteState.id, | ||
quote_reference_name: quoteState.referenceName, | ||
order_form_id: orderFormId, | ||
quote_creation_date: quoteState.creationDate, | ||
quote_use_date: new Date().toISOString(), | ||
creator_email: quoteState.creatorEmail, | ||
user_email: sessionResponse.namespaces?.profile?.email?.value, | ||
quote_last_update: quoteState.lastUpdate, | ||
}, | ||
} | ||
|
||
return metric | ||
} | ||
|
||
export const sendUseQuoteMetric = async ( | ||
metricsParam: UseQuoteMetricsParams | ||
) => { | ||
try { | ||
const metric = await buildUseQuoteMetric(metricsParam) | ||
|
||
sendMetric(metric) | ||
} catch (error) { | ||
console.warn('Unable to log metrics', error) | ||
} | ||
} |