Skip to content

Commit

Permalink
Feature/using checkoutanalytics mvp qr codes (#2550)
Browse files Browse the repository at this point in the history
* Detect and send analytics event when qrCode's "Copy" btn is pressed

* Fixing unit test fail

* Removing child comp's submitAnalytics function (since all it does is call super)
  • Loading branch information
sponglord authored Feb 14, 2024
1 parent 077e23b commit b7493e8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/lib/src/components/WeChat/WeChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { delay, countdownTime } from './config';

class WeChatPayElement extends QRLoaderContainer {
public static type = 'wechatpayQR';
public static analyticsType = 'wechatpayQR'; // Needed for use-case where merchant makes a payment themselves and then calls checkout.createFromAction(action)

formatProps(props) {
return {
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/components/helpers/QRLoaderContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class QRLoaderContainer<T extends QRLoaderContainerProps = QRLoaderContainerProp
instructions={this.props.instructions}
onActionHandled={this.props.onActionHandled}
brandName={this.displayName}
onSubmitAnalytics={this.submitAnalytics}
/>
</SRPanelProvider>
</CoreProvider>
Expand Down
5 changes: 5 additions & 0 deletions packages/lib/src/components/internal/QRLoader/QRLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { StatusObject } from '../Await/types';
import useImage from '../../../core/Context/useImage';
import { useA11yReporter } from '../../../core/Errors/useA11yReporter';
import useAutoFocus from '../../../utils/useAutoFocus';
import { ANALYTICS_DOWNLOAD_STR, ANALYTICS_QR_CODE_DOWNLOAD } from '../../../core/Analytics/constants';

const QRCODE_URL = 'barcode.shtml?barcodeType=qrCode&fileType=png&data=';

Expand Down Expand Up @@ -246,6 +247,10 @@ class QRLoader extends Component<QRLoaderProps, QRLoaderState> {
variant="action"
onClick={(e, { complete }) => {
copyToClipboard(this.props.qrCodeData);
this.props.onSubmitAnalytics({
type: ANALYTICS_DOWNLOAD_STR,
target: ANALYTICS_QR_CODE_DOWNLOAD
});
complete();
}}
icon={getImage({ imageFolder: 'components/' })('copy')}
Expand Down
2 changes: 2 additions & 0 deletions packages/lib/src/components/internal/QRLoader/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PaymentAmount } from '../../../types';
import Language from '../../../language/Language';
import { ActionHandledReturnObject } from '../../types';
import { h } from 'preact';
import { SendAnalyticsObject } from '../../../core/Analytics/types';

export interface QRLoaderProps {
delay?: number;
Expand Down Expand Up @@ -29,6 +30,7 @@ export interface QRLoaderProps {
instructions?: string | (() => h.JSX.Element);
copyBtn?: boolean;
onActionHandled?: (rtnObj: ActionHandledReturnObject) => void;
onSubmitAnalytics?: (aObj: SendAnalyticsObject) => void;
}

export interface QRLoaderState {
Expand Down
2 changes: 2 additions & 0 deletions packages/lib/src/core/Analytics/analyticsPreProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ANALYTICS_ACTION_STR,
ANALYTICS_CONFIGURED_STR,
ANALYTICS_DISPLAYED_STR,
ANALYTICS_DOWNLOAD_STR,
ANALYTICS_EVENT_ERROR,
ANALYTICS_EVENT_INFO,
ANALYTICS_EVENT_LOG,
Expand Down Expand Up @@ -44,6 +45,7 @@ export const analyticsPreProcessor = (analyticsModule: AnalyticsModule) => {
case ANALYTICS_UNFOCUS_STR:
case ANALYTICS_DISPLAYED_STR: // issuerList
case ANALYTICS_INPUT_STR: // issuerList
case ANALYTICS_DOWNLOAD_STR: // QR codes
analyticsModule.createAnalyticsEvent({
event: ANALYTICS_EVENT_INFO,
data: { component, type, target }
Expand Down
5 changes: 5 additions & 0 deletions packages/lib/src/core/Analytics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ export const ANALYTICS_SELECTED_STR = 'selected';
export const ANALYTICS_RENDERED_STR = 'rendered';
export const ANALYTICS_DISPLAYED_STR = 'displayed';
export const ANALYTICS_INPUT_STR = 'input';

export const ANALYTICS_DOWNLOAD_STR = 'download';

export const ANALYTICS_VALIDATION_ERROR_STR = 'validationError';

export const ANALYTICS_FOCUS_STR = 'focus';
export const ANALYTICS_UNFOCUS_STR = 'unfocus';

export const ANALYTICS_CONFIGURED_STR = 'configured';

export const ANALYTICS_QR_CODE_DOWNLOAD = 'qr_download_button';

export const ANALYTICS_INSTANT_PAYMENT_BUTTON = 'instant_payment_button';
export const ANALYTICS_FEATURED_ISSUER = 'featured_issuer';
export const ANALYTICS_LIST = 'list';
Expand Down

0 comments on commit b7493e8

Please sign in to comment.