MetaMask / metamask-sdk

The simplest yet most secure way to connect your blockchain-based applications to millions of MetaMask Wallet users.
https://metamask.io/sdk/
Other
182 stars 112 forks source link

[JS] - P0 - Segment integration for JS #16

Closed ezgi-cengiz closed 1 year ago

ezgi-cengiz commented 2 years ago

Install the Segment snippet on your website Copy the Segment snippet and paste it high in the of your website. Learn more about setting up Segment in the Analytics.js guide.

<script>
  !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e<analytics.methods.length;e++){var key=analytics.methods[e];analytics[key]=analytics.factory(key)}analytics.load=function(key,e){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.src="https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics._writeKey="YOUR_API_KEY";;analytics.SNIPPET_VERSION="4.15.3";
  analytics.load("YOUR_API_KEY");
  analytics.page();
  }}();
</script>
andreahaku commented 1 year ago

the events are:

enum TrackingEvents {
  REQUEST = 'sdk_connect_request_started',
  CONNECT = 'sdk_connection_established',
  DISCONNECT = 'sdk_disconnected',
}

with the sdk_connect_request_started event we also send:

This is the meaning for the platform options:

// React Native or Nodejs
NonBrowser = 'NonBrowser',

// MetaMask Mobile in-app browser
MetaMaskMobileWebview = 'MetaMaskMobileWebview',

// Desktop Browser
DesktopWeb = 'DesktopWeb',

// Mobile Browser
MobileWeb = 'MobileWeb',