Skip to content
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

Fix/analytics v1 priority1 #2487

Merged
merged 5 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Current Develop Branch

## v2.1.0 - Apr 12 2021
- [#2487](https://github.com/MetaMask/metamask-mobile/pull/2487): Fix/analytics v1 priority1
- [#2456](https://github.com/MetaMask/metamask-mobile/pull/2456): Analytics v2 (priority 1)
- [#2408](https://github.com/MetaMask/metamask-mobile/pull/2408): Fix/gas estimations
- [#2479](https://github.com/MetaMask/metamask-mobile/pull/2479): remove controllers tgz
Expand Down
2 changes: 1 addition & 1 deletion app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ const Main = props => {
const onUnapprovedMessage = (messageParams, type) => {
const { title: currentPageTitle, url: currentPageUrl } = messageParams.meta;
delete messageParams.meta;
setSignMessage(true);
setSignMessageParams(messageParams);
setSignType(type);
setCurrentPageTitle(currentPageTitle);
setCurrentPageUrl(currentPageUrl);
setSignMessage(true);
};

const connectionChangeHandler = useCallback(
Expand Down
20 changes: 12 additions & 8 deletions app/components/UI/AccountApproval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,18 @@ class AccountApproval extends PureComponent {
};

getAnalyticsParams = () => {
const { currentPageInformation, chainId, networkType } = this.props;
const url = new URL(currentPageInformation.url);
return {
dapp_host_name: url?.host,
dapp_url: currentPageInformation?.url,
network_name: networkType,
chain_id: chainId
};
try {
const { currentPageInformation, chainId, networkType } = this.props;
const url = new URL(currentPageInformation?.url);
return {
dapp_host_name: url?.host,
dapp_url: currentPageInformation?.url,
network_name: networkType,
chain_id: chainId
};
} catch (error) {
return {};
}
};

componentDidMount = () => {
Expand Down
18 changes: 10 additions & 8 deletions app/components/UI/AddCustomCollectible/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ class AddCustomCollectible extends PureComponent {
};

getAnalyticsParams = () => {
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const { address } = this.state;
return {
collectible_address: { value: address, anonymous: true },
network_name: type,
chain_id: chainId
};
try {
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
return {
network_name: type,
chain_id: chainId
};
} catch (error) {
return {};
}
};

addCollectible = async () => {
Expand Down
24 changes: 14 additions & 10 deletions app/components/UI/AddCustomToken/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,20 @@ export default class AddCustomToken extends PureComponent {
};

getAnalyticsParams = () => {
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const { address, symbol } = this.state;
return {
token_address: { value: address, anonymous: true },
token_symbol: { value: symbol, anonymous: true },
network_name: type,
chain_id: chainId,
source: 'Custom token'
};
try {
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const { address, symbol } = this.state;
return {
token_address: address,
token_symbol: symbol,
network_name: type,
chain_id: chainId,
source: 'Custom token'
};
} catch (error) {
return {};
}
};

addToken = async () => {
Expand Down
44 changes: 24 additions & 20 deletions app/components/UI/ApproveTransactionReview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,26 +318,30 @@ class ApproveTransactionReview extends PureComponent {
}

getAnalyticsParams = () => {
const { activeTabUrl, transaction, onSetAnalyticsParams } = this.props;
const { tokenSymbol, originalApproveAmount, encodedAmount } = this.state;
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const isDapp = !Object.values(AppConstants.DEEPLINKS).includes(transaction.origin);
const unlimited = encodedAmount === 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
const params = {
dapp_host_name: transaction?.origin,
dapp_url: isDapp ? activeTabUrl : undefined,
network_name: type,
chain_id: chainId,
active_currency: { value: tokenSymbol, anonymous: true },
number_tokens_requested: { value: originalApproveAmount, anonymous: true },
unlimited_permission_requested: unlimited,
referral_type: isDapp ? 'dapp' : transaction?.origin
};
// Send analytics params to parent component so it's available when cancelling and confirming
onSetAnalyticsParams && onSetAnalyticsParams(params);

return params;
try {
const { activeTabUrl, transaction, onSetAnalyticsParams } = this.props;
const { tokenSymbol, originalApproveAmount, encodedAmount } = this.state;
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const isDapp = !Object.values(AppConstants.DEEPLINKS).includes(transaction?.origin);
const unlimited = encodedAmount === 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
const params = {
dapp_host_name: transaction?.origin,
dapp_url: isDapp ? activeTabUrl : undefined,
network_name: type,
chain_id: chainId,
active_currency: { value: tokenSymbol, anonymous: true },
number_tokens_requested: { value: originalApproveAmount, anonymous: true },
unlimited_permission_requested: unlimited,
referral_type: isDapp ? 'dapp' : transaction?.origin
};
// Send analytics params to parent component so it's available when cancelling and confirming
onSetAnalyticsParams && onSetAnalyticsParams(params);

return params;
} catch (error) {
return {};
}
};

trackApproveEvent = event => {
Expand Down
24 changes: 14 additions & 10 deletions app/components/UI/CustomGas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,20 @@ class CustomGas extends PureComponent {
};

getAnalyticsParams = () => {
const { advancedCustomGas, chainId, networkType, view, analyticsParams } = this.props;
const { gasSpeedSelected } = this.state;
return {
...(analyticsParams || {}),
network_name: networkType,
chain_id: chainId,
function_type: { value: view, anonymous: true },
gas_mode: { value: advancedCustomGas ? 'Advanced' : 'Basic', anonymous: true },
speed_set: { value: advancedCustomGas ? undefined : gasSpeedSelected, anonymous: true }
};
try {
const { advancedCustomGas, chainId, networkType, view, analyticsParams } = this.props;
const { gasSpeedSelected } = this.state;
return {
...(analyticsParams || {}),
network_name: networkType,
chain_id: chainId,
function_type: view,
gas_mode: advancedCustomGas ? 'Advanced' : 'Basic',
speed_set: advancedCustomGas ? undefined : gasSpeedSelected
};
} catch (error) {
return {};
}
};

//Handle gas fee selection when save button is pressed instead of everytime a change is made, otherwise cannot switch back to review mode if there is an error
Expand Down
30 changes: 17 additions & 13 deletions app/components/UI/MessageSign/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,21 @@ export default class MessageSign extends PureComponent {
};

getAnalyticsParams = () => {
const { currentPageInformation } = this.props;
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const url = new URL(currentPageInformation.url);
return {
dapp_host_name: url?.host,
dapp_url: currentPageInformation?.url,
network_name: type,
chain_id: chainId,
sign_type: 'eth'
};
try {
const { currentPageInformation } = this.props;
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const url = new URL(currentPageInformation?.url);
return {
dapp_host_name: url?.host,
dapp_url: currentPageInformation?.url,
network_name: type,
chain_id: chainId,
sign_type: 'eth'
};
} catch (error) {
return {};
}
};

componentDidMount = () => {
Expand Down Expand Up @@ -113,14 +117,14 @@ export default class MessageSign extends PureComponent {
};

cancelSignature = () => {
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_CANCELLED, this.getAnalyticsParams());
this.rejectMessage();
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_CANCELLED, this.getAnalyticsParams());
this.props.onCancel();
};

confirmSignature = () => {
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_COMPLETED, this.getAnalyticsParams());
this.signMessage();
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_COMPLETED, this.getAnalyticsParams());
this.props.onConfirm();
};

Expand Down
31 changes: 18 additions & 13 deletions app/components/UI/PersonalSign/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@ export default class PersonalSign extends PureComponent {
};

getAnalyticsParams = () => {
const { currentPageInformation } = this.props;
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const url = new URL(currentPageInformation.url);
return {
dapp_host_name: url?.host,
dapp_url: currentPageInformation?.url,
network_name: type,
chain_id: chainId,
sign_type: 'personal'
};
try {
const { currentPageInformation } = this.props;
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const url = new URL(currentPageInformation?.url);

return {
dapp_host_name: url?.host,
dapp_url: currentPageInformation?.url,
network_name: type,
chain_id: chainId,
sign_type: 'personal'
};
} catch (error) {
return {};
}
};

componentDidMount = () => {
Expand Down Expand Up @@ -118,14 +123,14 @@ export default class PersonalSign extends PureComponent {
};

cancelSignature = () => {
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_CANCELLED, this.getAnalyticsParams());
this.rejectMessage();
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_CANCELLED, this.getAnalyticsParams());
this.props.onCancel();
};

confirmSignature = () => {
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_COMPLETED, this.getAnalyticsParams());
this.signMessage();
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_COMPLETED, this.getAnalyticsParams());
this.props.onConfirm();
};

Expand Down
24 changes: 14 additions & 10 deletions app/components/UI/SearchTokenAutocomplete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,20 @@ export default class SearchTokenAutocomplete extends PureComponent {
};

getAnalyticsParams = () => {
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const { address, symbol } = this.state.selectedAsset;
return {
token_address: { value: address, anonymous: true },
token_symbol: { value: symbol, anonymous: true },
network_name: type,
chain_id: chainId,
source: 'Add token dropdown'
};
try {
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const { address, symbol } = this.state.selectedAsset || {};
return {
token_address: address,
token_symbol: symbol,
network_name: type,
chain_id: chainId,
source: 'Add token dropdown'
};
} catch (error) {
return {};
}
};

addToken = async () => {
Expand Down
18 changes: 11 additions & 7 deletions app/components/UI/TransactionEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,17 @@ class TransactionEditor extends PureComponent {
};

getGasAnalyticsParams = () => {
const { transaction, activeTabUrl } = this.props;
const { selectedAsset } = transaction;
return {
dapp_host_name: transaction?.origin,
dapp_url: activeTabUrl,
active_currency: { value: selectedAsset?.symbol, anonymous: true }
};
try {
const { transaction, activeTabUrl } = this.props;
const { selectedAsset } = transaction;
return {
dapp_host_name: transaction?.origin,
dapp_url: activeTabUrl,
active_currency: { value: selectedAsset?.symbol, anonymous: true }
};
} catch (error) {
return {};
}
};

render = () => {
Expand Down
32 changes: 18 additions & 14 deletions app/components/UI/TypedSign/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,22 @@ export default class TypedSign extends PureComponent {
};

getAnalyticsParams = () => {
const { currentPageInformation, messageParams } = this.props;
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const url = new URL(currentPageInformation.url);
return {
dapp_host_name: url?.host,
dapp_url: currentPageInformation?.url,
network_name: type,
chain_id: chainId,
sign_type: 'typed',
version: messageParams?.version
};
try {
const { currentPageInformation, messageParams } = this.props;
const { NetworkController } = Engine.context;
const { chainId, type } = NetworkController?.state?.provider || {};
const url = new URL(currentPageInformation?.url);
return {
dapp_host_name: url?.host,
dapp_url: currentPageInformation?.url,
network_name: type,
chain_id: chainId,
sign_type: 'typed',
version: messageParams?.version
};
} catch (error) {
return {};
}
};

componentDidMount = () => {
Expand Down Expand Up @@ -129,14 +133,14 @@ export default class TypedSign extends PureComponent {
};

cancelSignature = () => {
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_CANCELLED, this.getAnalyticsParams());
this.rejectMessage();
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_CANCELLED, this.getAnalyticsParams());
this.props.onCancel();
};

confirmSignature = () => {
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_COMPLETED, this.getAnalyticsParams());
this.signMessage();
AnalyticsV2.trackEvent(AnalyticsV2.ANALYTICS_EVENTS.SIGN_REQUEST_COMPLETED, this.getAnalyticsParams());
this.props.onConfirm();
};

Expand Down
Loading