From 592d28fd0e52d4c46184153cdfb7cc1fee837372 Mon Sep 17 00:00:00 2001 From: Bilal Mir Date: Wed, 10 May 2023 16:33:17 +0500 Subject: [PATCH] fix(txn): txnHash in submitTxn (#37) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- src/Session/index.js | 13 +++++++------ src/WalletConnection/index.js | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bf97c8..ab6d741 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -135,3 +135,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Events flow in session. - Geolocation tracking on intial events. + +## [1.0.0-beta.4] - 2023-05-10 + +### Fixed + +- Add txn hash on txn-submit tracking. +- Expire session on wallet or chain change. diff --git a/package.json b/package.json index 828fcac..c6f1967 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "analytics-web3", - "version": "1.0.0-beta.3", + "version": "1.0.0-beta.4", "description": "Spock analytics SDK analytics-web3 is a js module to collect and log all the data and events of DApp for analytics.", "main": "dist/analytics-web3.min.js", "license": "UNLICENSED", diff --git a/src/Session/index.js b/src/Session/index.js index c4911e2..e475a59 100644 --- a/src/Session/index.js +++ b/src/Session/index.js @@ -1,7 +1,7 @@ -import { LOG, TRACKING_EVENTS, STORAGE } from '../constants'; +import { LOG, TRACKING_EVENTS, STORAGE, EVENTS } from '../constants'; import BaseAnalytics from '../BaseAnalytics'; import { limitedTimeout, sessionUUID } from './utils'; -import { getCookie } from '../utils/cookies'; +import { deleteCookie, getCookie } from '../utils/cookies'; import { JSON_Formatter } from '../utils/formatting'; import { addEvent, currentTimestamp } from '../utils/helpers'; import { notUndefined } from '../utils/validators'; @@ -28,10 +28,10 @@ class Session extends BaseAnalytics { addEvent(window, 'beforeunload', this.pauseSession.bind(this)); //TODO should we expire on new wallet connect - // addEvent(window, EVENTS.WALLET_CONNECTION, () => { - // this.endSession(); - // this.beginSession(); - // }); + addEvent(window, EVENTS.WALLET_CONNECTION, () => { + this.endSession(); + this.beginSession(); + }); this.visibilityEvents(); @@ -79,6 +79,7 @@ class Session extends BaseAnalytics { this.dispatch({ sessionId, txnReject, txnSubmit, flow: [...flow, ...this.store.flow] }); this.storedDuration = duration; this.request.post(`track/${TRACKING_EVENTS.REWIND_SESSION}`, { data: { sessionId } }); + deleteCookie(STORAGE.COOKIES.SESSION); } pauseSession() { diff --git a/src/WalletConnection/index.js b/src/WalletConnection/index.js index 9c4e5ab..72cc007 100644 --- a/src/WalletConnection/index.js +++ b/src/WalletConnection/index.js @@ -92,7 +92,7 @@ class WalletConnection extends BaseAnalytics { this.trackEvent({ event: TRACKING_EVENTS.TRANSACTION, properties, logMessage: 'Transaction rejected' }); this.dispatch({ txnReject: this.store.txnReject + 1 }); } else if (status === 'submitted' && this.cacheTxnHash !== txnHash) { - const properties = { ...txnObj, status: 1 }; + const properties = { ...txnObj, hash: txnHash, status: 1 }; this.trackEvent({ event: TRACKING_EVENTS.TRANSACTION, properties, logMessage: 'Transaction submitted' }); this.cacheTxnHash = txnHash; this.dispatch({ txnSubmit: this.store.txnSubmit + 1 }); @@ -181,7 +181,7 @@ class WalletConnection extends BaseAnalytics { } } - if (provider.isMetaMask) return WALLET_TYPE.METAMASK; + if (provider.isMetaMask || provider.connection?.url === 'metamask') return WALLET_TYPE.METAMASK; else if (provider.isWalletConnect) return WALLET_TYPE.WALLETCONNECT; else if (provider.isCoinbaseWallet) return WALLET_TYPE.COINBASE; else if (provider.isFortmatic) return WALLET_TYPE.FORTMATIC;