├── .node-version ├── website ├── static │ ├── .nojekyll │ └── img │ │ ├── image.png │ │ ├── amp_logo.png │ │ ├── image.webp │ │ ├── 404monster.png │ │ ├── amp_favicon.ico │ │ └── amp_logo.svg ├── babel.config.js ├── sidebars.js ├── .gitignore ├── src │ ├── pages │ │ └── styles.module.css │ └── css │ │ └── custom.css ├── package.json ├── README.md ├── docusaurus.config.js └── generate-jsdoc.js ├── .eslintignore ├── .prettierignore ├── .prettierrc.json ├── test ├── browser │ ├── .eslintrc.json │ ├── mocha-tests.html │ ├── snippet.html │ ├── server.js │ ├── index.html │ ├── amplitudejs-segment.html │ ├── amplitudejs-requirejs.html │ ├── amplitudejs2.html │ ├── mocha.css │ └── amplitudejs.html ├── global-scope.js ├── uuid.js ├── tests.js ├── md5.js ├── base64Id.js ├── config-manager.js ├── top-domain.js ├── server-zone.js ├── base64.js ├── mock-cookie.js ├── cookie.js ├── utm.js ├── worker-storage.js ├── language.js ├── cookiestorage.js ├── snippet-tests.js ├── revenue.js ├── base-cookie.js ├── web-worker.js └── utils.js ├── .babelrc ├── .github ├── ISSUE_TEMPLATE │ ├── Question.md │ ├── Feature_request.md │ └── Bug_report.md ├── semantic.yml ├── pull_request_template.md └── workflows │ ├── jira-issue-create.yml │ ├── lint.yml │ ├── test.yml │ ├── deploy-docs.yml │ ├── publish-github-packages.yml │ ├── codeql-analysis.yml │ ├── release.yml │ └── semantic-pr.yml ├── rollup.test.js ├── rollup.min.js ├── rollup.umd.min.js ├── src ├── language.js ├── global-scope.js ├── base64Id.js ├── worker-storage.js ├── top-domain.js ├── uuid.js ├── index.js ├── type.js ├── server-zone.js ├── utm.js ├── utf8.js ├── config-manager.js ├── constants.js ├── xhr.js ├── cookiestorage.js ├── cookie.js ├── base64.js ├── base-cookie.js ├── localstorage.js ├── amplitude-snippet.js ├── revenue.js ├── metadata-storage.js ├── utils.js └── identify.js ├── rollup.snippet-tests.js ├── .npmignore ├── .gitignore ├── scripts ├── create-snippet-instructions.js ├── readme.js ├── release.js ├── version.js └── deploy_s3.py ├── bower.json ├── .vscode └── settings.json ├── rollup.esm.js ├── .eslintrc.json ├── karma-web-worker.conf.js ├── rollup.config.js ├── rollup.umd.js ├── release.config.js ├── LICENSE ├── karma.conf.js ├── Makefile ├── CONTRIBUTING.md ├── package.json └── README.md /.node-version: -------------------------------------------------------------------------------- 1 | 14.4.0 2 | -------------------------------------------------------------------------------- /website/static/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /*.js 2 | /website/.docusaurus/ 3 | /website/build/ 4 | /build/ 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | *.md 2 | /*.js 3 | /website/.docusaurus/ 4 | /website/build/ 5 | /build/ 6 | -------------------------------------------------------------------------------- /website/static/img/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amplitude/Amplitude-JavaScript/HEAD/website/static/img/image.png -------------------------------------------------------------------------------- /website/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /website/static/img/amp_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amplitude/Amplitude-JavaScript/HEAD/website/static/img/amp_logo.png -------------------------------------------------------------------------------- /website/static/img/image.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amplitude/Amplitude-JavaScript/HEAD/website/static/img/image.webp -------------------------------------------------------------------------------- /website/static/img/404monster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amplitude/Amplitude-JavaScript/HEAD/website/static/img/404monster.png -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "proseWrap": "always", 4 | "singleQuote": true, 5 | "trailingComma": "all" 6 | } 7 | -------------------------------------------------------------------------------- /website/static/img/amp_favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amplitude/Amplitude-JavaScript/HEAD/website/static/img/amp_favicon.ico -------------------------------------------------------------------------------- /test/browser/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "prettier/prettier": "error", 4 | "no-prototype-builtins": "off" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /website/sidebars.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | sidebar: { 3 | 'API Reference': ['AmplitudeClient', 'Amplitude', 'Identify', 'Revenue', 'Options'], 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["@babel/env", { 4 | "targets": { 5 | "browsers": ["ie >= 8"] 6 | }, 7 | "modules": false 8 | }] 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question ❓ 3 | about: Ask a question 4 | labels: 'question' 5 | --- 6 | 7 | ## Summary 8 | 9 | 10 | -------------------------------------------------------------------------------- /rollup.test.js: -------------------------------------------------------------------------------- 1 | import config from './rollup.config.js'; 2 | 3 | config.input = 'test/tests.js'; 4 | config.output.file = 'build/tests.js'; 5 | config.output.sourcemap = true; 6 | 7 | export default config; 8 | -------------------------------------------------------------------------------- /rollup.min.js: -------------------------------------------------------------------------------- 1 | import config from './rollup.config.js'; 2 | import terser from '@rollup/plugin-terser'; 3 | 4 | config.plugins.push(terser()); 5 | config.output.file = 'amplitude.min.js'; 6 | 7 | export default config; 8 | -------------------------------------------------------------------------------- /rollup.umd.min.js: -------------------------------------------------------------------------------- 1 | import config from './rollup.umd.js'; 2 | import terser from '@rollup/plugin-terser'; 3 | 4 | config.plugins.push(terser()); 5 | config.output.file = 'amplitude.umd.min.js'; 6 | 7 | export default config; 8 | -------------------------------------------------------------------------------- /test/global-scope.js: -------------------------------------------------------------------------------- 1 | import GlobalScope from '../src/global-scope'; 2 | 3 | describe('GlobalScope', function () { 4 | it('should return true', function () { 5 | assert.isTrue(GlobalScope === window); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/language.js: -------------------------------------------------------------------------------- 1 | var getLanguage = function () { 2 | return ( 3 | (typeof navigator !== 'undefined' && 4 | ((navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage)) || 5 | '' 6 | ); 7 | }; 8 | 9 | export default { 10 | getLanguage, 11 | }; 12 | -------------------------------------------------------------------------------- /rollup.snippet-tests.js: -------------------------------------------------------------------------------- 1 | import config from './rollup.config.js'; 2 | import legacy from '@rollup/plugin-legacy'; 3 | 4 | config.plugins.push(legacy({ 5 | './amplitude-snippet.min.js': 'amplitude', 6 | })); 7 | config.input = 'test/snippet-tests.js'; 8 | config.output.file = 'build/snippet-tests.js'; 9 | 10 | export default config; 11 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | components 2 | documentation 3 | npm-debug.log 4 | build 5 | dist 6 | .DS_Store 7 | rollup.* 8 | circle.yml 9 | dist 10 | Makefile 11 | bower.json 12 | test 13 | build 14 | karma.conf.js 15 | scripts 16 | .npmignore 17 | .prettierrc.json 18 | .eslintrc.json 19 | amplitude.min.js 20 | amplitude-segment-snippet.min.js 21 | *.log 22 | src 23 | .watchmanconfig 24 | .babelrc 25 | -------------------------------------------------------------------------------- /src/global-scope.js: -------------------------------------------------------------------------------- 1 | /* global globalThis */ 2 | const GlobalScope = (() => { 3 | if (typeof globalThis !== 'undefined') { 4 | return globalThis; 5 | } 6 | if (typeof window !== 'undefined') { 7 | return window; 8 | } 9 | if (typeof self !== 'undefined') { 10 | return self; 11 | } 12 | if (typeof global !== 'undefined') { 13 | return global; 14 | } 15 | })(); 16 | 17 | export default GlobalScope; 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 🚀 3 | about: You'd like something added to the SDK 4 | labels: 'enhancement' 5 | --- 6 | 7 | 8 | 9 | ## Summary 10 | 11 | 12 | 13 | ## Motivations 14 | 15 | 16 | -------------------------------------------------------------------------------- /.github/semantic.yml: -------------------------------------------------------------------------------- 1 | # Validate the PR title, and ignore the commits 2 | titleOnly: true 3 | 4 | # By default types specified in commitizen/conventional-commit-types is used. 5 | # See: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json 6 | # You can override the valid types 7 | 8 | types: 9 | - feat 10 | - fix 11 | - perf 12 | - docs 13 | - test 14 | - refactor 15 | - style 16 | - build 17 | - ci 18 | - chore 19 | - revert 20 | -------------------------------------------------------------------------------- /src/base64Id.js: -------------------------------------------------------------------------------- 1 | // A URL safe variation on the the list of Base64 characters 2 | const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; 3 | 4 | const base64Id = () => { 5 | const randomValues = crypto.getRandomValues(new Uint8Array(22)); 6 | 7 | let str = ''; 8 | 9 | for (let i = 0; i < 22; ++i) { 10 | str += base64Chars.charAt(randomValues[i] % 64); 11 | } 12 | 13 | return str; 14 | }; 15 | 16 | export default base64Id; 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | components 3 | npm-debug.log 4 | build 5 | dist 6 | .DS_Store 7 | *.crt 8 | *.key 9 | amplitude.js 10 | amplitude.esm.js 11 | amplitude.min.js 12 | amplitude-snippet.min.js 13 | amplitude-snippet-instructions.js 14 | amplitude-segment-snippet.min.js 15 | .watchmanconfig 16 | package-lock.json 17 | amplitude.umd.js 18 | amplitude.umd.min.js 19 | amplitude.native.js 20 | amplitude.nocompat.js 21 | amplitude.nocompat.min.js 22 | 23 | # For WebStorm IDE 24 | .idea/ 25 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Generated jsdoc markdown 12 | docs/Amplitude.md 13 | docs/AmplitudeClient.md 14 | docs/Identify.md 15 | docs/Revenue.md 16 | docs/Options.md 17 | 18 | # Misc 19 | .DS_Store 20 | .env.local 21 | .env.development.local 22 | .env.test.local 23 | .env.production.local 24 | 25 | npm-debug.log* 26 | yarn-debug.log* 27 | yarn-error.log* 28 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | ### Summary 8 | 9 | 10 | 11 | ### Checklist 12 | 13 | * [ ] Does your PR title have the correct [title format](https://github.com/amplitude/Amplitude-JavaScript/blob/main/CONTRIBUTING.md#pr-commit-title-conventions)? 14 | * Does your PR have a breaking change?: 15 | -------------------------------------------------------------------------------- /test/uuid.js: -------------------------------------------------------------------------------- 1 | import UUID from '../src/uuid.js'; 2 | 3 | describe('UUID', function () { 4 | it('should generate a valid UUID-4', function () { 5 | var uuid = UUID(); 6 | assert.equal(36, uuid.length); 7 | assert.equal('4', uuid.substring(14, 15)); 8 | }); 9 | 10 | it('should generate a unique UUID-4', () => { 11 | const ids = new Set(); 12 | const count = 10000; 13 | for (let i = 0; i < count; i++) { 14 | ids.add(UUID()); 15 | } 16 | assert.equal(ids.size, count); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /test/tests.js: -------------------------------------------------------------------------------- 1 | import './base64.js'; 2 | import './language.js'; 3 | import './md5.js'; 4 | import './uuid.js'; 5 | import './cookie.js'; 6 | import './ua-parser.js'; 7 | import './identify.js'; 8 | import './cookiestorage.js'; 9 | import './utm.js'; 10 | import './amplitude.js'; 11 | import './amplitude-client.js'; 12 | import './utils.js'; 13 | import './revenue.js'; 14 | import './base-cookie.js'; 15 | import './top-domain.js'; 16 | import './base64Id.js'; 17 | import './server-zone.js'; 18 | import './config-manager.js'; 19 | import './worker-storage.js'; 20 | import './global-scope.js'; 21 | -------------------------------------------------------------------------------- /scripts/create-snippet-instructions.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | 4 | const cwd = process.cwd(); 5 | const instructionsFileName = path.join(cwd, 'amplitude-snippet-instructions.js'); 6 | 7 | const snippetFilename = path.join(cwd, 'amplitude-snippet.min.js'); 8 | const snippet = fs.readFileSync(snippetFilename, 'utf-8'); 9 | 10 | const script = ` 14 | `; 15 | fs.writeFileSync(instructionsFileName, script); 16 | 17 | console.log('Created amplitude-snippet-instructions.js'); 18 | -------------------------------------------------------------------------------- /test/browser/mocha-tests.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |