Skip to content

Commit

Permalink
feat: add initial analytics events
Browse files Browse the repository at this point in the history
  • Loading branch information
micwallace committed Sep 18, 2024
1 parent ff001cc commit 3c7edf9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
12 changes: 12 additions & 0 deletions javascript/tokenscript-viewer/src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,21 @@ const initViewerType = (params: URLSearchParams): ViewerTypes => {
viewerType = "new";
}

if (window.gtag) {
window.gtag('set', {
'viewer-type': viewerType
});
}

return viewerType
}

declare global {
interface Window {
gtag: any
}
}

@Component({
tag: 'app-root',
styleUrl: 'app.css',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class Web3WalletProviderObj {
for (const listener of this.walletChangeListeners){
listener(connection);
}

this.setGAWalletDetails();
}

isWalletConnected(){
Expand Down Expand Up @@ -194,6 +196,26 @@ class Web3WalletProviderObj {
return this.getConnectedWalletData('evm')[0];
}

private setGAWalletDetails(){
if (window.gtag) {
const data = this.getConnectedWalletData('evm')?.[0];

window.gtag('set', {
'wallet_address': data?.address,
'wallet_name': data?.providerType
});

if (data){
window.gtag('event', 'wallet_connected', {
'wallet_address': data.address,
'wallet_name': data.providerType
})
} else {
window.gtag('event', 'wallet_disconnected');
}
}
}

async disconnectWallet(){
await this.deleteConnections();
this.emitWalletChangeEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,19 @@ export class IFrameEthereumProvider implements ethers.Eip1193Provider {
if (completer) {
// Handle pending promise
if ('error' in message || 'result' in message) {

if (
window.gtag &&
'result' in message &&
'method' in message &&
message.method === "eth_accounts"
) {
window.gtag('set', {
'wallet_address': message.result?.[0],
'wallet_name': "iframe-provider"
});
}

completer.resolve(message);
} else {
completer.reject(
Expand Down

0 comments on commit 3c7edf9

Please sign in to comment.